Skip to content

Commit d84e6e5

Browse files
authored
Merge pull request #1996 from pietroalbini/csp
Add Content Security Policy to the website
2 parents 9c264a1 + c984367 commit d84e6e5

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

www/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<body id="idx">
1515

16-
<a id="platform-button" style="display: none;" href="#">
16+
<a id="platform-button" class="display-none" href="#">
1717
click or press "n" to cycle platforms
1818
</a>
1919

@@ -23,13 +23,13 @@
2323
<a href="https://www.rust-lang.org">Rust</a>
2424
</p>
2525

26-
<div id="platform-instructions-unix" class="instructions" style="display: none;">
26+
<div id="platform-instructions-unix" class="instructions display-none">
2727
<p>Run the following in your terminal, then follow the onscreen instructions.</p>
2828
<pre>curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh</pre>
2929
<p class="other-platforms-help">You appear to be running Unix. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
3030
</div>
3131

32-
<div id="platform-instructions-win32" class="instructions" style="display: none;">
32+
<div id="platform-instructions-win32" class="instructions display-none">
3333
<p>
3434
To install Rust, download and run
3535
<a class="windows-download" href="https://win.rustup.rs/i686">rustup&#x2011;init.exe</a>
@@ -40,7 +40,7 @@
4040
<p class="other-platforms-help">You appear to be running Windows 32-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
4141
</div>
4242

43-
<div id="platform-instructions-win64" class="instructions" style="display: none;">
43+
<div id="platform-instructions-win64" class="instructions display-none">
4444
<p>
4545
To install Rust, download and run
4646
<a class="windows-download" href="https://win.rustup.rs/x86_64">rustup&#x2011;init.exe</a>
@@ -51,7 +51,7 @@
5151
<p class="other-platforms-help">You appear to be running Windows 64-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
5252
</div>
5353

54-
<div id="platform-instructions-unknown" class="instructions" style="display: none;">
54+
<div id="platform-instructions-unknown" class="instructions display-none">
5555
<!-- unrecognized platform: ask for help -->
5656
<p>I don't recognize your platform.</p>
5757
<p>

www/rustup.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,15 @@ hr {
158158
margin-right: auto;
159159
padding: 1em;
160160
}
161+
162+
.display-none {
163+
display: none;
164+
}
165+
166+
.display-block {
167+
display: block;
168+
}
169+
170+
.display-inline {
171+
display: inline;
172+
}

www/rustup.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,27 @@ function detect_platform() {
5353
return os;
5454
}
5555

56+
function vis(elem, value) {
57+
var possible = ["block", "inline", "none"];
58+
for (var i = 0; i < possible.length; i++) {
59+
if (possible[i] === value) {
60+
elem.classList.add("display-" + possible[i]);
61+
} else {
62+
elem.classList.remove("display-" + possible[i]);
63+
}
64+
}
65+
}
66+
5667
function adjust_for_platform() {
5768
"use strict";
5869

5970
var platform = detect_platform();
6071

6172
platforms.forEach(function (platform_elem) {
6273
var platform_div = document.getElementById("platform-instructions-" + platform_elem);
63-
platform_div.style.display = "none";
74+
vis(platform_div, "none");
6475
if (platform == platform_elem) {
65-
platform_div.style.display = "block";
76+
vis(platform_div, "block");
6677
}
6778
});
6879

@@ -81,15 +92,15 @@ function adjust_platform_specific_instrs(platform) {
8192
}
8293
if (platform == "win64" || platform == "win32") {
8394
if (el_is_not_win) {
84-
el.style.display = "none";
95+
vis(el, "none");
8596
} else {
86-
el.style.display = el_visible_style;
97+
vis(el, el_visible_style);
8798
}
8899
} else {
89100
if (el_is_not_win) {
90-
el.style.display = el_visible_style;
101+
vis(el, el_visible_style);
91102
} else {
92-
el.style.display = "none";
103+
vis(el, "none");
93104
}
94105
}
95106
}
@@ -121,7 +132,7 @@ function set_up_cycle_button() {
121132
idx += 1;
122133

123134
if (idx == key.length) {
124-
cycle_button.style.display = "block";
135+
vis(cycle_button, "block");
125136
unlocked = true;
126137
cycle_platform();
127138
}

www/website_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"X-Content-Type-Options": "nosniff",
55
"X-Frame-Options": "DENY",
66
"X-XSS-Protection": "1; mode=block",
7-
"Referrer-Policy": "no-referrer, strict-origin-when-cross-origin"
7+
"Referrer-Policy": "no-referrer, strict-origin-when-cross-origin",
8+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' https://www.rust-lang.org; font-src 'self'"
89
}
910
}

0 commit comments

Comments
 (0)