mettags: limit the scope of url => metatag to http, https and / links.

- prevent of malicious injection of JS links and other unsafe types
This commit is contained in:
Marcin Kuzminski 2017-11-20 12:44:07 +01:00
parent a794d219f5
commit 6084d12664
2 changed files with 15 additions and 2 deletions

View file

@ -947,8 +947,8 @@ tags_paterns = OrderedDict((
('see', (re.compile(r'\[see\ \=\>\ *([a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\]'),
'<div class="metatag" tag="see">see: \\1 </div>')),
('url', (re.compile(r'\[url\ \=\&gt;\ \[([a-zA-Z0-9\ \.\-\_]+)\]\((.*?)\)\]'),
'<div class="metatag" tag="url"> <a href="\\2">\\1</a> </div>')),
('url', (re.compile(r'\[url\ \=\&gt;\ \[([a-zA-Z0-9\ \.\-\_]+)\]\((http://|https://|/)(.*?)\)\]'),
'<div class="metatag" tag="url"> <a href="\\2\\3">\\1</a> </div>')),
('license', (re.compile(r'\[license\ \=\&gt;\ *([a-zA-Z0-9\/\=\?\&amp;\ \:\/\.\-]*)\]'),
'<div class="metatag" tag="license"><a href="http:\/\/www.opensource.org/licenses/\\1">\\1</a></div>')),

View file

@ -237,6 +237,19 @@ def test_age_in_future(age_args, expected, kw, baseapp):
('url', '[url =&gt; [name](http://rc.com)]'),
]),
# entry
((
"[url =&gt; [linkNameJS](javascript:alert(document.domain))]\n"
"[url =&gt; [linkNameHTTP](http://rhodecode.com)]\n"
"[url =&gt; [linkNameHTTPS](https://rhodecode.com)]\n"
"[url =&gt; [linkNamePath](/repo_group)]\n"
),
[
('generic', '[linkNameJS]'),
('url', '[url =&gt; [linkNameHTTP](http://rhodecode.com)]'),
('url', '[url =&gt; [linkNameHTTPS](https://rhodecode.com)]'),
('url', '[url =&gt; [linkNamePath](/repo_group)]'),
]),
# entry
((
"hello pta[tag] gog [[]] [[] sda ero[or]d [me =&gt;>< sa]"
"[requires] [stale] [see<>=&gt;] [see =&gt; http://url.com]"