Skip to content

Commit 59e673e

Browse files
enhance security checks
1 parent 06387e4 commit 59e673e

8 files changed

Lines changed: 34 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ build
1616
.env.production.local
1717
.idea
1818
.eslintcache
19+
.copilot
20+
plan.md
1921

2022
# Compiled source
2123
*.com
@@ -48,5 +50,3 @@ Thumbs.db
4850
*.log
4951
*.sql
5052
*.sqlite
51-
52-
**/COPILOT.md

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
"<<projectname>>"
4343
]
4444
}
45-
]
45+
],
46+
"terminal.integrated.cwd": "react"
4647
}

react/eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import _import from 'eslint-plugin-import';
55
import jsxA11Y from 'eslint-plugin-jsx-a11y';
66
import jest from 'eslint-plugin-jest';
77
import prettier from 'eslint-plugin-prettier';
8+
import security from 'eslint-plugin-security';
89
import globals from 'globals';
910
import path from 'node:path';
1011
import { fileURLToPath } from 'node:url';
@@ -36,6 +37,7 @@ export default [
3637
'jsx-a11y': fixupPluginRules(jsxA11Y),
3738
jest,
3839
prettier: fixupPluginRules(prettier),
40+
security: fixupPluginRules(security),
3941
},
4042
languageOptions: {
4143
globals: {
@@ -72,6 +74,11 @@ export default [
7274
caughtErrorsIgnorePattern: '^_',
7375
},
7476
],
77+
'security/detect-object-injection': 'warn',
78+
'security/detect-unsafe-regex': 'warn',
79+
'security/detect-eval-with-expression': 'warn',
80+
'security/detect-non-literal-fs-filename': 'warn',
81+
'security/detect-non-literal-require': 'warn',
7582
},
7683
},
7784
];

react/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"babel-jest": "^30.0.5",
5353
"babel-preset-vite": "^1.1.3",
5454
"better-npm-audit": "^3.11.0",
55-
"eslint": "^9.33.0",
55+
"eslint": "^9.34.0",
5656
"eslint-config-prettier": "^10.1.8",
5757
"eslint-plugin-import": "^2.32.0",
5858
"eslint-plugin-jest": "^29.0.1",

react/src/serviceWorker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const isLocalhost = Boolean(
1515
// [::1] is the IPv6 localhost address.
1616
window.location.hostname === '[::1]' ||
1717
// 127.0.0.0/8 are considered localhost for IPv4.
18-
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
18+
window.location.hostname.startsWith('127.')
1919
);
2020

2121
export function register(config) {

react/src/services/Usage.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ describe('Usage', () => {
9191
fetch.mockResponseOnce(response);
9292
const data = await usage.request('xyz');
9393
expect(data.length).toEqual(expected.length);
94-
expected.forEach((item, index) => expect(data[index]).toEqual(item));
94+
expected.forEach((item, index) => {
95+
// eslint-disable-next-line security/detect-object-injection
96+
expect(data[index]).toEqual(item);
97+
});
9598
expect(fetch).toHaveBeenCalled();
9699
expect(fetch).toHaveBeenCalledWith('xyz/usage.db');
97100
});

react/src/utils/SortUtils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@
1919
const isAscending = (orderBy, property, ascending) => (orderBy === property ? !ascending : false);
2020

2121
const comparator = (isAscending, orderBy) => {
22+
const isSafeKey = (key, obj) =>
23+
typeof key === 'string' && /^[a-zA-Z0-9_$]+$/.test(key) && Object.prototype.hasOwnProperty.call(obj, key);
24+
2225
const ascending = (a, b, orderBy) => {
26+
if (!isSafeKey(orderBy, a) || !isSafeKey(orderBy, b)) return 0;
27+
// eslint-disable-next-line security/detect-object-injection
2328
if (a[orderBy] < b[orderBy]) return -1;
29+
// eslint-disable-next-line security/detect-object-injection
2430
if (a[orderBy] > b[orderBy]) return 1;
2531
return 0;
2632
};
2733
const descending = (a, b, orderBy) => {
34+
if (!isSafeKey(orderBy, a) || !isSafeKey(orderBy, b)) return 0;
35+
// eslint-disable-next-line security/detect-object-injection
2836
if (a[orderBy] > b[orderBy]) return -1;
37+
// eslint-disable-next-line security/detect-object-injection
2938
if (a[orderBy] < b[orderBy]) return 1;
3039
return 0;
3140
};

0 commit comments

Comments
 (0)