Skip to content

Commit

Permalink
Properly inherit "document features" configuration into iframes
Browse files Browse the repository at this point in the history
The whole "document features" setup is legacy stuff from old API, but it is used to implement the important runScripts and resources options in the new API.

Fixes #1821.
  • Loading branch information
domenic committed Apr 29, 2017
1 parent 1f488ec commit 3d0f28d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/jsdom/browser/documentfeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ exports.defaultDocumentFeatures = {
SkipExternalResources: false
};

exports.applyDocumentFeatures = (documentImpl, features) => {
features = features || {};

exports.applyDocumentFeatures = (documentImpl, features = {}) => {
for (let i = 0; i < exports.availableDocumentFeatures.length; ++i) {
const featureName = exports.availableDocumentFeatures[i];
let featureSource;
Expand Down
2 changes: 2 additions & 0 deletions lib/jsdom/living/nodes/DOMImplementation-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class DOMImplementationImpl {
this._ownerDocument._defaultView._globalProxy = vm.runInContext("this", this._ownerDocument._global);
this._ownerDocument._defaultView = this._ownerDocument._defaultView._globalProxy;
}
} else {
this._features[feature] = [];
}
}

Expand Down
6 changes: 0 additions & 6 deletions lib/jsdom/living/nodes/Document-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ class DocumentImpl extends NodeImpl {
this.readyState = "loading";

this._lastFocusedElement = null;

// Add level2 features
this.implementation._addFeature("core", "2.0");
this.implementation._addFeature("html", "2.0");
this.implementation._addFeature("xhtml", "2.0");
this.implementation._addFeature("xml", "2.0");
}

_defaultElementBuilder(document, tagName) {
Expand Down
12 changes: 12 additions & 0 deletions test/api/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ describe("API: constructor options", () => {
assert.strictEqual(dom.window.eval, undefined);
});

it("should not execute any scripts, even in iframes, by default (GH-1821)", () => {
const dom = new JSDOM(`<iframe></iframe>`);
const frameWindow = dom.window.document.querySelector("iframe").contentWindow;

frameWindow.document.open();
frameWindow.document.write(`<script>parent.prop = "i was executed";</script>`);
frameWindow.document.close();

assert.strictEqual(dom.window.prop, undefined);
assert.strictEqual(frameWindow.eval, undefined);
});

it("should execute <script>s and eval when set to \"dangerously\"", () => {
const dom = new JSDOM(`<body>
<script>document.body.appendChild(document.createElement("hr"));</script>
Expand Down

0 comments on commit 3d0f28d

Please sign in to comment.