-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e7672b
commit 39b784f
Showing
1 changed file
with
36 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ impl<'a> Generator<'a> { | |
self.generate_rfcbot()?; | ||
self.generate_zulip_map()?; | ||
self.generate_people()?; | ||
self.generate_index_html()?; | ||
Ok(()) | ||
} | ||
|
||
|
@@ -423,20 +424,36 @@ impl<'a> Generator<'a> { | |
Ok(()) | ||
} | ||
|
||
fn generate_index_html(&self) -> Result<(), Error> { | ||
const CONTENT: &[u8] = b"\ | ||
<!DOCTYPE html>\n\ | ||
<meta charset=\"utf-8\">\n\ | ||
<p>See <a href=\"https://github.com/rust-lang/team\">rust-lang/team</a>.</p>\n\ | ||
"; | ||
|
||
// GitHub has a security issue where a domain can point to GitHub Pages without any | ||
// repository attached to it. In that case, anyone can attach their own (malicious) | ||
// repo to the domain, effectively taking over it. | ||
// | ||
// This is not a problem for us, because team-api.infra.rust-lang.org does have content | ||
// (generated by this module!). Unfortunately, when there is no repo attached to a domain | ||
// GitHub serves the same 404 page as if there is no index.html file. This leads to *many* | ||
// people running automated scanners and emailing [email protected] claiming they | ||
// found a severe vulnerability and asking for a bounty. | ||
// | ||
// So let's just generate an index.html and reduce the volume of bogus reports. | ||
|
||
info!("writing index.html..."); | ||
self.write("index.html", CONTENT) | ||
} | ||
|
||
fn add<T>(&self, path: &str, obj: &T) -> Result<(), Error> | ||
where | ||
T: serde::Serialize + serde::de::DeserializeOwned + PartialEq, | ||
{ | ||
info!("writing API object {}...", path); | ||
let dest = self.dest.join(path); | ||
if let Some(parent) = dest.parent() { | ||
if !parent.exists() { | ||
std::fs::create_dir_all(parent)?; | ||
} | ||
} | ||
|
||
let json = serde_json::to_string_pretty(obj)?; | ||
std::fs::write(&dest, json.as_bytes())?; | ||
self.write(path, json.as_bytes())?; | ||
|
||
let obj2: T = | ||
serde_json::from_str(&json).with_context(|| format!("failed to deserialize {path}"))?; | ||
|
@@ -447,4 +464,15 @@ impl<'a> Generator<'a> { | |
|
||
Ok(()) | ||
} | ||
|
||
fn write(&self, path: &str, bytes: &[u8]) -> Result<(), Error> { | ||
let dest = self.dest.join(path); | ||
if let Some(parent) = dest.parent() { | ||
if !parent.exists() { | ||
std::fs::create_dir_all(parent)?; | ||
} | ||
} | ||
std::fs::write(&dest, bytes)?; | ||
Ok(()) | ||
} | ||
} |