You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,31 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
6
6
7
7
## [Unreleased][unreleased]
8
8
9
+
This is a **security release** to address potential denial of service attacks when parsing specially crafted,
10
+
malicious input from untrusted sources (like user input).
11
+
12
+
### Added
13
+
14
+
- Added `max_delimiters_per_line` config option to prevent denial of service attacks when parsing malicious input
15
+
- Added `table/max_autocompleted_cells` config option to prevent denial of service attacks when parsing large tables
16
+
- The `AttributesExtension` now supports attributes without values (#985, #986)
17
+
- The `AutolinkExtension` exposes two new configuration options to override the default behavior (#969, #987):
18
+
-`autolink/allowed_protocols` - an array of protocols to allow autolinking for
19
+
-`autolink/default_protocol` - the default protocol to use when none is specified
20
+
- Added `RegexHelper::isWhitespace()` method to check if a given character is an ASCII whitespace character
21
+
- Added `CacheableDelimiterProcessorInterface` to ensure linear complexity for dynamic delimiter processing
22
+
- Added `Bracket` delimiter type to optimize bracket parsing
23
+
24
+
### Changed
25
+
26
+
-`[` and `]` are no longer added as `Delimiter` objects on the stack; a new `Bracket` type with its own stack is used instead
27
+
-`UrlAutolinkParser` no longer parses URLs with more than 127 subdomains
28
+
- Expanded reference links can no longer exceed 100kb, or the size of the input document (whichever is greater)
29
+
- Delimiters should always provide a non-null value via `DelimiterInterface::getIndex()`
30
+
- We'll attempt to infer the index based on surrounding delimiters where possible
31
+
- The `DelimiterStack` now accepts integer positions for any `$stackBottom` argument
32
+
- Several small performance optimizations
33
+
9
34
## [2.5.3] - 2024-08-16
10
35
11
36
### Changed
@@ -77,6 +102,25 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
77
102
- Fixed declaration parser being too strict
78
103
-`FencedCodeRenderer`: don't add `language-` to class if already prefixed
79
104
105
+
### Deprecated
106
+
107
+
- Returning dynamic values from `DelimiterProcessorInterface::getDelimiterUse()` is deprecated
108
+
- You should instead implement `CacheableDelimiterProcessorInterface` to help the engine perform caching to avoid performance issues.
109
+
- Failing to set a delimiter's index (or returning `null` from `DelimiterInterface::getIndex()`) is deprecated and will not be supported in 3.0
110
+
- Deprecated `DelimiterInterface::isActive()` and `DelimiterInterface::setActive()`, as these are no longer used by the engine
111
+
- Deprecated `DelimiterStack::removeEarlierMatches()` and `DelimiterStack::searchByCharacter()`, as these are no longer used by the engine
112
+
- Passing a `DelimiterInterface` as the `$stackBottom` argument to `DelimiterStack::processDelimiters()` or `::removeAll()` is deprecated and will not be supported in 3.0; pass the integer position instead.
113
+
114
+
### Fixed
115
+
116
+
- Fixed NUL characters not being replaced in the input
- Fixed quadratic complexity parsing emphasis and strikethrough delimiters
119
+
- Fixed issue where having 500,000+ delimiters could trigger a [known segmentation fault issue in PHP's garbage collection](https://bugs.php.net/bug.php?id=68606)
120
+
- Fixed quadratic complexity deactivating link openers
121
+
- Fixed quadratic complexity parsing long backtick code spans with no matching closers
122
+
- Fixed catastrophic backtracking when parsing link labels/titles
Copy file name to clipboardExpand all lines: docs/2.5/configuration.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ $config = [
27
27
'html_input' => 'escape',
28
28
'allow_unsafe_links' => false,
29
29
'max_nesting_level' => PHP_INT_MAX,
30
+
'max_delimiters_per_line' => PHP_INT_MAX,
30
31
'slug_normalizer' => [
31
32
'max_length' => 255,
32
33
],
@@ -73,6 +74,7 @@ Here's a list of the core configuration options available:
73
74
-`escape` - Escape all HTML
74
75
-`allow_unsafe_links` - Remove risky link and image URLs by setting this to `false` (default: `true`)
75
76
-`max_nesting_level` - The maximum nesting level for blocks (default: `PHP_INT_MAX`). Setting this to a positive integer can help protect against long parse times and/or segfaults if blocks are too deeply-nested.
77
+
-`max_delimiters_per_line` - The maximum number of delimiters (e.g. `*` or `_`) allowed in a single line (default: `PHP_INT_MAX`). Setting this to a positive integer can help protect against long parse times and/or segfaults if lines are too long.
76
78
-`slug_normalizer` - Array of options for configuring how URL-safe slugs are created; see [the slug normalizer docs](/2.5/customization/slug-normalizer/#configuration) for more details
77
79
-`instance` - An alternative normalizer to use (defaults to the included `SlugNormalizer`)
78
80
-`max_length` - Limits the size of generated slugs (defaults to 255 characters)
Copy file name to clipboardExpand all lines: docs/2.5/customization/delimiter-processing.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,8 @@ public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $
48
48
49
49
This method is used to tell the engine how many characters from the matching delimiters should be consumed. For simple processors you'll likely return `1` (or whatever your minimum length is). In more advanced cases, you can examine the opening and closing delimiters and perform additional logic to determine whether they should be fully or partially consumed. You can also return `0` if you'd like.
50
50
51
+
**Note:** Unless you're returning a hard-coded value, you should probably implement `CacheableDelimiterProcessorInterface` instead of `DelimiterProcessorInterface` - this will allow the engine to perform additional caching for better performance.
Copy file name to clipboardExpand all lines: docs/2.5/extensions/tables.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,7 @@ $config = [
44
44
'center' => ['align' => 'center'],
45
45
'right' => ['align' => 'right'],
46
46
],
47
+
'max_autocompleted_cells' => 10_000,
47
48
],
48
49
];
49
50
@@ -159,6 +160,14 @@ $config = [
159
160
160
161
Or any other HTML attributes you'd like!
161
162
163
+
### Limiting Auto-Completed Cells
164
+
165
+
The GFM specification says that the:
166
+
167
+
> table’s rows may vary in the number of cells. If there are a number of cells fewer than the number of cells in the header row, empty cells are inserted.
168
+
169
+
This feature could be abused to create very large tables. To prevent this, you can configure the `max_autocompleted_cells` option to limit the number of empty cells that will be autocompleted. If the limit is reached, further parsing of the table will be aborted.
170
+
162
171
## Credits
163
172
164
173
The Table functionality was originally built by [Martin Hasoň](https://github.com/hason) and [Webuni s.r.o.](https://www.webuni.cz) before it was merged into the core parser.
See the [configuration](/2.5/configuration/) section for more information.
90
91
92
+
## Max Delimiters Per Line
93
+
94
+
Similarly to the maximum nesting level, **no maximum number of delimiters per line is enforced by default.** Delimiters can be nested (like `*a **b** c*`) or un-nested (like `*a* *b* *c*`) - in either case, having too many in a single line can result in long parse times. We therefore have a separate option to limit the number of delimiters per line.
95
+
96
+
If you need to parse untrusted input, consider setting a reasonable `max_delimiters_per_line` (perhaps 100-1000) depending on your needs. Once this level is hit, any subsequent delimiters on that line will be rendered as plain text.
Although this library does offer these security features out-of-the-box, some users may opt to also run the HTML output through additional filtering layers (like HTMLPurifier). If you do this, make sure you **thoroughly** test your additional post-processing steps and configure them to work properly with the types of HTML elements and attributes that converted Markdown might produce, otherwise, you may end up with weird behavior like missing images, broken links, mismatched HTML tags, etc.
0 commit comments