-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
LibWeb/CSS: Block shadow host matching in DOM #2552
LibWeb/CSS: Block shadow host matching in DOM #2552
Conversation
@@ -867,6 +867,11 @@ static bool fast_matches_simple_selector(CSS::Selector::SimpleSelector const& si | |||
static bool fast_matches_compound_selector(CSS::Selector::CompoundSelector const& compound_selector, Optional<CSS::CSSStyleSheet const&> style_sheet_for_rule, DOM::Element const& element, GC::Ptr<DOM::Element const> shadow_host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit only touches the non-recursive fast_matches
code path. What about the recursive matches
path?
See can_use_fast_matches
for how we decide whether a selector is fast-matchable :)
Also, please add a test!
19a0df3
to
8cbbaac
Compare
8cbbaac
to
8cf83eb
Compare
8cf83eb
to
d6cb319
Compare
if (shadow_host && &element == shadow_host.ptr() && component.type != CSS::Selector::SimpleSelector::Type::PseudoClass && component.type != CSS::Selector::SimpleSelector::Type::PseudoElement) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to move this check into its own static function, to save having to remember to modify both places.
Also... I think this doesn't block enough. It'll allow other kinds of pseudo-class, such as :first-child
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated it to allow only host and compound pseudo classes
95be6cc
to
4cf8374
Compare
Fixes an issue where selectors inside a shadow root could incorrectly match their shadow host directly using selectors like #host, instead of requiring :host pseudo-class selectors. Fixes issue LadybirdBrowser#2319
Add a test that verifies selectors inside a shadow root can only match their host element through :host pseudo-class. Tests both simple selectors (#id, .class) and complex selectors (:not, :where) to ensure they are blocked from matching the host element directly. Fixes issue LadybirdBrowser#2319
4cf8374
to
a7a71ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, thanks for working on it! If there are any edge cases, we can fix them when we find them.
Fixes an issue where selectors inside a shadow root could incorrectly match their shadow host directly using selectors like #host, instead of requiring :host pseudo-class selectors.
Fixes issue #2319