Skip to content

Commit 4a5ab5a

Browse files
committed
Add a .well-known/security.txt
1 parent 722d619 commit 4a5ab5a

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ toml = "0.8"
1515
serde_json = "1.0"
1616
rust_team_data = { git = "https://github.com/rust-lang/team" }
1717
percent-encoding = "2.1.0"
18+
19+
[dev-dependencies]
20+
time = { version = "0.3.36", features = ["parsing"] }

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ fn redirect_bare_en_us() -> Redirect {
233233
Redirect::permanent("/")
234234
}
235235

236+
#[get("/.well-known/security.txt")]
237+
fn well_known_security() -> &'static str {
238+
include_str!("../static/text/well_known_security.txt")
239+
}
240+
236241
#[catch(404)]
237242
#[allow(clippy::result_large_err)]
238243
fn not_found(req: &Request) -> Result<Template, Redirect> {
@@ -459,6 +464,7 @@ async fn rocket() -> _ {
459464
team_locale,
460465
subject_locale,
461466
redirect_bare_en_us,
467+
well_known_security,
462468
],
463469
)
464470
.register(

static/text/well_known_security.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Contact: https://www.rust-lang.org/policies/security
2+
Expires: 2024-05-15T00:00:00.000Z

tests/well_known_security.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
2+
3+
#[test]
4+
fn well_known_security_is_not_expired() {
5+
let text = include_str!("../static/text/well_known_security.txt");
6+
let expires = text.split("Expires:").nth(1).unwrap().trim();
7+
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
8+
let now = OffsetDateTime::now_utc();
9+
assert!(
10+
now < expires,
11+
"
12+
┌────────────────────────────────────────────────────────────────┐
13+
│ │
14+
│ I looks like the expiration date of the security policy has │
15+
│ passed. Before blindly updating it, please make sure the │
16+
│ pointed-to URL still refers to the source of truth of the │
17+
│ security policy of the Rust project. If all is well, you can │
18+
│ update the expiration date in the relevant file: │
19+
│ │
20+
│ static/text/well_known_security.txt │
21+
│ │
22+
└────────────────────────────────────────────────────────────────┘
23+
"
24+
);
25+
}

0 commit comments

Comments
 (0)