- Notifications
You must be signed in to change notification settings - Fork1k
chore: swagger docs omit brower based credentials, rely on swagger auth#13742
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -87,7 +87,31 @@ import ( | ||
var globalHTTPSwaggerHandler http.HandlerFunc | ||
func init() { | ||
globalHTTPSwaggerHandler = httpSwagger.Handler( | ||
httpSwagger.URL("/swagger/doc.json"), | ||
// The swagger UI has an "Authorize" button that will input the | ||
// credentials into the Coder-Session-Token header. This bypasses | ||
// CSRF checks **if** there is no cookie auth also present. | ||
// (If the cookie matches, then it's ok too) | ||
// | ||
// Because swagger is hosted on the same domain, we have the cookie | ||
// auth and the header auth competing. This can cause CSRF errors, | ||
// and can be confusing what authentication is being used. | ||
// | ||
// So remove authenticating via a cookie, and rely on the authorization | ||
// header passed in. | ||
httpSwagger.UIConfig(map[string]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I hate that they use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Not even a link to the docs 😢 | ||
// Pulled from https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/ | ||
// 'withCredentials' should disable fetch sending browser credentials, but | ||
// for whatever reason it does not. | ||
// So this `requestInterceptor` ensures browser credentials are | ||
// omitted from all requests. | ||
"requestInterceptor": `(a => { | ||
a.credentials = "omit"; | ||
return a; | ||
})`, | ||
Comment on lines +109 to +112 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. their recommendation is just to embed javascript in a string??? I extra hate that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yea, it is a bit crazy:https://github.com/swaggo/http-swagger/blob/master/swagger.go#L24-L27 | ||
"withCredentials": "false", | ||
})) | ||
} | ||
var expDERPOnce = sync.Once{} | ||