**TL;DR** Last of the stack, split out of #28045. #28178 decided what the scope is; this PR is everything that reports it, to the user on the consent page and to the client on rejection. | PR | What it does | |---|---| | #28007 | Schema: `codes.scope` and `tokens.scope`, so a negotiated scope has somewhere to live. Every code is still stamped unrestricted. | | #28167 | `ScopesCover` compares an allowlist against a request by permission coverage rather than by name, and fails closed on any shape it does not model. Added with no production callers. | | #28178 | The authorize endpoint checks the request against the scope catalog, grants it only if the app's filtered allowlist covers it, and persists the result on the code. | | **#28179 (this)** | The consent page lists the negotiated permissions, and `invalid_scope` reaches the client's own callback per RFC 6749 §4.1.2.1 instead of a Coder error page. Retires the interim plumbing #28178 left behind. | - #28178 has merged, so this diff is against main and reviews on its own. It is still worth reading first: nothing here decides a scope, it only reports the one `negotiateScope` already returns. - **The consent page HTML is not final.** Layout and wording in `site/static/oauth2allow.html` are still being refined. It is in this branch so the scope-enforcement flow can be exercised end to end in a browser, not because the markup is settled. The reviewable part of Half A is the Go side that decides what the page states; the presentation will change. - An unrestricted grant still reads as full access, not as a scope name. Nothing about what a token can do changes in this PR either. **Where in the flow** - Authorize endpoint only, both verbs. GET decides what the consent page states; both verbs send `invalid_scope` to the callback. The token exchange, refresh, and revocation are untouched. - `negotiateScope` is unchanged from #28178, so which requests succeed is unchanged. This PR reads its result twice: once to decide what the page lists, once to decide where the rejection goes. - The endpoint sits behind `apiKeyMiddlewareRedirect`, so the user is authenticated before any of this runs. That matters for the redirect, not just for the page. - Consent page rendering moves a decision into Go rather than the template: `RenderOAuthAllowData` carries `Scopes` and `Unrestricted` separately, and the template branches on `Unrestricted` alone. **What it satisfies** - RFC 6749 §4.1.2.1 — on a failure that is not a bad redirection URI, the server "informs the client by adding the following parameters to the query component of the redirection URI". `invalid_scope` now goes there. #28178's interim delivery, a static error page on GET and an error body on POST, is what this replaces. - RFC 6749 §4.1.2.1 — `state` is "REQUIRED if a `state` parameter was present in the client authorization request", so it is echoed only when the client sent one, never synthesized. Pinned by `OmittedStateNotEchoed`. - RFC 6749 §3.1.2.4 and §4.1.2.1 — on a "missing, invalid, or mismatching redirection URI" the server "MUST NOT automatically redirect the user-agent to the invalid redirection URI". This is the whole ordering argument, and the file's other error paths keep their existing delivery precisely because several of them are where that validation fails. - RFC 9700 §2.1 — pre-registered redirection URIs "MUST utilize exact string matching". `extractAuthorizeParams` already did this before the stack; Half B depends on it rather than adding it. - RFC 9700 §4.11.2 — names this exact hazard: an attacker who registers a client can "intentionally send an erroneous authorization request, e.g., by using an invalid scope value, thus instructing the authorization server to redirect the user agent to its phishing site". The destination is still only ever a URI that client registered, so this is a phishing surface that costs an attacker a registration, not an open redirect. The precaution the section requires, authenticating the user first, is what `apiKeyMiddlewareRedirect` provides. - RFC 9700 §4.12 — a server redirecting a request that may carry credentials "MUST NOT use the HTTP 307 status code". 302, matching the success redirect beside it. - RFC 6749 §4.1.2.1 — `server_error` exists "because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect". An unusable registered callback is the one case with nowhere to redirect, so it answers 500 on both verbs and logs the app and URL for an operator to correlate by. - Not yet: §1.4.1 still wants `scope` in the token response when the grant differs from the request. Tokens are untouched here, as in #28178, so that lands with enforcement. --- Split out of #28045 ([PLAT-479](https://linear.app/codercom/issue/PLAT-479)). Last of three. #28178 has merged, so this reviews against main. #28178 decided what the scope is. This PR is everything that tells someone about it. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
210 lines
5.8 KiB
HTML
210 lines
5.8 KiB
HTML
{{/* This template is used by application handlers to render allowing oauth2
|
|
links */}}
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Application {{.AppName}}</title>
|
|
<style>
|
|
* {
|
|
padding: 0;
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
html,
|
|
body {
|
|
background-color: #05060b;
|
|
color: #f7f9fd;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-family: sans-serif;
|
|
font-size: 16px;
|
|
/* A fixed height would let align-items: center push a long scope list
|
|
past both edges, leaving the top half unreachable by scrolling. */
|
|
min-height: 100%;
|
|
}
|
|
|
|
.container {
|
|
--side-padding: 24px;
|
|
width: 100%;
|
|
max-width: calc(320px + var(--side-padding) * 2);
|
|
padding: 0 var(--side-padding);
|
|
text-align: center;
|
|
}
|
|
|
|
.icons-container {
|
|
align-items: center;
|
|
display: flex;
|
|
justify-content: center;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.coder-svg,
|
|
.app-icon {
|
|
width: 80px;
|
|
}
|
|
|
|
.connect-symbol {
|
|
font-size: 40px;
|
|
font-weight: bold;
|
|
margin: 0 10px;
|
|
}
|
|
|
|
h1 {
|
|
font-weight: 700;
|
|
font-size: 36px;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
p,
|
|
li {
|
|
color: #b2bfd7;
|
|
line-height: 140%;
|
|
}
|
|
|
|
.user-name {
|
|
font-weight: bold;
|
|
}
|
|
|
|
#scope-list {
|
|
list-style: none;
|
|
margin-top: 12px;
|
|
/* The container centres its text, which would stagger the left edges. */
|
|
text-align: left;
|
|
padding-left: 8px;
|
|
}
|
|
|
|
#scope-disclaimer {
|
|
font-size: 13px;
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.button-group {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 12px;
|
|
margin-top: 24px;
|
|
}
|
|
|
|
.button-group a,
|
|
.button-group button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 6px 16px;
|
|
border-radius: 4px;
|
|
border: 1px solid #2c3854;
|
|
text-decoration: none;
|
|
background: none;
|
|
font-size: inherit;
|
|
color: inherit;
|
|
width: 200px;
|
|
height: 42px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.button-group a:hover,
|
|
.button-group button:hover {
|
|
border-color: hsl(222, 31%, 40%);
|
|
}
|
|
|
|
.button-group .primary-button {
|
|
background-color: #2c3854;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="icons-container">
|
|
{{- if .AppIcon }}
|
|
<img class="app-icon" src="{{ .AppIcon }}" />
|
|
<div class="connect-symbol">+</div>
|
|
{{end}}
|
|
<img class="coder-svg" src="/icon/coder.svg" alt="Coder" />
|
|
</div>
|
|
<h1>Authorize {{ .AppName }}</h1>
|
|
{{- if not .Unrestricted }}
|
|
<p id="description">
|
|
Allow {{ .AppName }} to access your
|
|
<span class="user-name">{{ .Username }}</span> account with these
|
|
permissions?
|
|
</p>
|
|
{{- /* WebKit drops implicit list semantics when list-style is none,
|
|
leaving VoiceOver to announce the permissions as loose text. */}}
|
|
<ul id="scope-list" role="list">
|
|
{{- range .Scopes }}
|
|
<li role="listitem">{{ . }}</li>
|
|
{{- end }}
|
|
</ul>
|
|
{{- /* Scope identifiers read narrower than they grant: template:read
|
|
reaches every template in the deployment, not the one in play. */}}
|
|
<p id="scope-disclaimer">
|
|
These are technical permission names. Grant them only to an application
|
|
you trust.
|
|
</p>
|
|
{{- else }}
|
|
<p id="description">
|
|
Allow {{ .AppName }} to have full access to your
|
|
<span class="user-name">{{ .Username }}</span> account?
|
|
</p>
|
|
{{- end }}
|
|
<div class="button-group" id="button-group">
|
|
<form id="allow-form" method="POST" style="display: inline;">
|
|
<input type="hidden" name="csrf_token" value="{{ .CSRFToken }}" />
|
|
<button type="submit" class="primary-button">Allow</button>
|
|
</form>
|
|
<a id="cancel-link" href="{{ .CancelURI }}">Cancel</a>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
(function () {
|
|
var appName = "{{ .AppName }}";
|
|
var description = document.getElementById("description");
|
|
var buttonGroup = document.getElementById("button-group");
|
|
var allowForm = document.getElementById("allow-form");
|
|
var cancelLink = document.getElementById("cancel-link");
|
|
var scopeList = document.getElementById("scope-list");
|
|
var scopeDisclaimer = document.getElementById("scope-disclaimer");
|
|
|
|
function showFeedback(message) {
|
|
buttonGroup.style.display = "none";
|
|
if (scopeList) {
|
|
scopeList.style.display = "none";
|
|
}
|
|
if (scopeDisclaimer) {
|
|
scopeDisclaimer.style.display = "none";
|
|
}
|
|
description.textContent = message;
|
|
}
|
|
|
|
allowForm.addEventListener("submit", function (e) {
|
|
e.preventDefault();
|
|
showFeedback(
|
|
appName +
|
|
" is now authorized to access your account. This window can now be closed."
|
|
);
|
|
setTimeout(function () {
|
|
allowForm.submit();
|
|
}, 500);
|
|
});
|
|
|
|
cancelLink.addEventListener("click", function (e) {
|
|
e.preventDefault();
|
|
showFeedback(
|
|
appName +
|
|
" was denied access to your account. This window can now be closed."
|
|
);
|
|
setTimeout(function () {
|
|
window.location.href = cancelLink.href;
|
|
}, 500);
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|