Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocomplete="off" to all generated hidden fields (fixes #42610) #43280

Merged
merged 2 commits into from Sep 22, 2021

Conversation

ryanfb
Copy link
Contributor

@ryanfb ryanfb commented Sep 21, 2021

Summary

Firefox has a longstanding bug where it may populate hidden inputs without autocomplete="off" with completely random values. Since Rails uses hidden fields extensively for e.g. CSRF protection and non-standard HTTP methods via _method, Firefox users interacting with otherwise-fine Rails apps will see random "Invalid Authenticity Token" errors and form inputs getting interpreted as the incorrect HTTP method, among other unexpected behavior. Adding autocomplete="off" does not appear to have any negative consequences for other browsers, and is valid HTML. There's more discussion and links at: #42610

I recently bundled my workaround for this into a gem for Rails 6.1 apps, rails-hidden_autocomplete, which I've now reworked into this PR so that it can benefit all Rails users & developers, since this bug is currently extremely frustrating to diagnose and fix in real-world apps (see also podqueue/rails-hidden_autocomplete#2).

Other Information

I appreciate that this change might need to be gated behind a new framework default for ActionView, which I'd be happy to work on adding if that's the consensus.

@rails-bot rails-bot bot added the actionview label Sep 21, 2021
@rafaelfranca
Copy link
Member

Action text tests are broken. Can you take a look?

@rails-bot rails-bot bot added the actiontext label Sep 22, 2021
@ryanfb
Copy link
Contributor Author

ryanfb commented Sep 22, 2021

Action text tests are broken. Can you take a look?

Should be fixed by 58127ec.

@rafaelfranca rafaelfranca merged commit aa449a8 into rails:main Sep 22, 2021
rafaelfranca added a commit that referenced this pull request Sep 22, 2021
Add autocomplete="off" to all generated hidden fields (fixes #42610)
andyundso added a commit to simplificator/datatrans that referenced this pull request Feb 21, 2022
andyundso added a commit to simplificator/datatrans that referenced this pull request Feb 21, 2022
andyundso added a commit to simplificator/datatrans that referenced this pull request Feb 21, 2022
kevindew added a commit to alphagov/whitehall that referenced this pull request Mar 11, 2022
Starting in Rails 6.1.5 hidden inputs have autocomplete="off" set as an
attribute, thus the test HTML needs to be updated.

This is explained further in: rails/rails#43280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants