Skip to content

Commit f49b8db

Browse files
committed
Add a .well-known/security.txt
1 parent d249f5d commit f49b8db

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
@@ -23,3 +23,6 @@ rust_team_data = { git = "https://github.com/rust-lang/team" }
2323
handlebars = "5.1.0"
2424
siphasher = "1.0.1"
2525
percent-encoding = "2.1.0"
26+
27+
[dev-dependencies]
28+
time = { version = "0.3.36", features = ["parsing"] }

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ fn redirect_bare_en_us() -> Redirect {
249249
Redirect::permanent("/")
250250
}
251251

252+
#[get("/.well-known/security.txt")]
253+
fn well_known_security() -> &'static str {
254+
include_str!("../static/text/well_known_security.txt")
255+
}
256+
252257
#[catch(404)]
253258
#[allow(clippy::result_large_err)]
254259
fn not_found(req: &Request) -> Result<Template, Redirect> {
@@ -475,6 +480,7 @@ async fn rocket() -> _ {
475480
team_locale,
476481
subject_locale,
477482
redirect_bare_en_us,
483+
well_known_security,
478484
],
479485
)
480486
.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)