Skip to content

Commit

Permalink
feat: allow localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Jun 25, 2024
1 parent 7c8cd49 commit d4311e9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/http_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,6 @@ impl TokenManager {

fn build_content_security_header(domains: Vec<Domain>) -> String {
let urls = domains.iter().map(AsRef::as_ref).flat_map(|domain| {
// TODO support abc.localhost
// TODO support localhost:8080
// TODO support 127.0.0.1
// TODO support ::1
let proto = if domain == "localhost" {
"http://"
} else {
Expand All @@ -329,7 +325,12 @@ fn build_content_security_header(domains: Vec<Domain>) -> String {
[" ", proto, "*.", domain, " ", proto, domain]
});

iter::once("frame-ancestors").chain(urls).collect()
let localhost_urls = " https://localhost:* http://localhost:* https://*.localhost:* http://*.localhost:* https://127.0.0.1:* http://127.0.0.1:*";

iter::once("frame-ancestors")
.chain(urls)
.chain(iter::once(localhost_urls))
.collect()
}

#[test]
Expand All @@ -342,14 +343,14 @@ fn test_build_content_security_header() {

case(
&["walletconnect.com"],
"frame-ancestors https://*.walletconnect.com https://walletconnect.com",
"frame-ancestors https://*.walletconnect.com https://walletconnect.com https://localhost:* http://localhost:* https://*.localhost:* http://*.localhost:* https://127.0.0.1:* http://127.0.0.1:*",
);

case(
&["walletconnect.com", "vercel.app", "localhost"],
"frame-ancestors https://*.walletconnect.com https://walletconnect.com \
https://*.vercel.app https://vercel.app \
http://*.localhost http://localhost",
http://*.localhost http://localhost https://localhost:* http://localhost:* https://*.localhost:* http://*.localhost:* https://127.0.0.1:* http://127.0.0.1:*",
);
}

Expand Down

0 comments on commit d4311e9

Please sign in to comment.