-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Secure Medium URL parsing to prevent SSRF vulnerability (CodeQL … #127
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 |
|---|---|---|
|
|
@@ -1425,7 +1425,29 @@ async function processArticle(article, sourceName, tags, category, feedLang) { | |
| }, | ||
| { | ||
| name: 'scribe.rip', | ||
| transform: (u) => u.includes('medium.com') ? u.replace('medium.com', 'scribe.rip') : null | ||
| transform: (u) => { | ||
| try { | ||
| const parsedUrl = new URL(u); | ||
| // Safely check if this is a medium.com URL by parsing the hostname | ||
| if (parsedUrl.hostname === 'medium.com' || parsedUrl.hostname.endsWith('.medium.com')) { | ||
| return u.replace(parsedUrl.hostname, 'scribe.rip'); | ||
| } | ||
| } catch (_) {} | ||
| return null; | ||
| } | ||
| }, | ||
| { | ||
| name: 'freedium', | ||
| transform: (u) => { | ||
| try { | ||
| const parsedUrl = new URL(u); | ||
| // Safely check if this is a medium.com URL | ||
| if (parsedUrl.hostname === 'medium.com' || parsedUrl.hostname.endsWith('.medium.com')) { | ||
| return u.replace(parsedUrl.hostname, 'freedium.app'); | ||
| } | ||
| } catch (_) {} | ||
| return null; | ||
| } | ||
|
Comment on lines
+1441
to
+1450
|
||
| }, | ||
| { | ||
| name: 'web.archive.org', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hostname validation should use the existing
hostnameMatches()helper function (defined at line 584) for consistency with the rest of the codebase. The helper is already used throughout the file (lines 597-608) for the same purpose of checking if a hostname matches a domain including its subdomains.The current implementation duplicates the logic of
hostnameMatches()inline. Instead, extract the hostname once and use the helper:This improves maintainability and ensures consistent security checks across the codebase.