Skip to content

[hotfix] Check for ReDoS #208

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/doxdox-parser-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"comment-parser": "1.4.1",
"safe-regex": "2.1.1",
"super-regex": "1.0.0"
},
"peerDependencies": {
Expand All @@ -24,6 +25,7 @@
"@eslint/js": "9.0.0",
"@types/jest": "29.5.12",
"@types/node": "20.12.7",
"@types/safe-regex": "1.1.6",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"eslint": "9.0.0",
Expand Down
15 changes: 14 additions & 1 deletion packages/doxdox-parser-custom/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import parse from './index';
import safe from 'safe-regex';

import parse, { JSDOC_PATTERN, IDENTIFIER_PATTERNS } from './index';

describe('custom parser', () => {
describe('parse', () => {
Expand Down Expand Up @@ -35,6 +37,17 @@ describe('custom parser', () => {
});
});

describe('check regular expressions', () => {
it('jsdoc pattern is safe', () => {
expect(safe(JSDOC_PATTERN)).toBeTruthy();
});
it('identifier patterns are safe', () => {
for (let i = 0; i < IDENTIFIER_PATTERNS.length; i += 1) {
expect(safe(IDENTIFIER_PATTERNS[i])).toBeTruthy();
}
});
});

describe('parse example from JSDoc documentation https://jsdoc.app/', () => {
// JSDoc Example from https://jsdoc.app/
it('parse amd-module', async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/doxdox-parser-custom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { firstMatch, matches } from 'super-regex';

const REGEX_TIMEOUT = 1000;

const JSDOC_PATTERN = /(^|[ \t]+)\/\*\*\s*\n?(?:[^*]*(?:\*[^/])?)*\*\//gms;
export const JSDOC_PATTERN =
/(^|[ \t]+)\/\*\*\s*\n?(?:[^*]*(?:\*[^/])?)*\*\//gms;

const IDENTIFIER_PATTERNS = [
export const IDENTIFIER_PATTERNS = [
/(?:class|function|var|let|const)[ ]+([a-z0-9_]+)[ ]*(?:[={(])?/i,
/((?:[a-z0-9_.]+)(\.prototype)?\.(?:[a-z0-9_]+))/i,
/[a-z0-9_]+[ ]*as[ ]*([a-z0-9_]+)/i,
Expand Down