Skip to content

Implement whitelist for sanitizer: allowed_html_elements_with_attributes() - #53

Merged
Alkarex merged 12 commits into
FreshRSS:freshrssfrom
Inverle:sanitize-whitelist
Oct 29, 2025
Merged

Alkarex merged 12 commits into
FreshRSS:freshrssfrom
Inverle:sanitize-whitelist

Conversation

@Inverle

@Inverle Inverle commented Sep 14, 2025

Copy link
Copy Markdown
Member

@Inverle

Inverle commented Sep 14, 2025

Copy link
Copy Markdown
Member Author

Maybe now

@Alkarex

Alkarex commented Sep 14, 2025

Copy link
Copy Markdown
Member

Thanks 👍🏻
If you ca, it would be nice to:

  1. Add a minimal test (there are examples in the test directory)
  2. Open the same PR at https://github.com/simplepie/simplepie

@Inverle

Inverle commented Sep 25, 2025 •

Copy link
Copy Markdown
Member Author

done (test added, PR not opened yet)

@Inverle

Inverle commented Sep 27, 2025

Copy link
Copy Markdown
Member Author

Attempting to fix CI, have to wait for approval so no idea if this works

@Inverle

Inverle commented Sep 28, 2025

Copy link
Copy Markdown
Member Author

simplepie#947

@Inverle

Inverle commented Oct 20, 2025

Copy link
Copy Markdown
Member Author

What should be done now?

@Alkarex

Alkarex commented Oct 21, 2025

Copy link
Copy Markdown
Member

Sorry for the delay. I rewrote the approach to iterate the elements and attributes. I was not so happy of the two layers of XPath.

  1. Please double-check my changes 638515c (not tested)
  2. If that is good enough, please update upstream PR accordingly
  3. We will merge here

@Inverle

Inverle commented Oct 25, 2025

Copy link
Copy Markdown
Member Author

Please double-check my changes 638515c (not tested)

WIP

Comment thread tests/SanitizeTest.php Resolved
* Fixed sanitization output returning `<!DOCTYPE html>` regardless of input
* Custom elements are not allowed anymore
* Added `allow_data_attr` and `allow_aria_attr` parameters
* Don't remove children of the disallowed element
* Replaced `removeAttribute()` with `removeAttributeNS()` to ensure all disallowed attributes are removed
    * For example `xmlns` was not being removed correctly
* Fixed test using incorrect variable `$sanitize` instead of `$sanitize_whitelist`
@Inverle Inverle changed the title Implement whitelist for sanitizer: whitelist_tags() Implement whitelist for sanitizer: allowed_html_elements_with_attributes() Oct 25, 2025
@Inverle

Inverle commented Oct 25, 2025 •

Copy link
Copy Markdown
Member Author

If that is good enough, please update upstream PR accordingly

@Alkarex Please review the new changes before I do that (and run the tests workflow)

I have also updated FreshRSS/FreshRSS#7924 for FreshRSS testing. Seems to work fine with my feeds

Comment thread src/Sanitize.php Resolved
Comment thread src/Sanitize.php Resolved
Comment thread src/Sanitize.php Resolved
Comment thread src/Sanitize.php Resolved
Comment thread src/Sanitize.php Resolved
@Inverle

Inverle commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Ready for review

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
@Inverle

Inverle commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Though I don't understand why removeAttributeNode() and removeAttribute() behave differently

@Inverle

Inverle commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Looks like CI didn't print all the unsupported functions at once..

@Alkarex

Alkarex commented Oct 29, 2025

Copy link
Copy Markdown
Member

Looks like CI didn't print all the unsupported functions at once..

Yes, that would have been likely caught by simplepie#939

@Inverle

Inverle commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Everything still works

@Alkarex

Alkarex commented Oct 29, 2025

Copy link
Copy Markdown
Member

Please double-check 4a16e57 and I think we are good to go

@Inverle

Inverle commented Oct 29, 2025

Copy link
Copy Markdown
Member Author

Looks fine

@Alkarex
Alkarex merged commit 0d953d4 into FreshRSS:freshrss Oct 29, 2025
@Inverle
Inverle deleted the sanitize-whitelist branch October 29, 2025 22:34
Alkarex added a commit to Inverle/FreshRSS that referenced this pull request Oct 29, 2025
Alkarex added a commit to FreshRSS/FreshRSS that referenced this pull request Nov 1, 2025
* Implement whitelist for SimplePie sanitizer

ref: #7770 (comment)

FreshRSS/simplepie#53
simplepie/simplepie#947

* Remove `<plaintext>` from whitelist

* Improve order

* Remove some tags from whitelist

* Revert partially

* sync

* Display contents of `<noscript>` and `<noembed>`

* sync

* Allow use of `<track>`

* sync again

* Sync to SimplePie fork
FreshRSS/simplepie#53

* Alphabetic order

* Reduce list of stripped attributes

* Temporarily strip some attributes

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
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.

2 participants