-
-
Notifications
You must be signed in to change notification settings - Fork 1
Potential fix for code scanning alert no. 12: Incomplete multi-character sanitization #11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,8 +75,30 @@ function smartTruncate(text, maxLength = 500) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return truncated.trim() + '...'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * HTML-escape a string so it is safe to insert into HTML contexts. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Converts &, <, and > to their corresponding entities. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns {string} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function htmlEscape(input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/&/g, '&') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/</g, '<') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(/>/g, '>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Sanitize and process articles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function sanitizeArticle(article, sourceName, tags, category) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const rawSummary = htmlEscape( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| article.contentSnippet?.replace(/<[^>]*>/g, '') || '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: htmlEscape(article.title?.replace(/<[^>]*>/g, '') || '').slice(0, 200) || 'Untitled', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | |
| * HTML-escape a string so it is safe to insert into HTML contexts. | |
| * Converts &, <, and > to their corresponding entities. | |
| * @param {string} input | |
| * @returns {string} | |
| */ | |
| function htmlEscape(input) { | |
| if (!input) { | |
| return ''; | |
| } | |
| return input | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>'); | |
| } | |
| // Sanitize and process articles | |
| function sanitizeArticle(article, sourceName, tags, category) { | |
| const rawSummary = htmlEscape( | |
| article.contentSnippet?.replace(/<[^>]*>/g, '') || '' | |
| ); | |
| return { | |
| title: htmlEscape(article.title?.replace(/<[^>]*>/g, '') || '').slice(0, 200) || 'Untitled', | |
| // Note: HTML escaping is intentionally handled at the presentation layer | |
| // (e.g., via textContent and DOMPurify). At the data layer we only strip | |
| // HTML tags (see sanitizeText) and keep the underlying text unescaped. | |
| // Sanitize and process articles | |
| function sanitizeArticle(article, sourceName, tags, category) { |
Uh oh!
There was an error while loading. Please reload this page.