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

Local rustdocs generate cross-origin errors trying to load fonts in Firefox #34681

Closed
luser opened this issue Jul 6, 2016 · 10 comments
Closed
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@luser
Copy link
Contributor

luser commented Jul 6, 2016

Loading the locally installed copy of the standard library docs in Firefox I see errors in the console about loading fonts:

downloadable font: download failed (font-family: "Source Serif Pro" style:normal weight:normal stretch:normal src index:1): bad URI or cross-site access not allowed source: file:///C:/Users/Ted%20Mielczarek/.multirust/toolchains/stable-x86_64-pc-windows-msvc/share/doc/rust/html/SourceSerifPro-Regular.woff

This is because Firefox implements a strict same-origin policy for file: URLs: https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs

...and web fonts follow the same-origin policy, so a html page loaded from a file: URL can't load a web font from a parent directory.

/cc @Ms2ger

@Aatch Aatch added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jul 7, 2016
@GuillaumeGomez
Copy link
Member

Please take a look at #34702 to see if it solved your issue.

@ollie27
Copy link
Member

ollie27 commented Jul 10, 2016

This might be a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=760436.

@GuillaumeGomez
Copy link
Member

It's because of firefox. But not sure if this is a bug.

@Ms2ger
Copy link
Contributor

Ms2ger commented Jul 11, 2016

Note that that bug is marked as invalid.

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
@QuietMisdreavus
Copy link
Member

Triage: still a problem. Reading the discussion in the bugzilla link that @ollie27 linked, it may be deliberate:

I believe this is working as designed. AIUI, the issue here is that for a page loaded from a file:// URI, only files in (or below) the same directory of the filesystem are considered to be "same origin", and so putting the font in a different subtree (../font/) means it will be blocked by security policy restrictions.

You can relax this by setting security.fileuri.strict_origin_policy to false in about:config, but as this gives the page access to your entire local filesystem, it's something to be used with caution.

If that's the case, i'm not totally sure this is a problem we can fix without asking Firefox to adopt a looser same-origin policy for file:// URLs.

@jonhoo
Copy link
Contributor

jonhoo commented Nov 7, 2018

Looking back, this might be part of the reason I wanted #54772. I was opening docs locally in Firefox, and kept seeing the awful fonts that the browser falls back to when it fails to load the rustdoc fonts. I think the situation would be significantly improved (though not entirely fixed) by making the font stacks be only the loaded font + the font style. So, for example, today we have

body {
    font: 16px/1.4 "Source Serif Pro",Georgia,Times,"Times New Roman",serif;
}

The page looks significantly better with just

body {
    font: 16px/1.4 "Source Serif Pro",serif;
}

I don't know why those other intermediate font overrides are even there?

jonhoo added a commit to jonhoo/rust that referenced this issue Nov 7, 2018
This is a (much) more constrained version of rust-lang#54772 that also aims at
improving the situation in rust-lang#34681. It removes any font specifications
that are not the "official" rustdoc font, and instead relies on the
browser to provide the fallback font if the official on is not
available. On Linux systems, this is particularly important, as fonts
like Helvetica, Arial, and Times often look pretty bad since they're
pulled from extracted MS fonts. A specification like `serif` or
`sans-serif` lets the browser instead choose a good font.
@jonhoo
Copy link
Contributor

jonhoo commented Nov 7, 2018

From #docs on Discord:

@killercup: another fix for the font issue is to inline the font in the css (by using a data url, i.e. encode it as base64). not sure why that's not suggested in the issue

kennytm added a commit to kennytm/rust that referenced this issue Nov 8, 2018
…llaumeGomez

Remove intermediate font specs

This is a (much) more constrained version of rust-lang#54772 that also aims at improving the situation in rust-lang#34681. It removes any font specifications that are not the "official" rustdoc font, and instead relies on the browser to provide the fallback font if the official on is not available. On Linux systems, this is particularly important, as fonts like Helvetica, Arial, and Times often look pretty bad since they're pulled from extracted MS fonts. A specification like `serif` or `sans-serif` lets the browser instead choose a good font.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Nov 9, 2018
…llaumeGomez

Remove intermediate font specs

This is a (much) more constrained version of rust-lang#54772 that also aims at improving the situation in rust-lang#34681. It removes any font specifications that are not the "official" rustdoc font, and instead relies on the browser to provide the fallback font if the official on is not available. On Linux systems, this is particularly important, as fonts like Helvetica, Arial, and Times often look pretty bad since they're pulled from extracted MS fonts. A specification like `serif` or `sans-serif` lets the browser instead choose a good font.
@medwards
Copy link
Contributor

medwards commented Mar 25, 2019

For myself this issue is caused by the fact that I go directly to the API search page (file:///home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc/rust/html/std/index.html?search=).

In this case the fonts are actually one folder above my current folder which violates the rule outlined by jfkthame in the mozilla bug:

By default, only files in or under the same directory are considered same-origin for "file:" URLs, so your "../i/Pecita.otf" is not allowed to load.

To verify this I copied the fonts into the std folder and prepended std/ to the font urls in rustdoc.css. This fixed it for me.

Edit: Verified that this affects rustup doc --std on my machine and that my workaround also applies.

@luser
Copy link
Contributor Author

luser commented Sep 17, 2019

This seems to work fine now in Firefox 69. For reference it looks like this behavior was changed in Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1565942, which landed in Firefox 69 and was backported to 68.0.2.

@GuillaumeGomez
Copy link
Member

Awesome! I guess we can close it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants