Skip to content

Commit

Permalink
Add crate to audit content security policy (#2993)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 9, 2024
1 parent adb6f25 commit bf7ad35
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions crates/audit-content-security-policy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "audit-content-security-policy"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
colored = "2.0.4"
reqwest = { version = "0.11.22", features = ["blocking"] }
93 changes: 93 additions & 0 deletions crates/audit-content-security-policy/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use {colored::Colorize, reqwest::blocking::get, std::process};

const SERVERS: &[(&str, &str, &str)] = &[
(
"regtest.ordinals.net",
"/content/41bf99a297ca79d181160a91fc0efc8a71170ee24b87783c9c11b0fcbe23615fi0",
"https://regtest.ordinals.com/content/",
),
(
"regtest.ordinals.com",
"/content/41bf99a297ca79d181160a91fc0efc8a71170ee24b87783c9c11b0fcbe23615fi0",
"https://regtest.ordinals.com/content/",
),
(
"signet.ordinals.net",
"/content/7e1bc3b56b872aaf4d1aaf1565fac72182313c9142b207f9398afe263e234135i0",
"https://signet.ordinals.com/content/",
),
(
"signet.ordinals.com",
"/content/7e1bc3b56b872aaf4d1aaf1565fac72182313c9142b207f9398afe263e234135i0",
"https://signet.ordinals.com/content/",
),
(
"testnet.ordinals.net",
"/content/0a1b4e4acf89686e4d012561014041bffd57a62254486f24cb5b0a216c04f102i0",
"https://testnet.ordinals.com/content/",
),
(
"testnet.ordinals.com",
"/content/0a1b4e4acf89686e4d012561014041bffd57a62254486f24cb5b0a216c04f102i0",
"https://testnet.ordinals.com/content/",
),
(
"alpha.ordinals.net",
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0",
"https://ordinals.com/content/",
),
(
"bravo.ordinals.net",
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0",
"https://ordinals.com/content/",
),
(
"charlie.ordinals.net",
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0",
"https://ordinals.com/content/",
),
(
"ordinals.com",
"/content/6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0",
"https://ordinals.com/content/",
),
];

fn main() {
let mut failures = 0;

for (host, path, needle) in SERVERS {
eprint!("GET {host}");

let response = get(format!("https://{host}{path}")).unwrap();

let mut fail = false;

if !response.status().is_success() {
eprint!(" {}", response.status().to_string().red());
fail = true;
}

let headers = response.headers();

let content_security_policy = headers
.get("content-security-policy")
.map(|value| value.to_str().unwrap().to_string())
.unwrap_or_default();

if !content_security_policy.contains(needle) {
fail = true;
}

if fail {
eprintln!(" {}", "FAIL".red());
failures += 1;
} else {
eprintln!(" {}", "PASS".green());
}
}

if failures > 0 {
process::exit(1);
}
}
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ update-mdbook-theme:
audit-cache:
cargo run --package audit-cache

audit-content-security-policy:
cargo run --package audit-content-security-policy

coverage:
cargo llvm-cov

Expand Down

0 comments on commit bf7ad35

Please sign in to comment.