Skip to content

Commit

Permalink
- Fix: Avoid cross-frame unsafe instanceof
Browse files Browse the repository at this point in the history
- npm: Update eslint-config-ash-nazg
  • Loading branch information
brettz9 committed Nov 28, 2018
1 parent 9f844f6 commit 99ec41a
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 33 deletions.
7 changes: 6 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

# ?

- Fix: Avoid cross-frame unsafe `instanceof`
- Enhancement: Add svgcanvas distributions
- Update: Bump StackBlur version
- Demo: Rename import to match named dist export
- Linting (ESLint): Prefer `addEventListener`, exponentiation operator,
avoiding catastrophic regexes, prefer spread, prefer
`startsWith`/`endsWith`, no fn ref in iterator
- npm: Update devDeps

# 4.0.1

Expand Down
17 changes: 16 additions & 1 deletion dist/dom-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
(function () {
'use strict';

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}

return _typeof(obj);
}

// From https://github.com/inexorabletash/polyfill/blob/master/dom.js

/**
Expand Down Expand Up @@ -37,7 +51,8 @@

function convertNodesIntoANode(nodes) {
nodes = nodes.map(function (node) {
return !(node instanceof Node) ? document.createTextNode(node) : node;
var isNode = node && _typeof(node) === 'object' && 'nodeType' in node;
return isNode ? node : document.createTextNode(node);
});

if (nodes.length === 1) {
Expand Down
10 changes: 7 additions & 3 deletions dist/index-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,6 @@ var getReverseNS = function getReverseNS() {
}
})();

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2758,9 +2757,14 @@ var supportsNativeSVGTransformLists_ = function () {
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/index-es.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-es.min.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/index-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,6 @@
}
})();

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2764,9 +2763,14 @@
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/index-umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-umd.min.js.map

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions dist/redirect-on-lacking-support.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
(function () {
'use strict';

function _typeof(obj) {
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}

return _typeof(obj);
}

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
Expand Down Expand Up @@ -2419,7 +2433,6 @@

};

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2559,9 +2572,14 @@
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

if (!supportsSvg()) {
Expand Down
10 changes: 7 additions & 3 deletions dist/svgcanvas-iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,6 @@ var SvgCanvas = (function () {
return reverseNS;
};

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2970,9 +2969,14 @@ var SvgCanvas = (function () {
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/svgcanvas-iife.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/svgcanvas-iife.min.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions editor/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ const rxform = rect.transform.baseVal;
const t1 = svg.createSVGTransform();
rxform.appendItem(t1);
const r1 = rxform.getItem(0);
// Todo: Do frame-independent instance checking
return r1 instanceof SVGTransform && t1 instanceof SVGTransform &&
const isSVGTransform = (o) => {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && typeof o === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};
return isSVGTransform(r1) && isSVGTransform(t1) &&
r1.type === t1.type && r1.angle === t1.angle &&
r1.matrix.a === t1.matrix.a &&
r1.matrix.b === t1.matrix.b &&
Expand Down
3 changes: 2 additions & 1 deletion editor/external/dom-polyfill/dom-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function mixin (o, ps) {
*/
function convertNodesIntoANode (nodes) {
nodes = nodes.map((node) => {
return !(node instanceof Node) ? document.createTextNode(node) : node;
const isNode = node && typeof node === 'object' && 'nodeType' in node;
return isNode ? node : document.createTextNode(node);
});
if (nodes.length === 1) {
return nodes[0];
Expand Down
10 changes: 7 additions & 3 deletions editor/xdomain-svgedit-config-iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,6 @@
}
})();

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2761,9 +2760,14 @@
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

/**
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"axe-testcafe": "^1.1.0",
"babel-plugin-transform-object-rest-spread": "^7.0.0-beta.3",
"eslint": "5.9.0",
"eslint-config-ash-nazg": "0.1.1",
"eslint-config-ash-nazg": "0.2.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-compat": "2.6.3",
"eslint-plugin-import": "2.14.0",
Expand Down
10 changes: 7 additions & 3 deletions svgedit-config-iife.js
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,6 @@
}
})();

/* globals jQuery */
var $ = jQuery;

var supportsSVG_ = function () {
Expand Down Expand Up @@ -2761,9 +2760,14 @@
var rxform = rect.transform.baseVal;
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
var r1 = rxform.getItem(0); // Todo: Do frame-independent instance checking
var r1 = rxform.getItem(0);

var isSVGTransform = function isSVGTransform(o) {
// https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform
return o && _typeof(o) === 'object' && typeof o.setMatrix === 'function' && 'angle' in o;
};

return r1 instanceof SVGTransform && t1 instanceof SVGTransform && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
return isSVGTransform(r1) && isSVGTransform(t1) && r1.type === t1.type && r1.angle === t1.angle && r1.matrix.a === t1.matrix.a && r1.matrix.b === t1.matrix.b && r1.matrix.c === t1.matrix.c && r1.matrix.d === t1.matrix.d && r1.matrix.e === t1.matrix.e && r1.matrix.f === t1.matrix.f;
}(); // Public API

/**
Expand Down

0 comments on commit 99ec41a

Please sign in to comment.