| 1 |
Security considerations |
| 2 |
----------------------- |
| 3 |
|
| 4 |
Pygments provides no guarantees on execution time, which needs to be taken |
| 5 |
into consideration when using Pygments to process arbitrary user inputs. For |
| 6 |
example, if you have a web service which uses Pygments for highlighting, there |
| 7 |
may be inputs which will cause the Pygments process to run "forever" and/or use |
| 8 |
significant amounts of memory. This can subsequently be used to perform a |
| 9 |
remote denial-of-service attack on the server if the processes are not |
| 10 |
terminated quickly. |
| 11 |
|
| 12 |
Unfortunately, it's practically impossible to harden Pygments itself against |
| 13 |
those issues: Some regular expressions can result in "catastrophic |
| 14 |
backtracking", but other bugs like incorrect matchers can also |
| 15 |
cause similar problems, and there is no way to find them in an automated fashion |
| 16 |
(short of solving the halting problem.) Pygments has extensive unit tests, |
| 17 |
automated randomized testing, and is also tested by `OSS-Fuzz <https://github.com/google/oss-fuzz/tree/master/projects/pygments>`_, |
| 18 |
but we will never be able to eliminate all bugs in this area. |
| 19 |
|
| 20 |
Our recommendations are: |
| 21 |
|
| 22 |
* Ensure that the Pygments process is *terminated* after a reasonably short |
| 23 |
timeout. In general Pygments should take seconds at most for reasonably-sized |
| 24 |
input. |
| 25 |
* *Limit* the number of concurrent Pygments processes to avoid oversubscription |
| 26 |
of resources. |
| 27 |
|
| 28 |
The Pygments authors will treat any bug resulting in long processing times with |
| 29 |
high priority -- it's one of those things that will be fixed in a patch release. |
| 30 |
When reporting a bug where you suspect super-linear execution times, please make |
| 31 |
sure to attach an input to reproduce it. |