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

fix: properly setup CSRF errors #4259

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jonas-jonas
Copy link
Member

@jonas-jonas jonas-jonas commented Dec 31, 2024

The current implementation frequently returns errors that seem to contradict itself (reason says "no CSRF cookie sent" and detail says "CSRF cookie found but did not match). The reason is as follows: herodot errors are copied in the WithDetail method, and in theory all operations in that method happen on a new struct. The details field is a map[string]any, of which only the pointer to it is copied in WithDetail, not the actual contents. This means, that calling WithDetail on an existing error, modifies the details field on the original error as well.

And in this specific case, it means that calling WithDetail on ErrInvalidCSRFTokenServer, modifies the details field for all errors that do so, leading to misleading error responses.

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

@jonas-jonas jonas-jonas self-assigned this Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant