Skip to content
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

Merged
merged 7 commits into from
May 28, 2019
Merged

Conversation

twifkak
Copy link
Member

@twifkak twifkak commented May 24, 2019

This fixes the error where /priv/doc/https:// URLs were being
improperly 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.

twifkak added 3 commits May 23, 2019 18:25
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.
Copy link
Collaborator

@alin04 alin04 left a 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?

packager/mux/mux.go Outdated Show resolved Hide resolved
packager/mux/mux.go Show resolved Hide resolved
packager/mux/mux.go Outdated Show resolved Hide resolved
packager/mux/mux.go Show resolved Hide resolved
packager/mux/mux.go Outdated Show resolved Hide resolved
packager/mux/params/params.go Outdated Show resolved Hide resolved
packager/signer/signer.go Outdated Show resolved Hide resolved
twifkak added 4 commits May 24, 2019 14:56
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.)
Selectively, on changed lines, to minimize conflict on rebase.
@twifkak
Copy link
Member Author

twifkak commented May 24, 2019

Test for the escaping is in signer_test.

  • For the validation.go change, see TestEscapeQueryParamsInFetchAndSign and TestDisallowInvalidCharsSign. (Hmm, perhaps that should be in validation_test.go.)
  • For the mux change, see the 3 TestSignAsPathParam* tests.

@twifkak
Copy link
Member Author

twifkak commented May 24, 2019

Also, got rid of all the capitalization changes & the need for the separate params pkg.

@twifkak twifkak marked this pull request as ready for review May 24, 2019 23:07
// 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()) {
Copy link
Collaborator

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 { ... }

Copy link
Member Author

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. :)

@twifkak twifkak merged commit 9c34d5e into ampproject:master May 28, 2019
@twifkak twifkak deleted the inner_url branch May 28, 2019 22:28
twifkak added a commit to twifkak/amppackager that referenced this pull request Jun 11, 2019
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`.
@twifkak twifkak mentioned this pull request Jun 11, 2019
twifkak added a commit that referenced this pull request Jun 11, 2019
Fixes breakage from #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`.
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.

3 participants