Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upLimited the usage of custom css to a specific div #349
Conversation
This comment has been minimized.
This comment has been minimized.
Would applying the |
This comment has been minimized.
This comment has been minimized.
I haven't thought of that... I don't think it would be too magical. I'm using |
mikicz
force-pushed the
mikicz:page-css-restriction
branch
from
d910a97
to
63213cd
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
It was actually easier than I thought it would be. The extra requirement |
hroncok
reviewed
Mar 17, 2018
parsed = cssutils.parseString(css) | ||
|
||
for rule in parsed.cssRules: | ||
rule.selectorText = ".lesson-content " + rule.selectorText |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mikicz
force-pushed the
mikicz:page-css-restriction
branch
from
63213cd
to
32d23f5
Mar 17, 2018
mikicz
closed this
Mar 17, 2018
mikicz
deleted the
mikicz:page-css-restriction
branch
Mar 17, 2018
mikicz
restored the
mikicz:page-css-restriction
branch
Mar 17, 2018
mikicz
reopened this
Mar 17, 2018
This comment has been minimized.
This comment has been minimized.
Hm, GitHub could have asked me if I really want to delete the branch even though a PR with it is open. My bad, sorry for the confusing emails. @hroncok I added the docstring as you requested... |
encukou
reviewed
Mar 18, 2018
""" | ||
If the lesson defines extra css, the scope of the styles is limited to ``.lesson-content``, | ||
a div which contains the actual lesson content. That way the styles can't disrupt | ||
overall page appearance. |
This comment has been minimized.
This comment has been minimized.
encukou
Mar 18, 2018
Member
That way the styles can't disrupt overall page appearance.
That is wrong. You can't rely on this function with untrusted input.
For example, this CSS would break pages:
.dummy, * {
position: absolute;
}
This comment has been minimized.
This comment has been minimized.
Style note: please have the docstring say what the function does, e.g. The rest of the docstring can give details. |
mikicz
force-pushed the
mikicz:page-css-restriction
branch
from
32d23f5
to
336c27d
Mar 18, 2018
This comment has been minimized.
This comment has been minimized.
@encukou You're right of course. I changed it so each individual selector is altered, not just the first one. |
This comment has been minimized.
This comment has been minimized.
It's nice to plug that particular hole, but can you be sure other such exploits don't exist? What if, say, CSS (and cssutils) add a parent selector some time in the future? As it is, this PR makes it convenient to write correct CSS that doesn't break the rest of the page. But until proved otherwise, it's not secure against malicious input, and the dosctring shouldn't imply that. |
This comment has been minimized.
This comment has been minimized.
(To be extra clear: at this point it's perfectly OK that this is not secure against malicious input. Just change the docstring.) |
This comment has been minimized.
This comment has been minimized.
Fair, this PR is about the convenience, however, we will have to solve this problem at some point anyway since, if I understood correctly, securing against malicious input should be a part of the thesis implementation. If I should protect naucse against malicious CSS input, can we have the discussion here? If you think it's not important enough, says so, ignore the following text, I'll amend the docstring and that's going to be it.
I might be wrong, of course, and tell me if I am, but I went over all the available CSS selectors and I believe this code covers all of them in regards of the style modifying Firstly, most of the selectors are ruled out by the space after + div {
...
} but such style wouldn't pass validation and a A weird one I had to look up was But again, if you don't think securing against malicious CSS input is important, even in the thesis implementation, says so, I'll shut up and just change the docstring. |
This comment has been minimized.
This comment has been minimized.
OK, let's secure things! Talk to Miro regarding scope of the thesis. Your review of selectors looks comprehensive; I didn't check it yet though, and it looks like checking it will take some time. And I'm worried about bugs in cssutils. Or – more securely – do a whitelist. Allow only the minimum necessary. |
This comment has been minimized.
This comment has been minimized.
Or you could just change the docstring and figure this out in a follow-up PR. |
This comment has been minimized.
This comment has been minimized.
Well, I guess it mostly depends on what you guys want. If you're both fine with disabling the feature for "external" content, I'd honestly go for that right now since it makes a lot of stuff easier. It even obsoletes this PR, which is really only a preparation for securing naucse against malicious CSS... |
This comment has been minimized.
This comment has been minimized.
What does disabling mean here?
|
This comment has been minimized.
This comment has been minimized.
Yeah, I understood it like that. |
This comment has been minimized.
This comment has been minimized.
I would be fine with that as a known limitation of the initial implementation. |
This comment has been minimized.
This comment has been minimized.
On Wednesday we agreed not to disable this functionality in the forks and to use the code from this PR in the thesis implementation, so I added a comment to requirements why the library version is frozen and expanded a bit about the safety in the docstring of the method. |
This comment has been minimized.
This comment has been minimized.
@mikicz Please look at this: https://github.com/maxchehab/CSS-Keylogging The security of your approach relies on two assumptions:
The second is right out, and I don't trust the first – it's really just a matter of time before someone finds a creative loophole in either CSS itself or the library we're using. My mind is set now: before I allow CSS from untrusted users, there needs to be a strict whitelist. BUT, the contribution you're making with your thesis does not allow content from untrusted users – repo owners still need to add courses to the list, which implies some trust & accountability, and as long as naucse is limited to our community, I'm perfectly fine with just trusting the course authors. Freezing |
mikicz
force-pushed the
mikicz:page-css-restriction
branch
from
c986a4f
to
af6f33c
Mar 27, 2018
This comment has been minimized.
This comment has been minimized.
Thanks for the thorough review, you're absolutely right of course and I apologize for my arrogance in pushing this as a "safe" option. I amended the docstring and updated the requirements. |
This comment has been minimized.
This comment has been minimized.
Thanks. Sorry for killing the fun :( |
mikicz commentedMar 16, 2018
My thesis implementation includes limiting CSS from forks to only the content of the lesson itself, this is a preparation for that, so the diff is manageable.