Skip to content

Commit 2a44346

Browse files
authored
Fix many JS vulns, fix tests (software-mansion#1775)
* fix: lint problem * fix: ignore malformed JSON file for FlowJS * fix: add missing @types/jest package * chore: update TypeScript version * chore: update all eslint deps Includes updating and installing missing/wrong peer deps * chore: update all Jest deps * chore: replace Jest config with jest.config.ts * fix: make root Jest tests ignore Example folders * chore: update css-select dep * chore: update css-tree to latest 1.x version 2.x broke tests so left a 1.x * chore: upgrade ansi-regex to close JS vuln * chore: upgrade ejs to close JS vuln * chore: upgrade async to close JS vuln * chore: upgrade simple-plist to close JS vuln
1 parent 1dc42ea commit 2a44346

16 files changed

+1714
-1668
lines changed

Diff for: .flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[ignore]
2+
.*/node_modules/resolve/test/resolver/malformed_package_json/package.json
23

34
[include]
45

Diff for: jest.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
testPathIgnorePatterns: ['/node_modules/', '/Example/', '/TestsExample/'],
5+
preset: 'react-native',
6+
verbose: true,
7+
};
8+
9+
export default config;

Diff for: package.json

+18-15
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,39 @@
5959
"react-native": ">=0.50.0"
6060
},
6161
"dependencies": {
62-
"css-select": "^4.2.1",
63-
"css-tree": "^1.0.0-alpha.39"
62+
"css-select": "^5.1.0",
63+
"css-tree": "^1.1.3"
6464
},
6565
"devDependencies": {
66+
"@babel/core": "^7.18.2",
67+
"@babel/plugin-syntax-flow": "^7.17.12",
68+
"@babel/plugin-transform-react-jsx": "^7.17.12",
6669
"@react-native-community/bob": "^0.9.7",
67-
"@react-native-community/eslint-config": "0.0.7",
68-
"@react-native-community/eslint-plugin": "^1.0.0",
70+
"@react-native-community/eslint-config": "^3.0.2",
71+
"@react-native-community/eslint-plugin": "^1.2.0",
6972
"@types/css-tree": "^1.0.3",
73+
"@types/jest": "^27.5.2",
74+
"@types/node": "*",
7075
"@types/react": "^17.0.16",
7176
"@types/react-native": "^0.63.40",
7277
"babel-eslint": "^10.1.0",
73-
"babel-jest": "^25.1.0",
74-
"eslint": "^6.8.0",
75-
"eslint-plugin-flowtype": "^4.6.0",
76-
"eslint-plugin-prettier": "^3.1.2",
77-
"eslint-plugin-react": "^7.18.3",
78+
"babel-jest": "^28.1.0",
79+
"eslint": "^8.16.0",
80+
"eslint-plugin-flowtype": "^8.0.3",
81+
"eslint-plugin-prettier": "^4.0.0",
82+
"eslint-plugin-react": "^7.30.0",
7883
"flow-bin": "^0.119.1",
7984
"flow-typed": "^3.0.0",
8085
"flowgen": "^1.10.0",
81-
"jest": "^25.1.0",
86+
"jest": "^28.1.0",
8287
"pegjs": "^0.10.0",
83-
"prettier": "^1.19.1",
88+
"prettier": "^2.6.2",
8489
"react": "^16.13.0",
8590
"react-native": "^0.62.3",
8691
"react-test-renderer": "^16.13.0",
8792
"release-it": "^14.12.5",
88-
"typescript": "^3.8.3"
89-
},
90-
"jest": {
91-
"preset": "react-native"
93+
"ts-node": "^10.8.0",
94+
"typescript": "^4.7.2"
9295
},
9396
"nativePackage": true
9497
}

