Closed edmorley closed 5 years ago
If we remove those inline styles, we'll lose the ability to easily change the font that is used for rendering. I understand that this violates CSP, but we cannot remove it as we would cripple functionality used by thousands of users. MkDocs (Jinja respectively) only allows HTML files for partials, so there's currently no other way (to my knowledge) to set the font.
Hi! Thank you for the reply.
So i was looking at this a bit earlier, but forgot to comment. One way to solve this for the common case would be to only use inline CSS if people have overridden the chosen font (and set fonts via stylesheet otherwise). Users who want to customise the fonts and use CSP can then either:
font.{code,...}
feature and accept they'll have to use unsafe-inline
or add hashesfont: false
and manually include their own stylesheet...but at least people using default fonts won't have to have the complexity of either.
Thoughts?
There may need to be some other combinations we need to address. The default font should be Roboto if it isn't specified otherwise or font
is set to false
. Again, feel free to create a PR in which we can discuss concrete solutions how this can be implemented and I think we can make it into master
. However, some documentation needs to be added on how to achieve maximum security and what options may impact it.
Description
Hi!
Currently mkdocs-material includes inline styles in the generated HTML, which means the insecure
'unsafe-inline'
source has to be used for the style-src Content-Security-Policy (or else hashes manually generated, which is a pain).Expected behavior
No inline styles.
Actual behavior
Inline styles in the generated HTML:
Which comes from: https://github.com/squidfunk/mkdocs-material/blob/7f08e2849a4d51ca7457e64bd2b2ab806103d771/src/base.html#L136-L145
...which result in the following errors in the browser console if the more secure
style-src
policy is used:Steps to reproduce the bug
Content-Security-Policy: style-src 'self' https://fonts.googleapis.com;
(a reduced version of the actual policy that would be used on a production site)Package versions
Project configuration
System information