Skip to content

Commit

Permalink
Add a .well-known/security.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Jul 25, 2024
1 parent d249f5d commit f49b8db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
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 @@ -23,3 +23,6 @@ rust_team_data = { git = "https://github.com/rust-lang/team" }
handlebars = "5.1.0"
siphasher = "1.0.1"
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 @@ -249,6 +249,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 @@ -475,6 +480,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: 2024-05-15T00:00:00.000Z
25 changes: 25 additions & 0 deletions tests/well_known_security.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use time::{format_description::well_known::Rfc3339, OffsetDateTime};

#[test]
fn well_known_security_is_not_expired() {
let text = include_str!("../static/text/well_known_security.txt");
let expires = text.split("Expires:").nth(1).unwrap().trim();
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
let now = OffsetDateTime::now_utc();
assert!(
now < expires,
"
┌────────────────────────────────────────────────────────────────┐
│ │
│ I looks like the expiration date of the security policy has │
│ passed. 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 │
│ │
└────────────────────────────────────────────────────────────────┘
"
);
}

0 comments on commit f49b8db

Please sign in to comment.