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

Error if bucket name contains scheme #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ func main() {
*s3prefix = *logURL
}

_, err := url.ParseRequestURI(*s3bucket)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the documentation for ParseRequestURI it doesn't seem to say it will reject absolute URIs (starting with a scheme). It actually seems to say the opposite - that it will accept them. Does this definitely work?

Copy link
Member Author

@pgporada pgporada Sep 11, 2023

Choose a reason for hiding this comment

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

From my manual testing, yes it works.

$ go run . -log-url https://oak.ct.letsencrypt.org/2023 -tile-size 256 -s3-bucket s3://whatever
2023/09/11 14:36:11 scheme provided for s3-bucket, but should not be
exit status 1

$ go run . -log-url https://oak.ct.letsencrypt.org/2023 -tile-size 256 -s3-bucket whoops://hasotherscheme
2023/09/11 14:36:34 scheme provided for s3-bucket, but should not be
exit status 1

# As expected, runs ctile instead of erroring out
$ go run . -log-url https://oak.ct.letsencrypt.org/2023 -tile-size 256 -s3-bucket noscheme
^Csignal: interrupt

What I'm ultimately relying on using url.ParseRequestURI is that the call to getScheme returns nil, because if it does there's a good chance that a scheme was found and I can return an error to the ctile user.

if err == nil {
log.Fatal("scheme provided for s3-bucket, but should not be")
}
pgporada marked this conversation as resolved.
Show resolved Hide resolved

cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
log.Fatal(err)
Expand Down