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

Allow for special attribute filtering. #13

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

Conversation

smfoote
Copy link
Owner

@smfoote smfoote commented Apr 29, 2015

Experimental: Allow attribute values to be filtered before being
attached to an element. This should prevent something like:

<a href="{customUrl}">Click me</a>

from being an XSS hole with a context like:

{
  customUrl: "javascript:alert('hacked')"
}

@smfoote smfoote force-pushed the safe-href branch 4 times, most recently from 72622cc to 0022cfd Compare May 6, 2015 20:45
@prashn64
Copy link
Collaborator

@jimmyhchan this could be interesting

@prashn64 prashn64 closed this May 21, 2015
@prashn64 prashn64 reopened this May 21, 2015
},

attrFilters: {
'a[href]': function(val) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we may have to repeat this key a bunch of times. a[href], img[src]. is there a way to gather a bunch of contexts to filter on.

Copy link
Owner Author

Choose a reason for hiding this comment

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

We could pretty easily define a single function and then assign it to multiple contexts:

function anchorsAndImages (val) {
  ...
}

attrFilters: {
  'a[href]': anchorsAndImages,
  'img[src]': anchorsAndImages
}

I was also thinking of having some more generic rules. For example, 'a' would match all attributes in an anchor tag, and '[src]' would match src attributes on any tag. That leads to a few questions:

  1. If multiple filters are found for a single attribute, are they all executed or just the most specific?
  2. If they are all executed, in what order are they executed? From most specific to least specific? Random?

Experimental: Allow attribute values to be filtered before being
attached to an element. This should prevent something like:

```
<a href="{customUrl}">Click me</a>
```
from being an XSS hole with a context like:

```
{
  customUrl: "javascript:alert('hacked')"
}
```
@smfoote
Copy link
Owner Author

smfoote commented Jun 10, 2015

So, even with the new compiler, I think we need to put something in the runtime, because we won't know until runtime if attributes with UGC need to be filtered.

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.

3 participants