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 all 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
16 changes: 16 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,19 @@ describe('ICSS :export pseudo-selector', () => {
).toThrow()
})
})
describe('ReDos', () => {
jest.setTimeout(1000)
it('should finish transform of 100k zeros + "p" in under 1s', () => {
const bigValue = '0'.repeat(100000) + 'p'
const cssString = `
.foo { some-prop: "${bigValue}"; }
`
const start = performance.now()
transform(cssString, {
scalable: false,
parseMediaQueries: false
})
const duration = performance.now() - start
expect(duration).toBeLessThan(1000)
})
})
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