Skip to content

Re-work configuration handling and sanitize-core.#296

Merged
mozfreddyb merged 21 commits intoWICG:mainfrom
otherdaniel:clean-sanitize-core-even-harder
Sep 17, 2025
Merged

Re-work configuration handling and sanitize-core.#296
mozfreddyb merged 21 commits intoWICG:mainfrom
otherdaniel:clean-sanitize-core-even-harder

Conversation

@otherdaniel
Copy link
Collaborator

@otherdaniel otherdaniel commented Jun 3, 2025

This PR is meant to capture our recent discussion. It surely needs more editing; but I think the general structure is there. I'd be particularly interested in quick feedback on whether this accurately captures the discussion consensus.


This re-writes config handling and sanitize-core based on 2025-05-28 and 2025-05-14 meeting discussion. This would replace #285.

Since we couldn't quite agree on whether redundent global attribute and per-element attribute definitions should be considered an error, I have tried to cover both. Where they differ, a statement "IF DISALLOW REDUNDANT PER-ELEMENT-ATTRIBUTES" contains the additional checks needed to disallow this.


Preview | Diff

@evilpie
Copy link
Collaborator

evilpie commented Jun 11, 2025

I think in set a configuration we should first handle attributes and removeAttributes and afterwards elements, it avoids having to go through all per-element attributes for every global attribute. While I think this shouldn't really be observable from a spec perspective, I think most implementation will want to produce error messages that might make this difference observable in practice.

@otherdaniel otherdaniel force-pushed the clean-sanitize-core-even-harder branch from 1fc4830 to 16add11 Compare June 13, 2025 16:32
@otherdaniel
Copy link
Collaborator Author

I have updated the "Configuration Invariants" chapter (but not the actual algorithms) to match our discussion from last Wednesday: https://pr-preview.s3.amazonaws.com/otherdaniel/purification/pull/296.html#invariants

I'd be happy for a rough review whether this matches what we discussed. If so, I'll update the algorithm parts next.

@evilpie
Copy link
Collaborator

evilpie commented Jun 16, 2025

Adding these tables to the spec is a good idea.

An attribute is allowed, if it’s in the local allow list, and not in the global remove list. No duplicate entries between global remove and local allow lists are allowed.

I would word this as

An attribute is only allowed if it’s in the local allow list. No duplicate entries between global remove and local allow lists are allowed.

to make it clearer that this is a strict list. I don't think we need "not in the global remove list" in the first sentences, as this is already enforced by the second.

local attributes: Custom data attributes are allowed. No custom data attributes may be listed in any allow-list, as that would mean a duplicate entry.

I misunderstood this the first time when reading. Maybe "All custom data attributes are allowed..." would help? Not sure.

@evilpie
Copy link
Collaborator

evilpie commented Jun 16, 2025

If a global removeAttributes remove list exists, then:

I am wondering if we should change this to just "must be absent".

A config like { removeAttributes: ["title"], dataAttributes: false } might give to wrong impression of removing data attributes?

@otherdaniel otherdaniel force-pushed the clean-sanitize-core-even-harder branch from 16add11 to c178053 Compare June 16, 2025 15:30
@otherdaniel
Copy link
Collaborator Author

If a global removeAttributes remove list exists, then:

I am wondering if we should change this to just "must be absent".

Done.

@otherdaniel
Copy link
Collaborator Author

Adding these tables to the spec is a good idea.

An attribute is allowed, if it’s in the local allow list, and not in the global remove list. No duplicate entries between global remove and local allow lists are allowed.

I would word this as

An attribute is only allowed if it’s in the local allow list. No duplicate entries between global remove and local allow lists are allowed.

to make it clearer that this is a strict list. I don't think we need "not in the global remove list" in the first sentences, as this is already enforced by the second.

Done. Also added a sentence that the global remove list might apply elsewhere.

local attributes: Custom data attributes are allowed. No custom data attributes may be listed in any allow-list, as that would mean a duplicate entry.

I misunderstood this the first time when reading. Maybe "All custom data attributes are allowed..." would help? Not sure.

Done.

@otherdaniel
Copy link
Collaborator Author

I think this latest version represents the current group thinking; and I hope I've incorporated all feedback.

This ends up being more complicated than what is proposed in #294, but largely because there's a few more edge cases this needs to handle. (E.g. neither attributes or removeAttributes present; or the global removeAttributes + local attributes case.)

@mozfreddyb mozfreddyb requested review from annevk and evilpie July 7, 2025 06:50
@otherdaniel
Copy link
Collaborator Author

Did another pass.

I think I've handled all the feedback, but admittedly I haven't been terribly good at marking things as resolved, which makes the comment list here a bit unwiedly. Anything I've overlooked?

@evilpie
Copy link
Collaborator

evilpie commented Aug 18, 2025

Did another pass.

I think I've handled all the feedback, but admittedly I haven't been terribly good at marking things as resolved, which makes the comment list here a bit unwiedly. Anything I've overlooked?

I don't think it can be helped, we have to go through the comments and resolve them.

@evilpie
Copy link
Collaborator

evilpie commented Aug 19, 2025

Sorry, I tried to comment on some of the older comments and Github totally didn't like that.

@evilpie
Copy link
Collaborator

evilpie commented Aug 19, 2025

With the current text in this PR we won't throw for duplicate names in a Sanitizer config, but I think we decided to throw for these cases.

new Sanitizer({ elements: ["br", "br"] });

@otherdaniel
Copy link
Collaborator Author

With the current text in this PR we won't throw for duplicate names in a Sanitizer config, but I think we decided to throw for these cases.

Yes, that's how I remember it too.

[=valid=] now checks for dupes (and thus the constructor will throw on them), while [=canonicalize=] will just copy all elements (without eliminating dupes).

@otherdaniel
Copy link
Collaborator Author

Sorry, I tried to comment on some of the older comments and Github totally didn't like that.

I think I found them: :-)

@otherdaniel
Copy link
Collaborator Author

otherdaniel commented Aug 20, 2025

Based on today's meeting, we think this PR is pretty much good to go. I made another pass through all outstanding comments to resolve them, and indeed found two more I had forgotten! Fixes those, too. :)

It'd likely be best to handle new issues (like #304 + #305) in new PRs.

@evilpie
Copy link
Collaborator

evilpie commented Aug 21, 2025

Great work. I read through everything again and it looks good to me. It's quite possible that I will find something when updating the implementation in Firefox, but that IMO shouldn't block this from landing. Like Daniel, I would prefer tracking problems as individual smaller issues.

Copy link
Collaborator

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By-and-large this looks okay to me, but there's many editorial bits to follow-up on.

@mozfreddyb mozfreddyb merged commit 283218f into WICG:main Sep 17, 2025
2 checks passed
github-actions bot added a commit that referenced this pull request Sep 17, 2025
SHA: 283218f
Reason: push, by mozfreddyb

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
lando-prod-mozilla bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Sep 24, 2025
@otherdaniel otherdaniel deleted the clean-sanitize-core-even-harder branch October 1, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants