Skip to content

[JS]: Regex Global Flag in Test Function #810

Closed
@aydinnyunus

Description

@aydinnyunus

Query PR

github/codeql#15163

Language

Javascript

CVE(s) ID list

CVE-2018-3737 uses global flag for parsing ssh public key.

Other incorrect regular expressions.

CWE

CWE-20: Improper Input Validation
CWE-185: Incorrect Regular Expression

Report

Overview

This pull request adds a new CodeQL query designed to detect issues related to the use of the global flag (g) in regular expressions within JavaScript and TypeScript codebases. This query focuses on identifying instances where the global flag might lead to inconsistent or erroneous behavior, particularly when used in conjunction with the test method of RegExp objects. The goal is to help developers identify and rectify potential bugs in their code related to global regular expressions.

Changes Introduced

  • New Query Added: RegexValidation.ql - Identifies potentially problematic uses of the global flag in regular expressions, especially when used in test method calls.
  • Code Examples: Provided in the /CWE-020 directory, showcasing both problematic (bad) and corrected (good) usage scenarios.
  • Documentation: Comprehensive documentation detailing the query's purpose, how it works, and the specific issue it addresses, including examples and best practices.
const forbidden = /['|]/g;
forbidden.test("'")

image

Are you planning to discuss this vulnerability submission publicly? (Blog Post, social networks, etc).

  • Yes
  • No

Blog post link

No response

Metadata

Metadata

Labels

All For OneSubmissions to the All for One, One for All bounty

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions