trentm / trentm/python-markdown2

[shadow] safe_mode bypassed by links

Open
#51 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.8k
Forks
459
Avg merge
2d 19h
Merged PRs (30d)
4

Description

_This is a _shadow issue* for Issue 51 on Google Code (from which this project was moved).
Added 2011-01-19T00:10:59.000Z by he...@precheur.org.
Labels: Type-Defect, Priority-Medium.
Please make updates to the bug there.*

Original description

>>> from markdown2 import Markdown
>>> m = Markdown(safe_mode='replace')
>>> m.convert("[evil][evil]\n[evil]: javascript:alert('evil');")
u'<p><a href=&quot;javascript:alert(\'evil\');&quot;>evil</a></p>\n'
>>> m.convert('![img](javascript:void\(0\);)')
u'<p><img src=&quot;javascript:void(0);&quot; alt=&quot;img&quot; /></p>\n'

As you can see, it's possible to execute javascript code via the the src & href attributes and maybe others. It would be good to have something like `is_safe_link` in Markdown's contructor:

  def is_safe_link(value):
    return value.startswith('http://') or value.startswith('#')

<b>What version of the product are you using? On what operating system?</b>

1.0.1.17

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the original Google Code issue linked in the shadow report and reproduce the two Markdown.convert examples using Markdown(safe_mode='replace'). Review the safe_mode handling and the proposed is_safe_link entry point; done means javascript URLs in link and image attributes are no longer accepted or emitted when safe mode is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.