-
Notifications
You must be signed in to change notification settings - Fork 254
normalize domains with trailing slashes #477
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ def minify_source_list(directive, source_list) | |
| else | ||
| source_list = populate_nonces(directive, source_list) | ||
| source_list = reject_all_values_if_none(source_list) | ||
| source_list = normalize_uri_paths(source_list) | ||
|
|
||
| unless directive == REPORT_URI || @preserve_schemes | ||
| source_list = strip_source_schemes(source_list) | ||
|
|
@@ -147,6 +148,19 @@ def reject_all_values_if_none(source_list) | |
| end | ||
| end | ||
|
|
||
| def normalize_uri_paths(source_list) | ||
| source_list.map do |source| | ||
| # Normalize domains ending in a single / as without omitting the slash accomplisheg the same. | ||
| # https://www.w3.org/TR/CSP3/#match-paths § 6.6.2.10 Step 2 | ||
| if source.chomp("/").include?("/") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing this might not be normalizing is a CSP directive like The quoted spec is about matching on the It would be good to address this, with unit tests as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a test and some code to fix this. The code doesn't feel great, I'd welcome more elegant solutions here! |
||
| source | ||
| else | ||
| source.chomp("/") | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| # Removes duplicates and sources that already match an existing wild card. | ||
| # | ||
| # e.g. *.github.com asdf.github.com becomes *.github.com | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.