Diff for: src/ReactNativeSVG.web.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function remeasure() {
227227

228228
export class WebShape<
229229
P extends BaseProps = BaseProps,
230-
C = {}
230+
C = {},
231231
> extends React.Component<P, C> {
232232
[x: string]: unknown;
233233
_remeasureMetricsOnActivation: () => void;

Diff for: src/css.tsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function existsOne(
117117
elems: Array<XmlAST | string>,
118118
): boolean {
119119
return elems.some(
120-
elem =>
120+
(elem) =>
121121
typeof elem === 'object' &&
122122
(predicate(elem) || existsOne(predicate, elem.children)),
123123
);
@@ -290,7 +290,7 @@ function filterByPseudos(selectors: FlatSelectorList) {
290290
csstree.generate({
291291
type: 'Selector',
292292
children: new List<CssNode>().fromArray(
293-
pseudos.map(pseudo => pseudo.item.data),
293+
pseudos.map((pseudo) => pseudo.item.data),
294294
),
295295
}),
296296
),
@@ -307,7 +307,7 @@ const usePseudos = [''];
307307
*/
308308
function cleanPseudos(selectors: FlatSelectorList) {
309309
selectors.forEach(({ pseudos }) =>
310-
pseudos.forEach(pseudo => pseudo.list.remove(pseudo.item)),
310+
pseudos.forEach((pseudo) => pseudo.list.remove(pseudo.item)),
311311
);
312312
}
313313

@@ -493,7 +493,7 @@ function sortSelectors(selectors: FlatSelectorList) {
493493
return selectors;
494494
}
495495
const specs = selectors.map(selectorWithSpecificity);
496-
return exec(specs, len).map(s => s.selector);
496+
return exec(specs, len).map((s) => s.selector);
497497
}
498498

499499
const declarationParseProps = {
@@ -517,14 +517,17 @@ function CSSStyleDeclaration(ast: XmlAST) {
517517
styles,
518518
declarationParseProps,
519519
) as DeclarationList;
520-
declarations.children.each(node => {
520+
declarations.children.each((node) => {
521521
try {
522522
const { property, value, important } = node as Declaration;
523523
const name = property.trim();
524524
priority.set(name, important);
525525
style[camelCase(name)] = csstree.generate(value).trim();
526526
} catch (styleError) {
527-
if (styleError.message !== 'Unknown node type: undefined') {
527+
if (
528+
styleError instanceof Error &&
529+
styleError.message !== 'Unknown node type: undefined'
530+
) {
528531
console.warn(
529532
"Warning: Parse error when parsing inline styles, style properties of this element cannot be used. The raw styles can still be get/set using .attr('style').value. Error details: " +
530533
styleError,
@@ -666,7 +669,7 @@ export const inlineStyles: Middleware = function inlineStyles(
666669
},
667670
});
668671
} catch (selectError) {
669-
if (selectError.constructor === SyntaxError) {
672+
if (selectError instanceof SyntaxError) {
670673
console.warn(
671674
'Warning: Syntax error when trying to select \n\n' +
672675
selectorStr +
@@ -695,11 +698,7 @@ export function SvgCssUri(props: UriProps) {
695698
const { uri, onError = err } = props;
696699
const [xml, setXml] = useState<string | null>(null);
697700
useEffect(() => {
698-
uri
699-
? fetchText(uri)
700-
.then(setXml)
701-
.catch(onError)
702-
: setXml(null);
701+
uri ? fetchText(uri).then(setXml).catch(onError) : setXml(null);
703702
}, [onError, uri]);
704703
return <SvgCss xml={xml} override={props} />;
705704
}

Diff for: src/elements/Shape.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ export default class Shape<P> extends Component<P> {
252252
* representative example / reproduction.
253253
* */
254254
getBBox = (options?: SVGBoundingBoxOptions): SVGRect => {
255-
const { fill = true, stroke = true, markers = true, clipped = true } =
256-
options || {};
255+
const {
256+
fill = true,
257+
stroke = true,
258+
markers = true,
259+
clipped = true,
260+
} = options || {};
257261
const handle = findNodeHandle(this.root as Component);
258262
return RNSVGRenderableManager.getBBox(handle, {
259263
fill,

Diff for: src/lib/Matrix2D.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
const DEG_TO_RAD = Math.PI / 180;
66

77
export const identity: [number, number, number, number, number, number] = [
8-
1,
9-
0,
10-
0,
11-
1,
12-
0,
13-
0,
8+
1, 0, 0, 1, 0, 0,
149
];
1510

1611
let a = 1;

Diff for: src/lib/SvgTouchableMixin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const SvgTouchableMixin = {
117117
};
118118

119119
const touchKeys = Object.keys(SvgTouchableMixin);
120-
const touchVals = touchKeys.map(key => SvgTouchableMixin[key]);
120+
const touchVals = touchKeys.map((key) => SvgTouchableMixin[key]);
121121
const numTouchKeys = touchKeys.length;
122122

123123
export default (target: { [x: string]: unknown; state: unknown }) => {

Diff for: src/lib/extract/extractBrush.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const contextFillBrush = [3];
77
const contextStrokeBrush = [4];
88

99
export default function extractBrush(color?: ColorValue) {
10-
1110
if (!color || color === 'none') {
1211
return null;
1312
}

Diff for: src/lib/extract/extractGradient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function extractGradient(
5454

5555
const stops = [];
5656
const childArray = children
57-
? Children.map(children, child =>
57+
? Children.map(children, (child) =>
5858
React.cloneElement(child, {
5959
parent,
6060
}),

Diff for: src/lib/extract/extractLengthList.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ export default function extractLengthList(
1111
} else if (typeof lengthList === 'number') {
1212
return [lengthList];
1313
} else if (typeof lengthList === 'string') {
14-
return lengthList
15-
.trim()
16-
.replace(commaReg, ' ')
17-
.split(spaceReg);
14+
return lengthList.trim().replace(commaReg, ' ').split(spaceReg);
1815
} else {
1916
return [];
2017
}

Diff for: src/lib/extract/extractText.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import extractLengthList from './extractLengthList';
33
import { pickNotNil } from '../util';
44
import { NumberArray, NumberProp } from './types';
55

6-
const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?(?:%|px|em|pt|pc|mm|cm|in]))*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
6+
const fontRegExp =
7+
/^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?(?:%|px|em|pt|pc|mm|cm|in]))*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i;
78
const fontFamilyPrefix = /^[\s"']*/;
89
const fontFamilySuffix = /[\s"']*$/;
910
const commaReg = /\s*,\s*/g;

Diff for: src/lib/extract/extractTransform.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ import { parse } from './transform';
33
import { NumberProp, TransformedProps, TransformProps } from './types';
44

55
function appendTransformProps(props: TransformedProps) {
6-
const {
7-
x,
8-
y,
9-
originX,
10-
originY,
11-
scaleX,
12-
scaleY,
13-
rotation,
14-
skewX,
15-
skewY,
16-
} = props;
6+
const { x, y, originX, originY, scaleX, scaleY, rotation, skewX, skewY } =
7+
props;
178
appendTransform(
189
x + originX,
1910
y + originY,

Diff for: src/lib/extract/extractViewBox.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ export default function extractViewBox(props: {
3636
return null;
3737
}
3838

39-
const params = (Array.isArray(viewBox)
40-
? viewBox
41-
: viewBox.trim().split(spacesRegExp)
39+
const params = (
40+
Array.isArray(viewBox) ? viewBox : viewBox.trim().split(spacesRegExp)
4241
).map(Number);
4342

4443
if (params.length !== 4 || params.some(isNaN)) {

Diff for: src/xml.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ export const err = console.error.bind(console);
110110

111111
export function SvgXml(props: XmlProps) {
112112
const { onError = err, xml, override } = props;
113-
const ast = useMemo<JsxAST | null>(() => (xml !== null ? parse(xml) : null), [
114-
xml,
115-
]);
113+
const ast = useMemo<JsxAST | null>(
114+
() => (xml !== null ? parse(xml) : null),
115+
[xml],
116+
);
116117

117118
try {
118119
return <SvgAst ast={ast} override={override || props} />;
@@ -134,11 +135,7 @@ export function SvgUri(props: UriProps) {
134135
const { onError = err, uri } = props;
135136
const [xml, setXml] = useState<string | null>(null);
136137
useEffect(() => {
137-
uri
138-
? fetchText(uri)
139-
.then(setXml)
140-
.catch(onError)
141-
: setXml(null);
138+
uri ? fetchText(uri).then(setXml).catch(onError) : setXml(null);
142139
}, [onError, uri]);
143140
return <SvgXml xml={xml} override={props} />;
144141
}

0 commit comments

Comments
 (0)