This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Fix auth-related error in the SSC REST API client hook#62798
Merged
Conversation
dc8a51e to
26a960a
Compare
Contributor
|
I guess I faced this issue today, but "fixed" it in an ugly way to unblock myself. |
taras-yemets
approved these changes
May 20, 2024
Contributor
Author
Sorry for not posting a PR to fix this sooner! 🙇 (Though to be fair, it was a PITA to track down.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on integrating the SSC REST API client hook (https://github.com/sourcegraph/sourcegraph/pull/62715) I spent longer than I would have liked trying to figure out why it wasn't working in some cases...
To cut to the punch line, there is a quirk of the
fetch()API in that it won't send the "origin" header forGETorHEADrequests. And that lead to the Sourcegraph backend not treating the request as authenticated, even though we supplied the user'ssgssession cookie.After doing my best to understand how things all work, it looks like the simplest thing would be to just supply the
X-Requested-Withheader. Which is how the backend authenticates HTTP requests based on the session cookie. (In addition to theOriginheader if it is made available, which is why I didn't catch this when working on the initial PR -- because I was only usingPOSTmethods...)Test Plan
Testing locally (how I found the book). CI/CD.