-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Bootstrap v4 breaks Content-Security-Policy compared to Bootstrap v3 #25394
Comments
Hmm, interesting—hadn't considered this at all with the embedded SVGs. I suppose the easiest path forward for this is documenting a way to swag our navbar toggler for a custom one. |
Also, inline SVG put aside document parsing (more CSS to parse === more time document wait for it to be loaded) I think it's better to inline them on project bundling via Grunt or Webpack (if you really want less http requests but bigger CSS bundle) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We'll try to tackle this as part of v5 when we get to that and can make breaking changes to our components to move the background images from base64 to in-HTML elements. |
@mdo Bootstrap v5 seems like it could be a long way off. You mentioned earlier in the thread that a good workaround might be to replace the navbar toggler icon with a custom one. I tried doing this but the alignment was all messed up on small screens, could you share the documentation you had in mind, so those of us trying to implement CSP can get something functional and secure setup? |
Could it be fixed with |
Note that we don't use one SVG, so this isn't only about the navbar toggler icon. Your best bet is to relax CSP allowing |
It's probably where most people building sites using bootstrap will run into this though since there are a lot of sites using navbars that are accessed from mobile devices.
"Make your site insecure for an undetermined amount of time" - I can understand that doing a whole release for this issue is too big a task, but Bootstrap 5 could be several years away, and asking people to make their sites insecure is quite a big ask. I was hoping for a workaround in the interim, @mdo's suggestion sounded ideal. I don't agree that making my site insecure is a good idea. |
Unfortunately, that's how it is. We can't introduce potentially breaking changes right now. v5 is the next major version and work has already started in the |
@XhmikosR in your opinion is the custom navbar toggler icon workaround
possible?
…On Tue, 4 Dec 2018 at 13:37, XhmikosR ***@***.***> wrote:
Unfortunately, that's how it is. We can't introduce potentially breaking
changes right now.
v5 is the next major version and work has already started in the
v4-without-jquery branch.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#25394 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB07z-lb3MHn_p_iEzynhmUE0_h-AInNks5u1hgcgaJpZM4RmDER>
.
|
Yeah, but like I said there are a lot more cases we use CSS-inlined SVGs, so I'm not sure if changing the toggler icon alone will be enough. I usually use purgecss in my build process so it's enough for me. |
It will at least be enough for fixing the navbar toggler csp issue. Using the octicon hamburger icon... When I swap out
for
The toggler renders fine in the browser and without a CSP error, although it looks a little different (slightly smaller), but the main problem is that when viewed in Chrome devtools device tool, it's set in from the right side for most phone sized devices. How do I get it to render correctly on all screens? |
@mdo "We'll try to tackle this as part of v5". |
For people building Bootstrap from the source (rather than including the compiled CSS and minified JS) you could use https://www.npmjs.com/package/patch-package to edit (then subsequently patch on each install) the Bootstrap source to remove the data URIs and include the SVGs in an alternative way that will satisfy your CSP requirements. |
Thanks for this info! I will look into it :-) |
The rendering issue looks like it might be a Chrome devtools bug, I have checked using a responsive design testing browser extension and all device sizes render correctly. I was also able to extract the bootstrap svg and use it instead of the octicon svg. Here are the steps I took to get the toggler rendering without the CSP error:
|
This comment has been minimized.
This comment has been minimized.
I have not found any reason that it is actually a problem to include |
We have open issues and PR about using inlined SVG (in the markup) instead of embedded in CSS. v5 is in it's first alpha, there'll be more breaking changes until a first stable release so please wait — or contribute. But this issue is definetely in our v5 roadmap. |
@ffoodd Thanks for clarification. |
Inline SVG would do it, i don't know why they don't implement this already ? if they have a hamburger or other svg inlines they should reallly create some files that can be replaced by other icons also. |
@ffoodd I would be happy to contribute. Can you link the PR you mentioned? I could not find it. |
There's no dedicated PR AFAIK, but multiple discussions on related issues and PR. You may start a dedicated PR if you want, just take some time to search and read comments here and there about inline SVGs. |
After going back and forth with the team on this, we're most likely sticking with the embedded SVGs in v4 and in v5. We can't use SVGs in the HTML for things like our checkboxes, radios, and selects, so we'd have two different implementations for how we handle SVGs across the project (embedded CSS and inline HTML). It'd also be a larger departure from v4 than I'm willing to make just yet. v6 could be where we really overhaul some of this stuff though and make some different leaps. Providing documentation on how to replace the images is definitely doable though. I'll stub out a PR shortly for that, along with guidance on what SVGs are included (most are from Bootstrap Icons, so they're easy to replace with external images). Beyond that, anything else I'm missing? |
Maybe I'm misunderstanding. Wasn't the problem that enforcing a reasonable CSP policy of Also, ensuring that anything that needs to hide/show something doesn't use inline styles, and instead sets a CSS class. |
I had this same problem with Boostrap Carousel colliding with Content Security Policy. I know it's not an answer to the problem, but I was able to do a workaround with the following simple steps.
`.carousel-control-prev-icon { .carousel-control-next-icon { .carousel-control-prev-icon, } Notice that with this technique for a workaround, the color of the icons needs to be predetermined. The "fill" attribute of an SVG element won't be available. The cold reality is that, when choosing between XSS protection and keeping SVGs for Bootstrap, it was time to throw the SVG problem overboard and secure the application. We simply can't have a design stylesheet breaking a security control that helps shut down an OWASP Top 10 problem. We hope that the Bootstrap team will be able to find a solution that works with CSP. Thanks. |
Finally opened #32759 to suggest some copy around this. Please review and let me know what you think! |
For anybody who wants to see the results of that documentation PR here is the online version: https://getbootstrap.com/docs/5.0/customize/overview/#csps-and-embedded-svgs What I am confused with this documentation PR is that there is no reference to URLs that you can plug into your CSP configurations or where in the CSP configurations to put them. You are just linking to the code documentation page for each element? I was hoping bootstrap could provide something like this: https://content-security-policy.com/examples/ https://stripe.com/docs/security/guide#content-security-policy Using URLs and plugging them in is much easier than locally hosted assets, inline images, etc. I wouldn't know where to begin on where to actually download the images/svgs from and then figure out where to put them locally and then how to reference them in my code. There is no guidance for that. |
@9mido Would you mind opening a new issue, please? Your suggestion makes sense and we can improve our docs, for sure. |
This is required by custom components (e.g. the "Tags" partial that renders tags with various font sizes and weights) as well as Bootstrap itself: twbs/bootstrap#25394
This is required by custom components (e.g. the "Tags" partial that renders tags with various font sizes and weights) as well as Bootstrap itself: twbs/bootstrap#25394
This is required by custom components (e.g. the "Tags" partial that renders tags with various font sizes and weights) as well as Bootstrap itself: twbs/bootstrap#25394
An easy but slightly inconvenient fix for this would be to download the required SVG from the bootstrap icons website Then change your navbar HTML to point to the local SVG instead. My example is to get the navbar toggle icon to display correctly on smaller-screen devices (mobiles and tablets) I am saving the SVG to a folder named img Change this: To this: |
As it seems, Bootstrap v4 is now using "data:image/svg+xml" background-urls which leads to errors when using a Content-Security-Policy like
default-src 'self'; form-action 'self'; frame-ancestors 'self'; require-sri-for script style
. In order to be able to migrate from Bootstrap v3 to Bootstrap v4 one would have to weaken the Content-Security-Policy protection.IMHO that's a regression.
The text was updated successfully, but these errors were encountered: