oficina / alta Public

Refuse a sign-in Location holding a # or a backslash

Astra's review of bb73d22 found that /authorize?consumer=docs# passed,
because url.Parse drops an empty fragment. A backslash in the query
passed too. authorizeTarget now refuses both characters in the raw
Location before parsing, which also covers every non-empty fragment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 0912560317dd9a8fa6370202dd35c83a2c7b4f91 parent bb73d22
2 files changed, +13 −2
  • adopt/delivery.go +7 −2
  • adopt/homeidentity_test.go +6 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/alta/adopt	18.658s
ok  	amadan.net/oficina/alta/carlosop	(cached)
?   	amadan.net/oficina/alta/carlosop/fakecarlos	[no test files]
ok  	amadan.net/oficina/alta/cmd/alta	(cached)
ok  	amadan.net/oficina/alta/cmd/alta-adopt	22.022s
ok  	amadan.net/oficina/alta/console	(cached)
?   	amadan.net/oficina/alta/console/fakeconsole	[no test files]
ok  	amadan.net/oficina/alta/homeop	(cached)
ok  	amadan.net/oficina/alta/homeop/fakehome	(cached)
ok  	amadan.net/oficina/alta/internal/web	(cached)
ok  	amadan.net/oficina/alta/provision	(cached)
=== compat ===
cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/altacompat	(cached)
diff --git a/adopt/delivery.go b/adopt/delivery.go
index dadfad7..a44394e 100644
--- a/adopt/delivery.go
+++ b/adopt/delivery.go
@@ -309,11 +309,16 @@ func signInIdentity(ctx context.Context, h *http.Client, origin string) (issuer,
// authorizeTarget is the issuer and consumer of a Location that is exactly
// HomeIssuerOrigin's /authorize with one non-empty consumer parameter, and
-// two empty strings for any other.
+// two empty strings for any other. A # or a backslash is refused in the
+// raw text: url.Parse drops an empty fragment and keeps a backslash in the
+// query, and browsers read a backslash differently from it.
func authorizeTarget(location string) (issuer, consumer string) {
+ if strings.ContainsAny(location, "#\\") {
+ return "", ""
+ }
u, err := url.Parse(location)
if err != nil || u.User != nil || u.Scheme+"://"+u.Host != HomeIssuerOrigin ||
- u.Path != "/authorize" || u.RawPath != "" || u.Fragment != "" {
+ u.Path != "/authorize" || u.RawPath != "" {
return "", ""
}
q, err := url.ParseQuery(u.RawQuery)
diff --git a/adopt/homeidentity_test.go b/adopt/homeidentity_test.go
index d33f2cb..d7fcd98 100644
--- a/adopt/homeidentity_test.go
+++ b/adopt/homeidentity_test.go
@@ -100,6 +100,12 @@ func TestPreflightRefusesSignInLookalikes(t *testing.T) {
"trailing slash": {redirectTo(303, HomeIssuerOrigin+"/authorize/?consumer=docs"), both},
"encoded path": {redirectTo(303, HomeIssuerOrigin+"/%61uthorize?consumer=docs"), both},
"fragment": {redirectTo(303, HomeIssuerOrigin+good+"#consumer=docs"), both},
+ "empty fragment": {redirectTo(303, HomeIssuerOrigin+good+"#"), both},
+ "backslash in host": {redirectTo(303, "https://id.oficina.works\\@evil.example"+good), both},
+ "backslash for path": {redirectTo(303, "https://id.oficina.works\\authorize?consumer=docs"), both},
+ "backslash in path": {redirectTo(303, HomeIssuerOrigin+"/authorize\\?consumer=docs"), both},
+ "backslash in query": {redirectTo(303, HomeIssuerOrigin+good+"\\"), both},
+ "backslash consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=docs\\"), both},
"repeated consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=docs&consumer=docs"), both},
"empty consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=&nonce=n"), both},
"no consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?nonce=n"), both},