Skip to content

Put safeguards around attribute nodes #47

Closed
@mikesamuel

Description

@mikesamuel

There are two cases where moving a node from one parent to another might be problematic.

const div = document.createElement('div')
div.appendChild(document.createTextNode('alert(1)'));
const script = document.createElement('script')
while (div.firstChild) {
  script.appendChild(div.firstChild);
}

We need to be suspicious of append to <script> elements regardless, but there's also a problem with attributes.

const div = document.createElement('div');
const a = document.createElement('a');

div.setAttribute('href', 'javascript:alert(1)');
const attr = div.getAttributeNode('href');
div.removeAttributeNode(attr);

a.setAttributeNode(attr);

But what about when a node comes from one context to a similar context?

const a0 = document.createElement('a');
const a1 = document.createElement('a');

a0.setAttribute('href', policy.createURL('http://example.com'));
const attr = a0.getAttributeNode('href');
a0.removeAttributeNode(attr);

a1.setAttributeNode(attr);

Should we support this kind of transparent DOM restructuring?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions