Skip to content

Commit bedded7

Browse files
authored
Merge pull request #72 from Taym95/fix-csp-trailing-dot-host-source
Allow trailing dot CSP host-source
2 parents 7ac6c48 + 97e13ee commit bedded7

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,8 @@ static SCHEME_SOURCE_GRAMMAR: Lazy<Regex> =
19251925
Lazy::new(|| Regex::new(r#"^(?P<scheme>[a-zA-Z][a-zA-Z0-9\+\-\.]*):$"#).unwrap());
19261926
/// https://www.w3.org/TR/CSP/#grammardef-host-source
19271927
static HOST_SOURCE_GRAMMAR: Lazy<Regex> = Lazy::new(|| {
1928-
Regex::new(r#"^((?P<scheme>[a-zA-Z][a-zA-Z0-9\+\-\.]*)://)?(?P<host>\*|(\*\.)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*)(?P<port>:(\*|[0-9]+))?(?P<path>/([:@%!\$&'\(\)\*\+,;=0-9a-zA-Z\-\._~]+)?(/[:@%!\$&'\(\)\*\+,;=0-9a-zA-Z\-\._~]*)*)?$"#).unwrap()
1928+
// host-part = "*" / [ "*." ] 1*host-char *( "." 1*host-char ) [ "." ]
1929+
Regex::new(r#"^((?P<scheme>[a-zA-Z][a-zA-Z0-9\+\-\.]*)://)?(?P<host>\*|(\*\.)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*\.?)(?P<port>:(\*|[0-9]+))?(?P<path>/([:@%!\$&'\(\)\*\+,;=0-9a-zA-Z\-\._~]+)?(/[:@%!\$&'\(\)\*\+,;=0-9a-zA-Z\-\._~]*)*)?$"#).unwrap()
19291930
});
19301931
/// https://www.w3.org/TR/CSP/#grammardef-hash-source
19311932
static HASH_SOURCE_GRAMMAR: Lazy<Regex> = Lazy::new(|| {

tests/examples.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ test_should_request_be_blocked! {
4444
policy: "connect-src https://*.notriddle.com:0443",
4545
dest: None,
4646
result: Allowed),
47+
( name: pre_request_connect_allow_trailing_dot_host_source,
48+
url: "https://www.notriddle.com.:443/meta",
49+
origin: "https://example.com",
50+
policy: "connect-src https://www.notriddle.com.:443",
51+
dest: None,
52+
result: Allowed),
4753
( name: pre_request_wild_script_allow,
4854
url: "https://www.notriddle.com/script.js",
4955
origin: "https://www.notriddle.com",

0 commit comments

Comments
 (0)