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

False positive on unquoted-attribute-var for Angular #3205

Open
Sjord opened this issue Oct 31, 2023 · 1 comment
Open

False positive on unquoted-attribute-var for Angular #3205

Sjord opened this issue Oct 31, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Sjord
Copy link
Contributor

Sjord commented Oct 31, 2023

Describe the bug
semgrep-rules/generic/html-templates/security/unquoted-attribute-var.yaml at develop · returntocorp/semgrep-rules

This triggers for Angular templates with unquoted attributes, but Angular actually behaves correctly and replaces the attribute value, instead of doing string replace.

example.html:

<h2 class="title" title={{name}}>Hello {{name}}</h2>
$ semgrep -c 'r/generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var' example.html

    example.html
       generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var
          Detected a unquoted template variable as an attribute. If unquoted, a malicious actor could
          inject custom JavaScript handlers. To fix this, add quotes around the template expression,
          like this: "{{ expr }}".
          Details: https://sg.run/weNX

           ▶▶┆ Autofix ▶ s/{{(.*?)}}/"{{\1}}"/g
            1┆ <h2 class="title" title={{name}}>Hello {{name}}</h2>
@Sjord Sjord added the bug Something isn't working label Oct 31, 2023
@ziggythehamster
Copy link

This is also an issue in Ember.js, where you have templates that look like this:

<top.heading @hasFilters={{data.foo}}>
...
</top.heading>

Fixing this for Ember would be a matter of considering @attributename={{ ... }} acceptable, unless I'm forgetting some edge case. Fixing this for Angular seems like it might not be possible unless the project can be detected as Angular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants