Skip to content

Commit c939dca

Browse files
committed
fix: prevent ReDoS vulnerability in HTML payload unwrapping regex
Fixed a polynomial Regular Expression Denial of Service (ReDoS) vulnerability in the HTML payload unwrapping function. The base64 capture group in the regex pattern was changed from greedy (`+`) to non-greedy (`+?`) to prevent exponential backtracking when processing malicious input. **Security Impact:** - Prevents potential DoS attacks through crafted HTML input that could cause excessive CPU usage - Maintains the same functional behavior for legitimate base64 payload extraction **Technical Details:** - Modified regex pattern in `lib/tdf3/src/utils/unwrap.ts` line 6 - Changed `([a-zA-Z0-9+/=]+)` to `([a-zA-Z0-9+/=]+?)` to use non-greedy matching - This eliminates catastrophic backtracking scenarios while preserving correct base64 extraction
1 parent f0d9719 commit c939dca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/tdf3/src/utils/unwrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InvalidFileError } from '../../../src/errors.js';
33

44
export function unwrapHtml(htmlPayload: Uint8Array): Uint8Array {
55
const html = new TextDecoder().decode(htmlPayload);
6-
const payloadRe = /<input id=['"]?data-input['"]?[^>]*?value=['"]?([a-zA-Z0-9+/=]+)['"]?/;
6+
const payloadRe = /<input id=['"]?data-input['"]?[^>]*?value=['"]?([a-zA-Z0-9+/=]+?)['"]?/;
77
const reResult = payloadRe.exec(html);
88
if (!reResult) {
99
throw new InvalidFileError('Payload is missing');

0 commit comments

Comments
 (0)