Skip to content

Commit ffc49ab

Browse files
Vitaly Puzrinmakenowjust
Vitaly Puzrin
andcommitted
Fix possible ReDOS in newline rule.
Co-authored-by: MakeNowJust <make.just.on@gmail.com>
1 parent 76469e8 commit ffc49ab

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [12.3.2] - 2022-01-08
9+
### Security
10+
- Fix possible ReDOS in newline rule. Thanks to @MakeNowJust.
11+
812

913
## [12.3.1] - 2022-01-07
1014
### Fixed
@@ -588,6 +592,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
588592
- Renamed presets folder (configs -> presets).
589593

590594

595+
[12.3.2]: https://github.com/markdown-it/markdown-it/compare/12.3.1...12.3.2
591596
[12.3.1]: https://github.com/markdown-it/markdown-it/compare/12.3.0...12.3.1
592597
[12.3.0]: https://github.com/markdown-it/markdown-it/compare/12.2.0...12.3.0
593598
[12.2.0]: https://github.com/markdown-it/markdown-it/compare/12.1.0...12.2.0

lib/rules_inline/newline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var isSpace = require('../common/utils').isSpace;
66

77

88
module.exports = function newline(state, silent) {
9-
var pmax, max, pos = state.pos;
9+
var pmax, max, ws, pos = state.pos;
1010

1111
if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; }
1212

@@ -20,7 +20,11 @@ module.exports = function newline(state, silent) {
2020
if (!silent) {
2121
if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) {
2222
if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) {
23-
state.pending = state.pending.replace(/ +$/, '');
23+
// Find whitespaces tail of pending chars.
24+
ws = pmax - 1;
25+
while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 0x20) ws--;
26+
27+
state.pending = state.pending.slice(0, ws);
2428
state.push('hardbreak', 'br', 0);
2529
} else {
2630
state.pending = state.pending.slice(0, -1);

test/pathological.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,9 @@ describe('Pathological sequences speed', () => {
138138
it('autolinks <<<<...<<> pattern', async () => {
139139
await test_pattern('<'.repeat(400000) + '>');
140140
});
141+
142+
it('hardbreak whitespaces pattern', async () => {
143+
await test_pattern('x' + ' '.repeat(150000) + 'x \nx');
144+
});
141145
});
142146
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy