Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
a672066
feat(coderd/rbac): compare scopes by permission coverage
BobbyHo Aug 14, 2026
4315706
Merge branch 'main' into plat479-1-rbac-scope-coverage
BobbyHo Aug 17, 2026
787c461
docs(coderd/rbac): shorten the ScopesCover doc comment
BobbyHo Aug 17, 2026
2d39e04
Merge branch 'main' into plat479-1-rbac-scope-coverage
BobbyHo Aug 18, 2026
2f6c44e
fix(coderd/rbac): guard allowed-side org and user permissions
BobbyHo Aug 18, 2026
bd40270
refactor(coderd/rbac): drop the unreachable negative skip in coverage
BobbyHo Aug 18, 2026
3139c54
test(coderd/rbac): pin the scope coverage table's weak assertions
BobbyHo Aug 18, 2026
9276bb8
refactor(coderd/rbac): make the coverage guards reachable from tests
BobbyHo Aug 18, 2026
865eb9a
refactor(coderd/rbac): share the alias table and name the canonical c…
BobbyHo Aug 18, 2026
26a6bed
docs(coderd/rbac): document the expansion invariant where it can be b…
BobbyHo Aug 18, 2026
7cca7b3
Merge branch 'main' into plat479-1-rbac-scope-coverage
BobbyHo Aug 19, 2026
1678a77
test(coderd/rbac): pin the coverage guards at one strength
BobbyHo Aug 19, 2026
aba3c6c
fix(coderd/rbac): name the scope once in expansion errors
BobbyHo Aug 19, 2026
9a08105
docs(coderd/rbac): correct the external scope list contract
BobbyHo Aug 19, 2026
2fcce8b
docs(coderd/rbac): trim the restated coverage invariant
BobbyHo Aug 19, 2026
a775a48
docs(coderd/rbac): correct the negative permission cross-reference
BobbyHo Aug 19, 2026
e0c0d4a
docs(coderd/rbac): name every category IsExternalScope admits
BobbyHo Aug 19, 2026
189740d
test(coderd/rbac): pin the alias list invariants on the alias table
BobbyHo Aug 19, 2026
7d08e49
Merge branch 'main' into plat479-1-rbac-scope-coverage
BobbyHo Aug 19, 2026
ca4dc52
feat(coderd/oauth2provider): negotiate and persist authorization scope
BobbyHo Aug 14, 2026
f402e1a
feat(site): state the negotiated scope on the OAuth2 consent page
BobbyHo Aug 14, 2026
28ef5ba
fix(coderd/oauth2provider): return invalid_scope to the client's call…
BobbyHo Aug 14, 2026
62950d3
test(coderd/rbac): close two mutation gaps in scope coverage tests
BobbyHo Aug 20, 2026
554a703
Merge branch 'main' into plat479-2-negotiate-scope
BobbyHo Aug 20, 2026
09bc1b4
refactor(coderd/oauth2provider): rename validateRequestedScope to neg…
BobbyHo Aug 21, 2026
6fe6c71
test(coderd/oauth2provider): bind the wire-level scope reasons to the…
BobbyHo Aug 21, 2026
e296dda
refactor(coderd): log undecidable oauth2 scope coverage instead of re…
BobbyHo Aug 21, 2026
2760db5
fix(coderd/oauth2provider): name the stored allowlist when none of it…
BobbyHo Aug 21, 2026
5b2ca57
refactor(coderd/oauth2provider): reword the oauth2 scope rejection re…
BobbyHo Aug 21, 2026
90a6f83
docs: correct what the oauth2 authorize scope parameter promises
BobbyHo Aug 21, 2026
77654a1
test(coderd/oauth2provider): fold the no-allowlist guarantee into one…
BobbyHo Aug 21, 2026
dfdd33f
Merge branch 'plat479-2-negotiate-scope' into plat479-3-report-negoti…
BobbyHo Aug 22, 2026
ba8a123
Merge branch 'main' into plat479-2-negotiate-scope
BobbyHo Aug 22, 2026
bc40908
test(coderd): close the consent-page and state-echo test gaps
BobbyHo Aug 23, 2026
cb7df2e
fix(site/static): left-align the consent permission list
BobbyHo Aug 23, 2026
41e9f40
fix(coderd/oauth2provider): validate the callback scheme before any r…
BobbyHo Aug 23, 2026
a56cdac
fix(coderd/oauth2provider): replace callback query params instead of …
BobbyHo Aug 23, 2026
009962c
feat: say that the consent permission names are technical
BobbyHo Aug 23, 2026
f983335
fix: state unrestricted OAuth2 consent in its own field
BobbyHo Aug 23, 2026
81bbfb0
docs: trim OAuth2 scope negotiation comments
BobbyHo Aug 23, 2026
b7f88f0
Merge branch 'plat479-2-negotiate-scope' into plat479-3-report-negoti…
BobbyHo Aug 23, 2026
2a2e006
Merge branch 'main' into plat479-2-negotiate-scope
BobbyHo Aug 23, 2026
a11d42c
test(coderd/oauth2provider): pin the consent list semantics and the s…
BobbyHo Aug 23, 2026
eb37c2f
test(coderd/oauth2provider): cover the error redirect in the query-pa…
BobbyHo Aug 23, 2026
a5e3f94
fix(coderd/oauth2provider): answer 500 and log on an unusable callbac…
BobbyHo Aug 23, 2026
60cbe59
fix: refuse to render a consent page for a grant with no permissions
BobbyHo Aug 23, 2026
fdc9532
docs: document invalid_scope rejections on the authorize endpoint
BobbyHo Aug 23, 2026
e63ff3a
docs(coderd): trim the scope test comments
BobbyHo Aug 25, 2026
a9ade4a
Merge branch 'plat479-2-negotiate-scope' into plat479-3-report-negoti…
BobbyHo Aug 25, 2026
5589bf6
docs: trim the consent page and error redirect comments
BobbyHo Aug 25, 2026
24b4f46
docs(coderd): drop the godoc-style comments from the scope tests
BobbyHo Aug 25, 2026
b92b7f9
docs(coderd/oauth2provider): trim the authorize.go comments
BobbyHo Aug 25, 2026
e4cc41d
Merge branch 'plat479-2-negotiate-scope' into plat479-3-report-negoti…
BobbyHo Aug 25, 2026
20caa9c
docs(coderd): trim the scope reporting test comments
BobbyHo Aug 25, 2026
c7d3d53
docs(site): trim the consent page scope comments
BobbyHo Aug 25, 2026
98545a6
feat(coderd): mint OAuth2 tokens with the negotiated scope
BobbyHo Aug 15, 2026
641e45e
test(coderd/oauth2provider): cover the negotiated scope end to end
BobbyHo Aug 18, 2026
1a30a9c
feat(coderd/oauth2provider): report the granted scope in token responses
BobbyHo Aug 18, 2026
8b46823
refactor(coderd/oauth2provider): clarify the unmintable scope sentinel
BobbyHo Aug 18, 2026
da5b590
test(coderd/oauth2provider): derive the exchange query from authorize…
BobbyHo Aug 18, 2026
fc6eb77
docs: scope the OAuth2 refresh limitation to narrowing
BobbyHo Aug 18, 2026
589b8b8
docs(coderd): trim the negotiated scope comments
BobbyHo Aug 25, 2026
78fbab1
Merge branch 'main' into plat479-2-negotiate-scope
BobbyHo Aug 26, 2026
f675cf1
fix(site/static): make the whole consent page reachable by scrolling
BobbyHo Aug 27, 2026
6b5f01d
Merge branch 'plat479-3-report-negotiated-scope' into plat480-1-apply…
BobbyHo Aug 27, 2026
90821d8
docs: say the negotiated scope now bounds the issued token
BobbyHo Aug 27, 2026
72b8cb5
docs: annotate the token endpoint with the response it returns
BobbyHo Aug 27, 2026
b6f74c3
feat: re-check the app allowlist at OAuth2 code redemption
BobbyHo Aug 28, 2026
9f3193e
docs(coderd/oauth2provider): trim the allowlist re-check comments
BobbyHo Aug 28, 2026
9e98cef
fix(coderd): make OAuth2 code redemption single-use under concurrency
BobbyHo Aug 28, 2026
48cb5a4
feat: let an OAuth2 refresh narrow the granted scope
BobbyHo Aug 29, 2026
ceb3997
Update coderd/oauth2provider/authorize.go
BobbyHo Aug 31, 2026
2cd9b60
Update coderd/oauth2provider/authorize.go
BobbyHo Aug 31, 2026
d160bda
docs(coderd/oauth2provider): trim the errNoGrantableScope comment
BobbyHo Aug 31, 2026
b60eee6
refactor(coderd/oauth2provider): canonicalize scopes before the catal…
BobbyHo Aug 31, 2026
4732d1f
refactor(coderd/oauth2provider): canonicalize the allowlist in one pass
BobbyHo Aug 31, 2026
03df6a9
test(coderd/rbac): pin the field sets scope coverage reads
BobbyHo Aug 31, 2026
a2d2856
docs(coderd/rbac): trim the TestCoverageModelFields comment
BobbyHo Aug 31, 2026
d83636b
Merge branch 'plat479-2-negotiate-scope' into plat479-3-report-negoti…
BobbyHo Aug 31, 2026
037e744
Merge remote-tracking branch 'origin/main' into plat479-3-report-nego…
BobbyHo Aug 31, 2026
cd35b94
Merge branch 'plat479-3-report-negotiated-scope' into plat480-1-apply…
BobbyHo Aug 31, 2026
508d09e
Merge branch 'plat480-1-apply-negotiated-scope' into plat480-2-stale-…
BobbyHo Aug 31, 2026
fc40ac3
Merge branch 'plat480-2-stale-scope-recheck' into plat480-3-single-us…
BobbyHo Aug 31, 2026
0e2bf76
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Aug 31, 2026
433e449
docs(coderd/oauth2provider): trim scope negotiation comments
BobbyHo Aug 31, 2026
5dffb74
Merge branch 'plat479-3-report-negotiated-scope' into plat480-1-apply…
BobbyHo Aug 31, 2026
6aa7510
docs(coderd/oauth2provider): trim scope negotiation comments
BobbyHo Aug 31, 2026
a1eae58
Merge branch 'plat480-1-apply-negotiated-scope' into plat480-2-stale-…
BobbyHo Aug 31, 2026
e1ea400
docs(coderd/oauth2provider): trim scope negotiation comments
BobbyHo Aug 31, 2026
52567a4
Merge branch 'plat480-2-stale-scope-recheck' into plat480-3-single-us…
BobbyHo Aug 31, 2026
8efc783
docs(coderd/oauth2provider): trim the single-use code comment
BobbyHo Aug 31, 2026
124d652
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Aug 31, 2026
5b08b81
docs(coderd/oauth2provider): trim refresh scope comments
BobbyHo Aug 31, 2026
35ce008
Merge branch 'main' into plat479-3-report-negotiated-scope
BobbyHo Aug 31, 2026
48d9c7f
fix(coderd/oauth2provider): return server_error for undecidable scope…
BobbyHo Sep 1, 2026
c8a3754
Merge branch 'plat479-3-report-negotiated-scope' into plat480-1-apply…
BobbyHo Sep 1, 2026
339aa34
Merge branch 'plat480-1-apply-negotiated-scope' into plat480-2-stale-…
BobbyHo Sep 1, 2026
6b29b13
Merge branch 'main' into plat480-1-apply-negotiated-scope
BobbyHo Sep 1, 2026
976335d
fix: answer invalid_grant for an unmintable stored scope
BobbyHo Sep 1, 2026
5ebc706
Merge branch 'plat480-1-apply-negotiated-scope' into plat480-2-stale-…
BobbyHo Sep 1, 2026
4a31118
Merge remote-tracking branch 'origin/main' into plat480-2-stale-scope…
BobbyHo Sep 2, 2026
cf7ddb7
Merge branch 'plat480-2-stale-scope-recheck' into plat480-3-single-us…
BobbyHo Sep 2, 2026
7a251f1
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Sep 2, 2026
c54ccdb
fix(coderd): address the allowlist re-check review
BobbyHo Sep 2, 2026
d5c8a1c
docs(coderd): simplify the scope check comments
BobbyHo Sep 2, 2026
bb574d0
Merge branch 'plat480-2-stale-scope-recheck' into plat480-3-single-us…
BobbyHo Sep 2, 2026
40fda97
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Sep 2, 2026
886ec18
refactor(coderd/oauth2provider): rename the coverage wrapper
BobbyHo Sep 2, 2026
d9d032d
test(coderd): cover replay and post-redemption state for single-use c…
BobbyHo Sep 3, 2026
8acedcd
Merge remote-tracking branch 'origin/main' into plat480-3-single-use-…
BobbyHo Sep 4, 2026
361f669
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Sep 4, 2026
85030f8
docs(coderd/oauth2provider): correct the canonicalization cross-refer…
BobbyHo Sep 4, 2026
ec80733
test(coderd/oauth2provider): assert the winner's token survives a ref…
BobbyHo Sep 4, 2026
98e6191
refactor(coderd): fold the duplicated app code delete into one query
BobbyHo Sep 4, 2026
15cc66f
docs(coderd): say why the code is deleted, and where single use can b…
BobbyHo Sep 4, 2026
b64f111
test(coderd/oauth2provider): enforce the redemption overlap in the test
BobbyHo Sep 4, 2026
270bfb5
Merge branch 'plat480-3-single-use-code' into plat481-1-narrow-refres…
BobbyHo Sep 4, 2026
f644e52
fix(coderd/oauth2provider): bound and sanitize the token endpoint's e…
BobbyHo Sep 4, 2026
663fa85
fix(coderd/oauth2provider): narrow the access token, not the grant
BobbyHo Sep 4, 2026
8f87b2d
fix(coderd/oauth2provider): name the way out when a refresh cannot widen
BobbyHo Sep 5, 2026
f54bbbc
fix(coderd/oauth2provider): canonicalize the ceiling once in narrowAc…
BobbyHo Sep 5, 2026
8d5f168
refactor(coderd/oauth2provider): address the review's nits and notes
BobbyHo Sep 5, 2026
e1b4f06
docs(admin/integrations): file the refresh narrowing under the code i…
BobbyHo Sep 5, 2026
2ba380a
test(coderd/oauth2provider): assert through the endpoint, not around it
BobbyHo Sep 5, 2026
755b5a1
fix(coderd/oauth2provider): honour scope on the exchange, and log sco…
BobbyHo Sep 5, 2026
e1f3f75
docs(coderd/oauth2provider): trim the scope comments
BobbyHo Sep 6, 2026
8d1c4f8
Merge remote-tracking branch 'origin/main' into plat481-1-narrow-refr…
BobbyHo Sep 9, 2026
a8e768e
Merge branch 'main' into plat481-1-narrow-refresh-scope
BobbyHo Sep 9, 2026
3cb7260
Merge branch 'main' into plat481-1-narrow-refresh-scope
BobbyHo Sep 9, 2026
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
76 changes: 46 additions & 30 deletions coderd/oauth2provider/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var (
errNoGrantableScope = xerrors.New("none of the scopes registered for this app are supported by this deployment; change the app's registered scopes to supported ones")
// The scope expands to permissions the allowlist does not cover.
errScopeNotAllowed = xerrors.New("scope requests permissions beyond this app's allowed scopes")
// A comparison that failed outright. The underlying error names RBAC
// The coverage check itself failed. The underlying error names RBAC
// internals, so it is logged rather than rendered.
errCoverageUndecidable = xerrors.New("scope coverage against this app's allowed scopes could not be determined")
errCoverageUndecidable = xerrors.New("scope coverage could not be determined")
)

