mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: optionally prefix authentication related cookies (#22148)
When the deployment option is enabled auth cookies are prefixed with `__HOST-` ([info](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie)). This is all done in a middleware that intercepts all requests and strips the prefix on incoming request cookies.
This commit is contained in:
Generated
+3
@@ -15571,6 +15571,9 @@ const docTemplate = `{
|
||||
"codersdk.HTTPCookieConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host_prefix": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"same_site": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
Generated
+3
@@ -14092,6 +14092,9 @@
|
||||
"codersdk.HTTPCookieConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host_prefix": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"same_site": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -900,6 +900,7 @@ func New(options *Options) *API {
|
||||
sharedhttpmw.Recover(api.Logger),
|
||||
httpmw.WithProfilingLabels,
|
||||
tracing.StatusWriterMiddleware,
|
||||
options.DeploymentValues.HTTPCookies.Middleware,
|
||||
tracing.Middleware(api.TracerProvider),
|
||||
httpmw.AttachRequestID,
|
||||
httpmw.ExtractRealIP(api.RealIPConfig),
|
||||
|
||||
+1
-1
@@ -704,7 +704,7 @@ func (api *API) postLogout(rw http.ResponseWriter, r *http.Request) {
|
||||
Name: codersdk.SessionTokenCookie,
|
||||
Path: "/",
|
||||
}
|
||||
http.SetCookie(rw, cookie)
|
||||
http.SetCookie(rw, api.DeploymentValues.HTTPCookies.Apply(cookie))
|
||||
|
||||
// Delete the session token from database.
|
||||
apiKey := httpmw.APIKey(r)
|
||||
|
||||
@@ -1905,10 +1905,13 @@ func TestUserLogout(t *testing.T) {
|
||||
// Create a custom database so it's easier to make scoped tokens for
|
||||
// testing.
|
||||
db, pubSub := dbtestutil.NewDB(t)
|
||||
dv := coderdtest.DeploymentValues(t)
|
||||
dv.HTTPCookies.EnableHostPrefix = true
|
||||
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
Database: db,
|
||||
Pubsub: pubSub,
|
||||
DeploymentValues: dv,
|
||||
Database: db,
|
||||
Pubsub: pubSub,
|
||||
})
|
||||
firstUser := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user