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

Forbid | in URL hosts #751

Merged
merged 2 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
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
34 changes: 16 additions & 18 deletions url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,21 @@ impl Host<String> {
}

let is_invalid_domain_char = |c| {
matches!(
c,
| '\0'..='\u{001F}'
| ' '
| '#'
| '%'
| '/'
| ':'
| '<'
| '>'
| '?'
| '@'
| '['
| '\\'
| ']'
| '^'
| '\u{007F}'
)
matches!(c, |'\0'..='\u{001F}'| ' '
| '#'
| '%'
| '/'
| ':'
| '<'
| '>'
| '?'
| '@'
| '['
| '\\'
| ']'
| '^'
| '\u{007F}'
| '|')
};

if domain.find(is_invalid_domain_char).is_some() {
Expand Down Expand Up @@ -146,6 +143,7 @@ impl Host<String> {
| '\\'
| ']'
| '^'
| '|'
)
};

Expand Down
45 changes: 45 additions & 0 deletions url/tests/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4707,6 +4707,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "sc://a|b/",
"base": "about:blank",
"failure": true
},
"Forbidden host codepoints: tabs and newlines are removed during preprocessing",
{
"input": "foo://ho\u0009st/",
Expand Down Expand Up @@ -4931,6 +4936,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "http://a|b/",
"base": "about:blank",
"failure": true
},
{
"input": "http://a\u007Fb/",
"base": "about:blank",
Expand Down Expand Up @@ -5200,6 +5210,11 @@
"base": "about:blank",
"failure": true
},
{
"input": "http://ho%7Cst/",
"base": "about:blank",
"failure": true
},
{
"input": "http://ho%7Fst/",
"base": "about:blank",
Expand Down Expand Up @@ -5777,6 +5792,36 @@
"base": "about:blank",
"failure": true
},
{
"input": "file://%43%7C",
"base": "about:blank",
"failure": true
},
{
"input": "file://%43|",
"base": "about:blank",
"failure": true
},
{
"input": "file://C%7C",
"base": "about:blank",
"failure": true
},
{
"input": "file://%43%7C/",
"base": "about:blank",
"failure": true
},
{
"input": "https://%43%7C/",
"base": "about:blank",
"failure": true
},
{
"input": "asdf://%43|/",
"base": "about:blank",
"failure": true
},
{
"input": "asdf://%43%7C/",
"base": "about:blank",
Expand Down