Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6fc28c

Browse files
authored
chore: bring back x-auth-checks with a length limit (#19928)
1 parentadb7521 commita6fc28c

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

‎coderd/coderd.go‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,8 @@ func New(options *Options) *API {
489489
r:=chi.NewRouter()
490490
// We add this middleware early, to make sure that authorization checks made
491491
// by other middleware get recorded.
492-
//nolint:revive,staticcheck // This block will be re-enabled, not going to remove it
493492
ifbuildinfo.IsDev() {
494-
// TODO: Find another solution to opt into these checks.
495-
// If the header grows too large, it breaks `fetch()` requests.
496-
// Temporarily disabling this until we can find a better solution.
497-
// One idea is to include checking the request for `X-Authz-Record=true`
498-
// header. To opt in on a per-request basis.
499-
// Some authz calls (like filtering lists) might be able to be
500-
// summarized better to condense the header payload.
501-
// r.Use(httpmw.RecordAuthzChecks)
493+
r.Use(httpmw.RecordAuthzChecks)
502494
}
503495

504496
ctx,cancel:=context.WithCancel(context.Background())

‎coderd/httpapi/authz.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import (
99
"github.com/coder/coder/v2/coderd/rbac"
1010
)
1111

12+
// The x-authz-checks header can end up being >10KB in size on certain queries.
13+
// Many HTTP clients will fail if a header or the response head as a whole is
14+
// too long to prevent malicious responses from consuming all of the client's
15+
// memory. I've seen reports that browsers have this limit as low as 4KB for the
16+
// entire response head, so we limit this header to a little less than 2KB,
17+
// ensuring there's still plenty of room for the usual smaller headers.
18+
constmaxHeaderLength=2000
19+
1220
// This is defined separately in slim builds to avoid importing the rbac
1321
// package, which is a large dependency.
1422
funcSetAuthzCheckRecorderHeader(ctx context.Context,rw http.ResponseWriter) {
@@ -23,6 +31,11 @@ func SetAuthzCheckRecorderHeader(ctx context.Context, rw http.ResponseWriter) {
2331
// configured on server startup for development and testing builds.
2432
// - If this header is missing from a response, make sure the response is
2533
// being written by calling `httpapi.Write`!
26-
rw.Header().Set("x-authz-checks",rec.String())
34+
checks:=rec.String()
35+
iflen(checks)>maxHeaderLength {
36+
checks=checks[:maxHeaderLength]
37+
checks+="<truncated>"
38+
}
39+
rw.Header().Set("x-authz-checks",checks)
2740
}
2841
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp