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

chore: bring back x-auth-checks with a length limit#19928

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

Merged
aslilac merged 1 commit intomainfromlilac/bring-back-x-authz-checks
Sep 24, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,16 +489,8 @@ func New(options *Options) *API {
r := chi.NewRouter()
// We add this middleware early, to make sure that authorization checks made
// by other middleware get recorded.
//nolint:revive,staticcheck // This block will be re-enabled, not going to remove it
if buildinfo.IsDev() {
// TODO: Find another solution to opt into these checks.
// If the header grows too large, it breaks `fetch()` requests.
// Temporarily disabling this until we can find a better solution.
// One idea is to include checking the request for `X-Authz-Record=true`
// header. To opt in on a per-request basis.
// Some authz calls (like filtering lists) might be able to be
// summarized better to condense the header payload.
// r.Use(httpmw.RecordAuthzChecks)
r.Use(httpmw.RecordAuthzChecks)
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
15 changes: 14 additions & 1 deletioncoderd/httpapi/authz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,14 @@ import (
"github.com/coder/coder/v2/coderd/rbac"
)

// The x-authz-checks header can end up being >10KB in size on certain queries.
// Many HTTP clients will fail if a header or the response head as a whole is
// too long to prevent malicious responses from consuming all of the client's
// memory. I've seen reports that browsers have this limit as low as 4KB for the
// entire response head, so we limit this header to a little less than 2KB,
// ensuring there's still plenty of room for the usual smaller headers.
const maxHeaderLength = 2000

// This is defined separately in slim builds to avoid importing the rbac
// package, which is a large dependency.
func SetAuthzCheckRecorderHeader(ctx context.Context, rw http.ResponseWriter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could technically find the size of the other headers to, and check how large they are. Then make sure they never exceed 4kb

Expand All@@ -23,6 +31,11 @@ func SetAuthzCheckRecorderHeader(ctx context.Context, rw http.ResponseWriter) {
// configured on server startup for development and testing builds.
// - If this header is missing from a response, make sure the response is
// being written by calling `httpapi.Write`!
rw.Header().Set("x-authz-checks", rec.String())
checks := rec.String()
if len(checks) > maxHeaderLength {
checks = checks[:maxHeaderLength]
checks += "<truncated>"
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: Won't this result in a header that is 2011 bytes long, sincemaxHeaderLength +len("<truncated>")

Suggested change
checks=checks[:maxHeaderLength]
checks+="<truncated>"
truncationMarker="<truncated>"
checks=checks[:(maxHeaderLength-len(truncationMarker))]
checks+=truncationMarker

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thought about that, but figured it wouldn't hurt to let it be a tiny bit longer 😄

}
rw.Header().Set("x-authz-checks", checks)
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp