Skip to content

Commit 74ae768

Browse files
authored
[CDTOOL-1090] fix(sso): Ensure that OPTIONS requests sent by browsers do not break SSO authentication (#1496)
Browsers may send 'preflight' OPTIONS requests before sending the GET request which contains the authentication result; the internal webserver will now accept this request, respond to it appropriately, and continue waiting for the GET request. The webserver will also explicitly reject any requests that are not directed at the proper path, or are any method other than GET or OPTIONS. All Submissions: * [X] Have you followed the guidelines in our Contributing document? * [X] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [ ] Does your submission pass tests? ### Changes to Core Features: * [ ] Have you added an explanation of what your changes do and why you'd like us to include them? * [ ] Have you written new tests for your core changes, as applicable? * [ ] Have you successfully run tests with your changes locally? ### User Impact * [ ] What is the user impact of this change? ### Are there any considerations that need to be addressed for release? <!-- Any breaking changes, etc -->
1 parent f20854a commit 74ae768

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
### Enhancements:
88

99
### Bug fixes:
10+
- fix(sso): Ensure that OPTIONS requests sent by browsers do not break SSO authentication. ([#1496](https://github.com/fastly/cli/pull/1496))
1011

1112
### Dependencies:
1213
- build(deps): `github.com/fastly/go-fastly/v10` from 10.3.0 to 10.4.0 ([#1499](https://github.com/fastly/cli/pull/1499))
1314

1415
## [v11.3.0](https://github.com/fastly/cli/releases/tag/v11.3.0) (2025-06-11)
1516

1617
### Enhancements:
17-
- feat(config-store): Allow for dynamic limits on Config Store entry lengths [#1485](https://github.com/fastly/cli/pull/1485)
18+
- feat(config-store): Allow for dynamic limits on Config Store entry lengths ([#1485](https://github.com/fastly/cli/pull/1485))
1819
- feat(backend): Add support for 'prefer IPv6' attribute. ([#1487](https://github.com/fastly/cli/pull/1487))
1920
- feat(tools/domain): add `suggest` and `status` domain tools endpoints ([#1482](https://github.com/fastly/cli/pull/1482))
2021
- feat(logging): Add support for 'processing region' attribute. ([#1491](https://github.com/fastly/cli/pull/1491))

pkg/auth/auth.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ const Remediation = "Please re-run the command. If the problem persists, please
2828
// ClientID is the auth provider's Client ID.
2929
const ClientID = "fastly-cli"
3030

31-
// RedirectURL is the endpoint the auth provider will pass an authorization code to.
32-
const RedirectURL = "http://localhost:8080/callback"
31+
// redirectPath is the path in the internal webserver which will receive the authorization code.
32+
const redirectPath = "/callback"
33+
34+
// redirectURL is the endpoint the auth provider will pass an authorization code to.
35+
const redirectURL = "http://localhost:8080" + redirectPath
3336

3437
// OIDCMetadata is OpenID Connect's metadata discovery mechanism.
3538
// https://swagger.io/docs/specification/authentication/openid-connect-discovery/
@@ -110,7 +113,7 @@ func (s Server) AuthURL() (string, error) {
110113
params.Add("client_id", ClientID)
111114
params.Add("code_challenge", challenge)
112115
params.Add("code_challenge_method", "S256")
113-
params.Add("redirect_uri", RedirectURL)
116+
params.Add("redirect_uri", redirectURL)
114117
for _, p := range s.Params {
115118
params.Add(p.Field, p.Value)
116119
}
@@ -135,7 +138,7 @@ func (s Server) GetJWT(authorizationCode string) (JWT, error) {
135138
ClientID,
136139
s.Verifier.Verifier(),
137140
authorizationCode,
138-
"http://localhost:8080/callback", // NOTE: not redirected to, just a security check.
141+
redirectURL, // NOTE: not redirected to, just a security check.
139142
)
140143

141144
req, err := http.NewRequest(http.MethodPost, s.WellKnownEndpoints.Token, strings.NewReader(payload))
@@ -204,6 +207,23 @@ func (s *Server) Start() error {
204207
// HandleCallback processes the callback from the authentication service.
205208
func (s *Server) HandleCallback() http.HandlerFunc {
206209
return func(w http.ResponseWriter, r *http.Request) {
210+
if r.URL.Path != redirectPath {
211+
w.WriteHeader(http.StatusBadRequest)
212+
return
213+
}
214+
215+
switch r.Method {
216+
case http.MethodOptions:
217+
w.Header().Add("Access-Control-Allow-Origin", "accounts.fastly.com")
218+
w.WriteHeader(http.StatusOK)
219+
return
220+
case http.MethodGet:
221+
// handled below
222+
default:
223+
w.WriteHeader(http.StatusBadRequest)
224+
return
225+
}
226+
207227
authorizationCode := r.URL.Query().Get("code")
208228
if authorizationCode == "" {
209229
fmt.Fprint(w, "ERROR: no authorization code returned\n")

0 commit comments

Comments
 (0)