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

get_markdown incorrectly renders text that contains both hyperlinks and parentheses #1102

Open
mattbuff-nynhp opened this issue Jun 26, 2023 · 3 comments

Comments

@mattbuff-nynhp
Copy link

If the following sentence is entered into a ticket, it does not render correctly in the ticket.html template:

Here is some example text containing (parentheses) before a link also surrounded by parentheses (https://github.com/).

It renders as:

Here is some example text containing (//github.com/).

The missing text in bold:

Here is some example text containing (parentheses) before a link also surrounded by parentheses (https://github.com/).

I've narrowed down the bug to the regex and text replacement in get_markdown(). The text renders correctly when the replacement code (lines 58-67) is commented out.

def get_markdown(text):
if not text:
return ""
pattern = r'([\[\s\S\]]*?)\(([\s\S]*?):([\s\S]*?)\)'
# Regex check
if re.match(pattern, text):
# get get value of group regex
scheme = re.search(pattern, text, re.IGNORECASE).group(2)
# scheme check
if scheme in helpdesk_settings.ALLOWED_URL_SCHEMES:
replacement = '\\1(\\2:\\3)'
else:
replacement = '\\1(\\3)'
text = re.sub(pattern, replacement, text, flags=re.IGNORECASE)
return mark_safe(
markdown(
text,
extensions=[
EscapeHtml(), 'markdown.extensions.nl2br',
'markdown.extensions.fenced_code'
]
)
)

@uhurusurfa
Copy link
Collaborator

The regex and associated code was introduced by this PR:
#985

It looks like it was designed to prevent javascript injection.

@gwasser - can you provide insight?

@gwasser
Copy link
Member

gwasser commented Jun 28, 2023

Basically yes, preventing javascript injection as a security issue. The regex could probably be extended to handle parentheses correctly.

@uhurusurfa
Copy link
Collaborator

Ok - I will work on a fix with some unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants