calibre contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service).

Bug #1951979 reported by Dwi Siswanto
258
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

# Summary
calibre contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service).

# Description

ReDoS, or Regular Expression Denial of Service, is a vulnerability affecting inefficient regular expressions which can perform extremely badly when run on a crafted input string.

# Proof of Concept

Vulnerable code: https://github.com/kovidgoyal/calibre/blob/39a22268b930f0d0cf51a42b556982da5f3dbf4d/src/calibre/ebooks/conversion/preprocess.py#L383

To see that the regular expression is vulnerable, copy-paste it into a separate file & run the code as shown below.

```python
import re

reg = re.compile(r'<head[^>]*>\n*(.*?)\n*</head>', re.IGNORECASE|re.DOTALL)

reg.match('<head>' + '\n' * 1337)
```

# Impact
This issue may lead to a denial of service.

# References
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS

CVE References

Revision history for this message
Kovid Goyal (kovid) wrote : Fixed in master

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

 status fixreleased

Changed in calibre:
status: New → Fix Released
Revision history for this message
Dwi Siswanto (dw1s) wrote :

Thanks for the quick fix, @kovid!
I confirm that it has been patched at `35b7e38c197ba4a3c17531e516610af8795e348`.

information type: Private Security → Private
information type: Private → Private Security
Dwi Siswanto (dw1s)
description: updated
Dwi Siswanto (dw1s)
information type: Private Security → Public Security
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.