Sanitizer: resolve img/source srcset URLs and add a src fallback#87
Open
polybjorn wants to merge 6 commits into
Open
Sanitizer: resolve img/source srcset URLs and add a src fallback#87polybjorn wants to merge 6 commits into
polybjorn wants to merge 6 commits into
Conversation
Resolve each srcset URL against the document base and drop disallowed schemes, since replace_urls() only handles single-URL attributes. On <img>, copy the smallest entry into src when src is empty or a placeholder.
polybjorn
added a commit
to polybjorn/FreshRSS
that referenced
this pull request
Jul 25, 2026
An empty src was resolved to the document base before the placeholder check ran, so src pointed at the article page instead of falling back to a srcset entry. Restore the original node-pass ordering and set the base ahead of it. Naming matches FreshRSS/simplepie#87 so the vendored file stays in sync.
polybjorn
marked this pull request as ready for review
July 25, 2026 19:58
Match the namespaced location used by the current Sanitize tests instead of the legacy root tests/ directory.
Documents why the allowed-node pass has to run before replace_urls().
4 tasks
Member
|
Please try to address the CI/CD failures if you can |
str_starts_with is PHP 8.0+, but composer.json declares >=7.2 and CI tests it. No existing test called allowed_html_elements_with_attributes(), so this path was never reached on the old matrix entries.
Arrow functions are 7.4+ and str_starts_with/str_ends_with are 8.0+, so Sanitize.php failed to parse on PHP 7.2 and 7.3. substr() returns string|false below 8.0, which broke the parse_srcset() return type under PHPStan on 7.4. assertDoesNotMatchRegularExpression is PHPUnit 9.1+ while composer.json still allows ^8.
srcset entries were absolutised and scheme-checked but never passed through https_url(), so on a forced-HTTPS domain src was upgraded and srcset was not, leaving the browser to pick an http candidate. The scheme check now also mirrors the disallowed_uri_schemes guard from replace_urls(); a blocked entry is still dropped rather than prefixed with unsafe:, since a candidate the browser must never pick has no reason to stay in the list. The test helper now calls set_url_replacements() so replace_urls() actually runs, which is how SimplePie configures the sanitizer.
Author
|
Done. Three causes:
Two things outside the CI fix:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FreshRSS drops
srcsetunless it is whitelisted, and even when allowed the URLs inside are never resolved, becausereplace_urls()only rewrites single-URL attributes. RelativesrcsetURLs leak, and lazy-loaded images (placeholder insrc, real images insrcset) show only the placeholder.This handles
srcsetin the allowed-node pass ofSanitize:srcsetURL on<img>and<source>is resolved against the document base, and entries with a disallowed scheme are removed.<img>, whensrcis empty or a placeholder (1x1 transparent GIF, or adata:URI under 128 chars), the smallest entry is copied intosrcas a fallback.srcsetrules, so unencoded commas in URLs (Cloudinary, WordPress) do not split entries.It only runs when a caller allows
srcsetthroughallowed_html_elements_with_attributes(), so default output is unchanged.Ports the
Sanitizechange from FreshRSS/FreshRSS#8843, which currently patches the vendored copy of this file directly. Once this lands and the library is re-vendored, that PR keeps only itsSimplePieCustom.phpallowlist change.Test plan
tests/Unit/SanitizeSrcsetTest.phpadds 23 tests covering URL resolution, placeholder detection, fallback selection, comma-in-URL parsing, scheme blocking, HTTPS forcing, and<picture><source>.composer test,composer phpstanandcomposer cspass, and the existingSanitizeTestis unchanged.