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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matloob
Copy link

@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.
@@ -148,15 +148,15 @@ func (p *Policy) AllowStandardAttributes() {
p.AllowAttrs("dir").Matching(Direction).Globally()
p.AllowAttrs(
"lang",
).Matching(regexp.MustCompile(`[a-zA-Z]{2,20}`)).Globally()
).Matching(regexp.MustCompile(`^[a-zA-Z]{2,20}$`)).Globally()
Copy link

@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
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)

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.

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