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

Remove inline scripts from the rustdoc output #81133

Closed
pietroalbini opened this issue Jan 17, 2021 · 0 comments · Fixed by #81161
Closed

Remove inline scripts from the rustdoc output #81133

pietroalbini opened this issue Jan 17, 2021 · 0 comments · Fixed by #81161
Assignees
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@pietroalbini
Copy link
Member

Rustdoc currently emits two inline <script> tags into each HTML page it generates, making it hard to enforce content security policies on websites hosting documentation. The two tags in question are:

<script>window.sidebarCurrent = {name: "rustwide", ty: "mod", relpath: "../"};</script>
<script>window.rootPath = "../";window.currentCrate = "rustwide";</script>

Both of the tags just define variables used by the JavaScript code, and it should be possible to replace them with data- attributes loaded by main.js without other changes to the codebase:

<div id="rustdoc-vars" data-root-path="../" data-current-crate="rustwide" ...></div>
// Top of main.js
var rustdocVars = document.getElementById("rustdoc-vars");
window.rootPath = rustdocVars.attributes["data-root-path"];
window.currentCrate = rustdocVars.attributes["data-current-crate"];
@pietroalbini pietroalbini added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-rustdoc-ui Area: Rustdoc UI (generated HTML) labels Jan 17, 2021
@GuillaumeGomez GuillaumeGomez self-assigned this Jan 17, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Jan 18, 2021
…, r=Nemo157

Remove inline script tags

Fixes rust-lang#81133.

cc `@pietroalbini`

r? `@Nemo157`
@bors bors closed this as completed in 1f777f3 Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants