-
Notifications
You must be signed in to change notification settings - Fork 55
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to hand-rolled http mux. #313
Conversation
This fixes the error where `/priv/doc/https://` URLs were being improperly unescaped before fetching/signing.
This helps detect errors in the mux config. Also, restrict mux to GET/HEAD - this uncovered a faulty test that expected POST to work, when it never had.
This complies with the recommendation at https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html#seccons-content-sniffing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a very quick pass. Is there an actual test for the escape/unescaping?
Have mux not depend on handler types. (This means the caller of New() may accidentally swap handlers, but that vector for error is only one line of the whole code base, so it seems like a reasonable trade-off.)
Test for the escaping is in signer_test.
|
Also, got rid of all the capitalization changes & the need for the separate |
// True iff url matches pattern, as defined by an [URLSet.Sign] block in the | ||
// config file. The format of this URLPattern is validated by | ||
// validateSignURLPattern in config.go. | ||
func signURLMatches(url *url.URL, pattern *util.URLPattern) error { | ||
for _, b := range []byte(url.String()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, leverage Go's IndexFunc, e.g. if IndexFun(url.String(), isFallbackURLCodePoint) == -1 { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could work? https://golang.org/pkg/bytes/#IndexFunc is based on a UTF-8 decoding of the string, whereas I want to go byte-by-byte. I think any multibyte UTF-8 char is also false for isFallbackURLCodePoint
? But I don't want to have to think about it. :)
Fixes breakage from ampproject#313 (9c34d5e). Also, when "fetch/sign URLs do not match config", log the underlying reason(s). Finally, improve the logging in gateway_server slightly + `go fmt`.
This fixes the error where
/priv/doc/https://
URLs were beingimproperly unescaped before fetching/signing.
In addition, validate that sign URLs don't contain any special characters, per the WICG recommendation.
The new mux code depends directly on the handlers, because we don't need any fancy dependency inversion. This required movings tests into a different package to break the import cycle, which in turn required changing the visibility of a lot of things.
Resolves #310.