Skip to content

helpers: apply id and lang attr regexps to full string#198

Open
matloob wants to merge 1 commit into
microcosm-cc:mainfrom
matloob:main
Open

helpers: apply id and lang attr regexps to full string#198
matloob wants to merge 1 commit into
microcosm-cc:mainfrom
matloob:main

Conversation

@matloob
Copy link
Copy Markdown

@matloob matloob commented Nov 21, 2023

The intent of the code seemed to be to allow ids and langs where the full string matches the regular expression, not just part of it.

The intent of the code seemed to be to allow ids and langs where the
full string matches the regular expression, not just part of it.
Comment thread helpers.go
p.AllowAttrs(
"lang",
).Matching(regexp.MustCompile(`[a-zA-Z]{2,20}`)).Globally()
).Matching(regexp.MustCompile(`^[a-zA-Z]{2,20}$`)).Globally()
Copy link
Copy Markdown

@diasbruno diasbruno Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ˆ and $ can be abused by attackers. Check if it's possible to use \A or \z.

Example: \A[a-zA-Z]{2,20}\z

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine? Unless the ?m flag is provided, ^ and $ match the beginning and end of the text, not the beginning and end of the line. (See https://pkg.go.dev/regexp/syntax)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. So just need to guarantee that the flag is enabled.

Copy link
Copy Markdown
Author

@matloob matloob Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi do you mean for us to add a test to ensure that the ?m flag is not used?

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

Successfully merging this pull request may close these issues.

2 participants