// canonicalScopes rewrites each name to its api_key_scope enum spelling and
Expand All @@ -56,6 +56,18 @@ func canonicalScopes(names []string) []string {
return slice.Unique(canonical)
}

// firstUnknownScope returns the first name clients may not request, and whether
// there was one. The catalog is a curation, not a validity check: RBAC also
// expands internal-only names such as debug_info:read.
func firstUnknownScope(names []string) (string, bool) {
for _, name := range names {
if !rbac.IsExternalScope(rbac.ScopeName(name)) {
return name, true
}
}
return "", false
}

// noScopeAllowlist reports whether an app has no scope allowlist. NULL and ""
// are the same state: admin-created apps store NULL, DCR-registered apps store
// a possibly empty req.Scope. Whitespace-only is a configured allowlist that
Expand Down Expand Up @@ -92,30 +104,33 @@ func grantableScopes(appScope string) []string {
return filtered
}

// firstScopeOutsideAllowlist returns the first scope in granted that the
// allowlist does not confer, or "" when it confers all of them. It compares
// what the scopes grant, not their names: `coder:workspaces.access` covers
const (
phaseAuthorize = "authorize"
phaseRedeem = "redeem"
phaseRefresh = "refresh"
)

// firstScopeBeyondCeiling returns the first requested scope the ceiling does not
// confer, or "" when it confers all of them. It compares what the scopes grant,
// not their names: a ceiling of `coder:workspaces.access` covers
// `workspace:read`. Pass both slices through canonicalScopes first, since RBAC
// expands `coder:all` but not the bare `all` alias. A comparison it cannot
// decide refuses.
func firstScopeOutsideAllowlist(ctx context.Context, logger slog.Logger, phase string, appID uuid.UUID, allowlist, granted []string) (string, error) {
allowedNames := make([]rbac.ScopeName, 0, len(allowlist))
for _, a := range allowlist {
allowedNames = append(allowedNames, rbac.ScopeName(a))
}
requestedNames := make([]rbac.ScopeName, 0, len(granted))
for _, g := range granted {
requestedNames = append(requestedNames, rbac.ScopeName(g))
}
// One pass over the allowlist rather than one per granted scope.
outside, err := rbac.FirstScopeNotCovered(allowedNames, requestedNames)
func firstScopeBeyondCeiling(ctx context.Context, logger slog.Logger, phase string, appID uuid.UUID, ceiling, requested []string) (string, error) {
Comment thread
BobbyHo marked this conversation as resolved.
Comment thread
BobbyHo marked this conversation as resolved.
ceilingNames := slice.StringEnums[rbac.ScopeName](ceiling)
requestedNames := slice.StringEnums[rbac.ScopeName](requested)
// One pass over the ceiling rather than one per requested scope.
outside, err := rbac.FirstScopeNotCovered(ceilingNames, requestedNames)
if err != nil {
logger.Warn(ctx, "oauth2 scope coverage could not be determined",
slog.Error(err),
slog.F("phase", phase),
slog.F("app_id", appID.String()),
slog.F("allowlist", strings.Join(allowlist, " ")),
slog.F("ceiling", strings.Join(ceiling, " ")),
Comment thread
BobbyHo marked this conversation as resolved.
slog.F("scope", string(outside)))
// outside is a name from the ceiling, so it can be a stored value.
// Both handlers answer with a fixed string; rendering err.Error()
// here would echo it to the client.
return "", xerrors.Errorf("'%s': %w", outside, errCoverageUndecidable)
}
return string(outside), nil
Expand All @@ -139,13 +154,8 @@ func negotiateScope(ctx context.Context, logger slog.Logger, app database.OAuth2
// of the two aliases, so checking after the rewrite accepts the same names.
granted := canonicalScopes(requested)

// The catalog is a curation, not a validity check: RBAC also expands
// internal-only names such as debug_info:read, but clients may not request
// them.
for _, s := range granted {
if !rbac.IsExternalScope(rbac.ScopeName(s)) {
return "", xerrors.Errorf("%q: %w", s, errUnknownScope)
}
if unknown, ok := firstUnknownScope(granted); ok {
return "", xerrors.Errorf("'%s': %w", unknown, errUnknownScope)
}

if noScopeAllowlist(app.Scope) {
Expand All @@ -169,7 +179,7 @@ func negotiateScope(ctx context.Context, logger slog.Logger, app database.OAuth2
return strings.Join(allowlist, " "), nil // RFC 6749 §3.3 default
}

outside, err := firstScopeOutsideAllowlist(ctx, logger, "authorize", app.ID, allowlist, granted)
outside, err := firstScopeBeyondCeiling(ctx, logger, phaseAuthorize, app.ID, allowlist, granted)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -207,6 +217,15 @@ func consentScopes(granted string) (names []string, unrestricted bool) {
// short enough for a Location header to survive the proxies in front of it.
const maxErrorDescription = 2048

// capErrorDescription bounds a description, whose length is otherwise the
// client's to choose.
func capErrorDescription(description string) string {
if len(description) > maxErrorDescription {
return description[:maxErrorDescription] + " (truncated)"
}
return description
}

// responseTypeCode is the only response type this server supports. response_type
// is read as text rather than through the SDK enum so every unsupported value
// takes one path, instead of splitting on whether a Go constant happens to
Expand Down Expand Up @@ -533,11 +552,8 @@ func (a authorizeResponse) codeURL(code string) *url.URL {
}

func redirectAuthorizeError(rw http.ResponseWriter, r *http.Request, logger slog.Logger, response authorizeResponse, code codersdk.OAuth2ErrorCode, description string) {
// Descriptions echo values the client sent, so their length is the client's
// to choose. Cap here, ahead of both the log field and the Location header.
if len(description) > maxErrorDescription {
description = description[:maxErrorDescription] + " (truncated)"
}
// Capped ahead of both the log field and the Location header.
description = capErrorDescription(description)

app := httpmw.OAuth2ProviderApp(r)
logger.Info(r.Context(), "oauth2 authorization rejected",
Expand Down
28 changes: 26 additions & 2 deletions coderd/oauth2provider/authorize_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ var (
ReasonCoverageUndecidable = errCoverageUndecidable.Error()
)

// MaxErrorDescription is the description bound, for the same tests.
const MaxErrorDescription = maxErrorDescription

// TestGrantableScopesNotSizedByInput pins the shape of the result, not just its
// contents. app.Scope is unvalidated registration metadata read on every
// authorization and redemption, so collecting duplicates and dropping them
Expand Down Expand Up @@ -383,6 +386,27 @@ func TestHashOAuth2State(t *testing.T) {
})
}

func TestCapErrorDescription(t *testing.T) {
t.Parallel()

t.Run("ShortDescriptionUnchanged", func(t *testing.T) {
t.Parallel()
assert.Equal(t, "unknown or unsupported scope", capErrorDescription("unknown or unsupported scope"))
})

t.Run("BoundIsInclusive", func(t *testing.T) {
t.Parallel()
atBound := strings.Repeat("x", maxErrorDescription)
assert.Equal(t, atBound, capErrorDescription(atBound))
})

t.Run("LongerDescriptionTruncated", func(t *testing.T) {
t.Parallel()
got := capErrorDescription(strings.Repeat("x", maxErrorDescription+1))
assert.Equal(t, strings.Repeat("x", maxErrorDescription)+" (truncated)", got)
})
}

func TestSanitizeErrorDescription(t *testing.T) {
t.Parallel()

Expand All @@ -397,13 +421,13 @@ func TestSanitizeErrorDescription(t *testing.T) {
want: "Only response_type=code is supported",
},
{
// What negotiateScope's %q produces for a well-behaved scope name.
// §5.2 excludes the double quote.
name: "QuotedScopeBecomesApostrophes",
description: `"openid": unknown or unsupported scope`,
want: "'openid': unknown or unsupported scope",
},
{
// %q escapes a quote inside the value; the backslash goes with it.
// §5.2 excludes the backslash too.
name: "EscapedQuoteLosesItsBackslash",
description: `"\"><img>": unknown or unsupported scope`,
want: "''><img>': unknown or unsupported scope",
Expand Down
Loading
Loading