Skip to content

Update: Document how to protect against Same-site CSRF #1936

@nickchomey

Description

@nickchomey

What is missing or needs to be updated?

I don't notice any text in the CSRF doc on how to protect against same-site CSRF, arising from malicious user-generated content. For example, a comment on a post, in a forum, etc includes a malicious link to the same site that invisibly mutates another user's state.

Escaping html output that might contain user-generated content is covered by the XSS doc, which is linked at the top of the CSRF doc. But escaping sn't always possible/desirable (and sometimes mistakes are made).

So, in the event something slips through, same site CSRF is possible. Though, is this only a problem if some GET requests can mutate state?

An exception to that is if you use a declarative JavaScript approach, as is now popular with htmx, Datastar, alpine etc, where you can create js post requests just via text

Eg <div data-on:click="@post('/pwned')"></div>

Though, I suppose that not escaping input is still a more fundamental issue than CSRF protection.

How should this be resolved?

Since the XSS docs already cover escaping, perhaps this is only an issue for GET mutations. Perhaps this can be called out more explicitly in the CSRF doc?

In particular, perhaps it should be made more clear that seemingly only CSRF tokens can protect against this, since Fetch Metadata, for example, would be same-origin/same-site?

@mkhanas, tagging you since you're interested in this topic as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACK_WAITINGIssue waiting acknowledgement from core team before to start the work to fix it.HELP_WANTEDIssue for which help is wanted to do the job.UPDATE_CSIssue about the update/refactoring of a existing cheat sheet.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions