Skip to content

[Proposal] CSRF checks on GET routes #4838

Closed
@beeonthego

Description

@beeonthego

The Vulnerabilities on GET Routes

For historical reasons some GET routes in Gitea do more than getting info and actually change state, for example /user/logout, and GET routes with action/:action in it. Current CSRF handler only checks POST routes, and thus leaves those GET routes vulnerable.

One particular route admin/notices/empty should probably be a POST i/o GET route.

Strategies

We are working on a PR to address these vulnerabilities, and would like the community feedback on the best strategy.

Option 1: reuse existing CSRF token + referrer-policy header (WARNING! BAD IDEA, Don't do this. See comments below for reason.)

In this option we will append the existing CSRF token to vulnerable GET routes as a query string, validate the token. A referrer-policy header can be set to same origin to prevent abuse of the token.

This option has less changes to existing code.

Option 2: generate a new JWT token with a key exclusive for this purpose

In this option we will generate a new JWT token and send to the browser via a new cookie. This will have more changes to the code.

Questions

security concerns on reusing csrf token on URL

We are thinking to implement option 1, and have code already done. It has less code changes and hopefully can be merged soon. Are there any concerns on this option 1?

response code or redirect

What should we do if the required token is missing or invalid? Should we redirect to home page, or return 403? Browsers treat 403 error code differently, for example Chrome on Mac displays the following message which may not be what you want.

This site can’t be reached
The web page at https://gitea.on-my-super-domain.dummy/user/logout might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_RESPONSE

Potential Impact

Both options require an extra handler on vulnerable routes to check the token in query string, and minor changes in URL in templates. While the PR can include the new token in default templates, this is potentially a breaking change to people using custom templates. The custom templates need to be updated to include the token in generated URL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions