Details
The output shows that:
- The
javascript:URL is written directly into<a href>attributes - The
<script>tag from comic text appears unescaped in the HTML body
---
Impact
Who is affected?
- Users who use
dosage --output htmlordosage --output rssoptions - Anyone who opens the generated HTML/RSS files in a browser
Attack scenario
- Attacker creates or compromises a webcomic site
- Attacker injects JavaScript into image title/alt attributes:
<img src="comic.png" title="Funny!<script>alert(1)</script>">
- Victim runs:
dosage MaliciousComic --output html - The generated
Comics/html/comics-YYYYMMDD.htmlcontains the unescaped script - When victim opens the file, JavaScript executes
Potential consequences
- Cookie theft if files are served over HTTP
- Local file access via
file://protocol - Phishing attacks through DOM manipulation
---
Recommended Fix
Escape all user-controlled content before writing to HTML/RSS:
import html
# In RSSEventHandler.comicDownloaded() - events.py around line 116:
if comic.text:
description += '<br/>%s' % html.escape(comic.text)
description += '<br/><a href="%s">View Comic Online</a>' % html.escape(pageUrl)
# In HtmlEventHandler.comicDownloaded() - events.py around line 232:
self.html.write(u'<li><a href="%s">%s</a>\n' % (html.escape(pageUrl), html.escape(pageUrl)))
# events.py around line 238:
if text:
self.html.write(u'<br/>%s\n' % html.escape(text))
For URLs, validating that they use safe protocols (http://, https://) would also help prevent javascript: URLs.
---
Resources
- CWE-79: Cross-site Scripting (XSS)
- OWASP XSS Prevention Cheat Sheet
- Python html.escape() documentation
---