Skip to content

fix: escape realm in WWW-Authenticate challenges - #920

Merged
butonic merged 1 commit into
mainfrom
fix/escape-www-authenticate-realm
Oct 28, 2026
Merged

butonic merged 1 commit into
mainfrom
fix/escape-www-authenticate-realm

Conversation

@kulmann

@kulmann kulmann commented Oct 27, 2026

Copy link
Copy Markdown
Member

Don't really know if this is really needed, but both me and @dragotin couldn't find any escaping of the host on any higher level. Is this a good idea then?

@kulmann
kulmann requested review from aduffeck and rhafer October 27, 2026 09:39
@kulmann kulmann self-assigned this Oct 27, 2026
@kulmann
kulmann requested review from butonic and maki5 October 27, 2026 09:39

@butonic butonic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO yes, let's get this in. RFC 9110 requires the realm to be sent quoted, and inside it only " and \ need a backslash, which is exactly what Challenge does:

For historical reasons, a sender MUST only generate the quoted-string syntax.

https://www.rfc-editor.org/rfc/rfc9110#section-11.5

A sender SHOULD NOT generate a quoted-pair in a quoted-string except where necessary to quote DQUOTE and backslash octets occurring within that string.

https://www.rfc-editor.org/rfc/rfc9110#section-5.6.4

AFAICT the r.Host fallback can't be abused today, because the HTTP/1 server already rejects a Host header containing " or \ with a 400 (httpguts.ValidHostHeader in net/http/server.go). So in practice this hardens the configured realm. It's still the right thing to do and costs nothing.

Not a blocker IMO: params ...string gets appended unescaped. That's fine for charset="UTF-8", but the signature makes it easy to pass something unescaped later. Taking key/value pairs and quoting them inside Challenge would avoid that ... or we just keep the comment as is.

👍

@butonic
butonic merged commit 2f017ae into main Oct 28, 2026
19 of 20 checks passed
@butonic
butonic deleted the fix/escape-www-authenticate-realm branch October 28, 2026 09:58
@openclouders openclouders mentioned this pull request Oct 28, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants