Skip to content

Commit 1639895

Browse files
authored
Merge pull request #2016 from rust-lang/remo/ynxwqrvksvok
Add a `.well-known/security.txt`
2 parents 722d619 + eef2e6d commit 1639895

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-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: 2025-05-15T00:00:00.000Z

tests/well_known_security.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
2+
3+
static TEXT: &str = include_str!("../static/text/well_known_security.txt");
4+
5+
#[test]
6+
fn well_known_security_is_not_about_to_expire() {
7+
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
8+
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
9+
let one_month_from_now = OffsetDateTime::now_utc() + time::Duration::days(30);
10+
assert!(
11+
one_month_from_now < expires,
12+
"
13+
┌────────────────────────────────────────────────────────────────┐
14+
│ │
15+
│ I looks like the expiration date of the security policy needs │
16+
│ updating. Before blindly updating it, please make sure the │
17+
│ pointed-to URL still refers to the source of truth of the │
18+
│ security policy of the Rust project. If all is well, you can │
19+
│ update the expiration date in the relevant file: │
20+
│ │
21+
│ static/text/well_known_security.txt │
22+
│ │
23+
└────────────────────────────────────────────────────────────────┘
24+
"
25+
);
26+
}
27+
28+
#[test]
29+
fn well_known_security_expires_within_a_year() {
30+
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
31+
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
32+
let one_year_from_now = OffsetDateTime::now_utc() + time::Duration::days(370);
33+
assert!(
34+
expires < one_year_from_now,
35+
"The security policy should be checked once a year, please reduce the expiration date."
36+
);
37+
}

0 commit comments

Comments
 (0)