이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Metadata

ID: javascript-browser-security/regexp-non-literal

Language: JavaScript

Severity: Warning

Category: Security

CWE: 1333

Description

Regular expressions should not use a variable as an argument since an attacker may inject values and cause a regular expression denial of service (ReDoS). Instead, use a library like recheck to check that no ReDoS can be triggered by a regular expression.

Non-Compliant Code Examples

const foo = new RegExp(req.something);
const bar = new RegExp(variable);

Compliant Code Examples

const TAG = "<tag>";

const foo = new RegExp(`^\\d+-${topicId}$`);
const foo = new RegExp(/something/);
const foo = new RegExp("weofiwje");
const foo = new RegExp(TAG, 'g');
PREVIEWING: dgreen15/github-error-fix