Skip to content
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

bug: Bleach should escape unclosed less than sign and render it instead of treating it as unclosed html. #590

Closed
hoIIer opened this issue May 2, 2021 · 4 comments

Comments

@hoIIer
Copy link

hoIIer commented May 2, 2021

bleach.clean(text) thinks less than sign without a closing greater than sign is html and clears it from output.

"a < b" -> "a &lt; b"
"a<b" -> "a"

Bleach should escape unclosed less than sign and render as "a&lt;b" or offer an option to do so.

  • Python Version: [e.g. 3.8.2]
  • Bleach Version: [e.g. 3.2.1]
bleach.clean('a<b')
@hoIIer hoIIer changed the title bug: Bleach render unclosed less than sign as raw output instead of treating it as unclosed html. bug: Bleach should render unclosed less than sign as raw output instead of treating it as unclosed html. May 2, 2021
@hoIIer hoIIer changed the title bug: Bleach should render unclosed less than sign as raw output instead of treating it as unclosed html. bug: Bleach should escape unclosed less than sign and render it instead of treating it as unclosed html. May 3, 2021
@g-k
Copy link
Collaborator

g-k commented Jun 14, 2021

Huh, yeah "a<b" -> "a" is a bug or regression.

Bleach should escape unclosed less than sign and render as "a<b" or offer an option to do so.

Bleach should escape it to avoid dangling markup attacks https://portswigger.net/web-security/cross-site-scripting/dangling-markup

@soujanyat
Copy link

Have a similar use case where bleach escape greater than or less than sign for the value comparison.

example: 10 > 5
bleach.clean('10 > 5')
u'10 > 5'

Since it is a comparison Html escape shouldn't happen. How to handle such use cases in bleach.clean()

@Id3aFly
Copy link

Id3aFly commented Dec 9, 2021

I also have this problem, when my string contains e.g. "Related to all items <G1"
bleach.clean('related to all items <G1') = 'related to all items '
This affects all strings with an unclosed < followed by an alphabetic char.

However, this does not happen for

  • greater than symbols: bleach.clean('related to all items >G1') = 'related to all items &gt;G1'
  • digits: bleach.clean('related to all items <1') = 'related to all items &lt;1'
  • if there is a space: bleach.clean('related to all items < G1') = 'related to all items &lt; G1'

@willkg
Copy link
Member

willkg commented Jan 13, 2023

This was fixed in 5.0.1 and is a dupe of issue #544.

@willkg willkg closed this as completed Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants