Skip to content

fix: prevent unrelated websites from modifying shortlinks via CSRF#30

Open
midchildan wants to merge 1 commit intokellegous:masterfrom
midchildan:fix/csrf
Open

fix: prevent unrelated websites from modifying shortlinks via CSRF#30
midchildan wants to merge 1 commit intokellegous:masterfrom
midchildan:fix/csrf

Conversation

@midchildan
Copy link
Copy Markdown

Issue

Unrelated websites can issue requests to register/modify shortlinks.

How to reproduce

  1. Run go on localhost:8067
  2. Access https://jsfiddle.net/tcm5vjwy/
  3. Shortlink :1 is set to https://example.com without any user interaction

The fix

  • Attach an X-Requested-With header in client requests
  • Make sure client POST requests have a content type of "application/json"

Added two mitigations for this issue:

- Attach an 'X-Requested-With' header in client requests
- Make sure client POST requests have a content type of "application/json"
@midchildan
Copy link
Copy Markdown
Author

I initially wrote the server side checks to mandate X-Requested-With be set to XMLHttpRequest, but I've now relaxed it a bit to accept any non-empty value.

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