You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[newsfeed] add allowBasicHtmlTags option for basic emphasis (MagicMirrorOrg#4176)
**Please make sure that you have followed these 3 rules before
submitting your Pull Request:**
> 1. Base your pull requests against the `develop` branch.
Done.
> 2. Include these infos in the description:
>
> - Does the pull request solve a **related** issue?
No
> - If so, can you reference the issue like this `Fixes
#<issue_number>`?
> - What does the pull request accomplish? Use a list if needed.
> - If it includes major visual changes please add screenshots.
>
Render a strict allowlist of basic formatting tags (b, strong, i, em, u)
in news titles and descriptions, while neutralizing all other HTML.
Feeds such as The Atlantic encode emphasis as entities (<em>),
which html-to-text decoded to a literal <em> string that the template
then auto-escaped, so the raw tag was shown on screen. The new opt-in
allowBasicHtmlTags option (default false) sanitizes both fields by
escaping everything and restoring only the exact, attribute-free
allowlisted tags, so the result is safe to render and arbitrary
HTML/script injection is impossible.
Adds unit tests for the sanitizer and an e2e test covering rendering and
an injection attempt.
Before screenshot: <img width="980" height="2726" alt="before"
src="https://github.com/user-attachments/assets/d1c871e1-21c5-44f9-ae40-da65c2c56f68"
/>
After screenshot: <img width="980" height="2726" alt="after"
src="https://github.com/user-attachments/assets/22d9e86b-221c-408e-a29b-718b0e98f236"
/>
> 3. Please run `node --run lint:prettier` before submitting so that
> style issues are fixed.
Done
**Note**: Sometimes the development moves very fast. It is highly
recommended that you update your branch of `develop` before creating a
pull request to send us your changes. This makes everyone's lives
easier (including yours) and helps us out on the development team.
Thanks again and have a nice day!
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
<divclass="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{escapeTitle(item.title, item.url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}</div>
48
+
<divclass="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{escapeTitle(item.title, item.url, config.dangerouslyDisableAutoEscapingor (config.allowedBasicHtmlTags | length), config.showTitleAsUrl) }}</div>
49
49
{%ifconfig.showDescription%}
50
50
<divclass="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
<divclass="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{escapeTitle(title, url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}</div>
71
+
<divclass="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{escapeTitle(title, url, config.dangerouslyDisableAutoEscapingor (config.allowedBasicHtmlTags | length), config.showTitleAsUrl) }}</div>
72
72
{%ifconfig.showDescription%}
73
73
<divclass="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
* NewsfeedFetcher - Fetches and parses RSS/Atom feed data
11
31
* Uses HTTPFetcher for HTTP handling with intelligent error handling
@@ -20,12 +40,22 @@ class NewsfeedFetcher {
20
40
* @param {string} encoding - Encoding of the feed (e.g., 'UTF-8')
21
41
* @param {boolean} logFeedWarnings - If true log warnings when there is an error parsing a news article
22
42
* @param {boolean} useCorsProxy - If true cors proxy is used for article url's
43
+
* @param {string[]} allowedBasicHtmlTags - Basic formatting tags to keep in title and description. Only tags from the safe list are honored; anything else is ignored.
0 commit comments