Skip to content

fix: 存在潜在的 ReDoS 漏洞或低效正则表达式 #17619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/css-to-react-native/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3636,3 +3636,23 @@
).toThrow()
})
})

describe('ReDos', () => {
jest.setTimeout(1000);

Check failure on line 3641 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3641 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3641 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3641 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon
it('should finish transform of 100k zeros + "p" in under 1s', () => {

Check failure on line 3642 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Block must not be padded by blank lines

Check failure on line 3642 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Block must not be padded by blank lines

Check failure on line 3642 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Block must not be padded by blank lines

Check failure on line 3642 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Block must not be padded by blank lines

const bigValue = '0'.repeat(100000) + 'p';

Check failure on line 3644 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3644 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3644 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3644 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon

const cssString = `
.foo { some-prop: "${bigValue}"; }
`;

Check failure on line 3648 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3648 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3648 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3648 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon

const start = performance.now();

Check failure on line 3650 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3650 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3650 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3650 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon
transform(cssString, {
scalable: false,
parseMediaQueries: false
});

Check failure on line 3654 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3654 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3654 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3654 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon
const duration = performance.now() - start;

Check failure on line 3655 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3655 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3655 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3655 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon
expect(duration).toBeLessThan(1000);

Check failure on line 3656 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Extra semicolon

Check failure on line 3656 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Extra semicolon

Check failure on line 3656 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-13)

Extra semicolon

Check failure on line 3656 in packages/css-to-react-native/__tests__/index.spec.js

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Extra semicolon
})
})
4 changes: 2 additions & 2 deletions packages/css-to-react-native/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const transformDecls = (styles, declarations, result, options = {}) => {
if (
typeof options.scalable === 'boolean' &&
!options.scalable &&
/(\d+)px/.test(value)
/(?<!\d)(\d+)px/.test(value)
) {
value = value.replace(/(\d+)px/g, '$1PX')
value = value.replace(/(?<!\d)(\d+)px/g, '$1PX')
}
// expect value is legal so that remove !import
if (/!import/i.test(value)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/css-to-react-native/src/transforms/rem.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const remToPx = value => {
return value.replace(/(\d*\.?\d+)rem/g, (match, m1) => parseFloat(m1, 10) * 16 + 'px')
return value.replace(/(?<!\d)((?:\d*\.\d+)|\d+)rem/g, (match, m1) => parseFloat(m1, 10) * 16 + 'px')
}
Loading