Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a .well-known/security.txt #2016

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ toml = "0.8"
serde_json = "1.0"
rust_team_data = { git = "https://github.com/rust-lang/team" }
percent-encoding = "2.1.0"

[dev-dependencies]
time = { version = "0.3.36", features = ["parsing"] }
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ fn redirect_bare_en_us() -> Redirect {
Redirect::permanent("/")
}

#[get("/.well-known/security.txt")]
fn well_known_security() -> &'static str {
include_str!("../static/text/well_known_security.txt")
}

#[catch(404)]
#[allow(clippy::result_large_err)]
fn not_found(req: &Request) -> Result<Template, Redirect> {
Expand Down Expand Up @@ -459,6 +464,7 @@ async fn rocket() -> _ {
team_locale,
subject_locale,
redirect_bare_en_us,
well_known_security,
],
)
.register(
Expand Down
2 changes: 2 additions & 0 deletions static/text/well_known_security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Contact: https://www.rust-lang.org/policies/security
Expires: 2025-05-15T00:00:00.000Z
37 changes: 37 additions & 0 deletions tests/well_known_security.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use time::{format_description::well_known::Rfc3339, OffsetDateTime};

static TEXT: &str = include_str!("../static/text/well_known_security.txt");

#[test]
fn well_known_security_is_not_about_to_expire() {
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
let one_month_from_now = OffsetDateTime::now_utc() + time::Duration::days(30);
assert!(
one_month_from_now < expires,
"
┌────────────────────────────────────────────────────────────────┐
│ │
│ I looks like the expiration date of the security policy needs │
│ updating. Before blindly updating it, please make sure the │
│ pointed-to URL still refers to the source of truth of the │
│ security policy of the Rust project. If all is well, you can │
│ update the expiration date in the relevant file: │
│ │
│ static/text/well_known_security.txt │
│ │
└────────────────────────────────────────────────────────────────┘
"
);
}

#[test]
fn well_known_security_expires_within_a_year() {
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
let one_year_from_now = OffsetDateTime::now_utc() + time::Duration::days(370);
assert!(
expires < one_year_from_now,
"The security policy should be checked once a year, please reduce the expiration date."
);
}
Loading