X Tutup
Skip to content

Commit bbeb558

Browse files
committed
Narrow the scope of the local server handler
Before, the local server handled any request regardless of path, which could potentially include requests generated by the browser such as the one for favicon. This could lead to race conditions around reading the code to continue to OAuth flow with. Now, have the OAuth flow redirect to `localhost:PORT/callback` and only handle `/callback` requests specifically.
1 parent 635d296 commit bbeb558

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

auth/oauth.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
4646

4747
q := url.Values{}
4848
q.Set("client_id", oa.ClientID)
49-
q.Set("redirect_uri", fmt.Sprintf("http://localhost:%d", port))
49+
q.Set("redirect_uri", fmt.Sprintf("http://localhost:%d/callback", port))
5050
q.Set("scope", "repo")
5151
q.Set("state", state)
5252

@@ -57,6 +57,10 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) {
5757
}
5858

5959
http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60+
if r.URL.Path != "/callback" {
61+
w.WriteHeader(404)
62+
return
63+
}
6064
defer listener.Close()
6165
rq := r.URL.Query()
6266
if state != rq.Get("state") {

0 commit comments

Comments
 (0)
X Tutup