Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

disable_form_autofill.tmpl 1.8KB

12345678910111213141516171819202122232425262728293031
  1. {{/*
  2. Why we need to disable form autofill:
  3. 1. Many pages contain different password inputs for different usages, eg: repo setting, autofill will make a mess.
  4. 2. We have `areYouSure` confirm dialog if a user leaves a pages without submit.
  5. Autofill will make the form changed even if the user didn't input anything. Then the user keeps seeing annoying confirm dialog.
  6. In history, Gitea put `<input class="fake" type="password">` in forms to bypass the autofill,
  7. but there were still many forms suffered the autofill problem.
  8. Now we improve it.
  9. Solutions which do NOT work:
  10. 1. Adding `autocomplete=off` doesn't help. New Chrome completely ignores it.
  11. 2. Use a JavaScript to run in a few seconds later after the page is loaded to process the autofilled inputs, it doesn't work.
  12. Because for security reason, the inputs won't be filled before the user makes an interaction in the page.
  13. So we can not predict the correct time to run the JavaScript code.
  14. Solutions which work:
  15. 1. Some hacky methods like: https://github.com/matteobad/detect-autofill
  16. 2. This solution: use invisible inputs. Be aware of:
  17. (a) The inputs must be at the beginning of the form, and can not be hidden.
  18. (b) The input for username must have a valid name.
  19. (c) There should be no negative word (eg: fake) in the `name` attribute.
  20. (d) Chrome seems to use a weighted algorithm to choose an input to fill text, so the using "username" as input name is better than using "user".
  21. We make the names of these dummy inputs begin with an underline to indicate it is for special usage,
  22. and these dummy form values won't be used by backend code.
  23. */}}
  24. <div class="autofill-dummy" aria-hidden="true">
  25. <input type="text" name="_autofill_dummy_username" class="ays-ignore" tabindex="-1">
  26. <input type="password" name="_autofill_dummy_password" class="ays-ignore" tabindex="-1">
  27. </div>