Skip to content

Rephrase security section for hidden inputs#44564

Open
blunket wants to merge 6 commits into
mdn:mainfrom
blunket:patch-1
Open

Rephrase security section for hidden inputs#44564
blunket wants to merge 6 commits into
mdn:mainfrom
blunket:patch-1

Conversation

@blunket

@blunket blunket commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

Clarify the security section on the docs about the hidden input type.

Motivation

I found the phrasing "pretty much any reputable server-side framework" to be opinionated in a negative way, so I replaced that phrasing first. Then I reorganized and clarified both paragraphs in that section and attempted to make it sound more neutral and professional in general.

I found the phrasing "pretty much any reputable server-side framework" to be opinionated in a slightly negative way, so I replaced that phrasing, then I reorganized the entire section and attempted to make it sound more neutral and professional in general.
@blunket blunket requested a review from a team as a code owner June 23, 2026 15:31
@blunket blunket requested review from estelle and removed request for a team June 23, 2026 15:31
@github-actions github-actions Bot added Content:HTML Hypertext Markup Language docs size/xs [PR only] 0-5 LoC changed labels Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (1 page)

(comment last updated: 2026-06-25 14:22:12)

@wbamberg

wbamberg commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

We now have a whole page on CSRF, including a section on CSRF tokens: https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF#csrf_tokens.

In my opinion it's better just to point to that page, than to try to summarise how CSRF and CSRF tokens work - I don't really think it's possible to summarise this in a way that's comprehensible and correct, so to understand it you have to read the full version anyway. So would be better, here, to say something like: "a common use of hidden fields is as CSRF tokens, which help protect websites against CSRF attacks".

Hidden inputs may also be used to store and submit security tokens (or _secrets_) for the purposes of improving website security. For example, this technique can help prevent a type of attack known as a [Cross Site Request Forgery (CSRF)](/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Website_security#cross-site_request_forgery_csrf). Many server-side frameworks use hidden secrets to prevent such attacks.

This would stop a malicious user from creating a fake form, pretending to be a bank, and emailing the form to unsuspecting users to trick them into transferring money to the wrong place. This kind of attack is called a [Cross Site Request Forgery (CSRF)](/en-US/docs/Learn_web_development/Extensions/Server-side/First_steps/Website_security#cross-site_request_forgery_csrf); pretty much any reputable server-side framework uses hidden secrets to prevent such attacks.
The basic idea is that if a user is filling in a sensitive form, such as a form on a banking website to transfer money, the data within the hidden input would prove both that they are who they say they are and that they are using the correct form to submit the transfer request. This would stop malicious users or bots from submitting a fake version of the form.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how a CSRF token proves that the user is "who they say they are". AIUI it helps ensure that the page containing the form was really served by the legitimate server, and isn't on a malicious site.

This is also not quite right:

This would stop malicious users or bots from submitting a fake version of the form.

In CSRF, malicious users don't submit fake forms. The real user submits the fake form - that's why it's a problem (because it contains the real user's cookies).

Like I say, it's hard to explain this correctly, concisely, and comprehensibly, so I think it is better just to link to the guide page, where we have the space to explain it properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree with you. I was not confident enough in my own understanding to change that phrasing about proving identity.

In pointing to this page then, the whole section becomes two short sentences. Does it still need its own section at that point? I'll go ahead and try to update the PR if so. Otherwise we can move these details about security on the page if you agree with me.

Thank you for the feedback!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a good question. I think it is probably worth keeping the section on this page even when it is very short, just to have it clearly signposted. And otherwise we get structural problems here, because Tracking edited content wants to be its own section, so then where do you put the security use case?

But sometimes this is the kind of thing you have to see, to get a feeling about whether it is sensible or not.

BTW I didn't say this before but I should have, or it sounds like I'm only complaining: I agree with your original motivation for making this change, and think this is an improvement. So, thank you!

blunket added 3 commits June 24, 2026 08:25
Also removed any notes throughout the page saying that the field cannot be edited.
@github-actions github-actions Bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Jun 25, 2026
Comment thread files/en-us/web/html/reference/elements/input/hidden/index.md Outdated
Comment thread files/en-us/web/html/reference/elements/input/hidden/index.md Outdated
blunket and others added 2 commits June 25, 2026 09:19
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants