TRE Python binding, ReDoS robustness demo

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

An experimental Python binding to the TRE regex engine shows developers a practical way to avoid catastrophic ReDoS vulnerabilities that the built-in re module cannot prevent.

Read this as

Simon Willison had Claude Code build a small Python connection to TRE, a regular expression engine originally used in Redis. Regular expressions are pattern-matching rules, and some malicious ones can freeze programs, an attack called ReDoS. TRE avoids this because it does not use backtracking, so it handled attacks on 10-million-character inputs quickly while Python's built-in re module choked on much smaller ones.

ReDoS attacks can hang servers using Python's standard re module, which scales exponentially on crafted inputs. Willison's experimental ctypes binding to TRE, built via Claude Code, demonstrates linear-time matching even on 10-million-character inputs. No production-ready library or pricing is offered, it is a proof of concept, but engineering teams running user-supplied regexes should evaluate TRE-based alternatives.

Willison used Claude Code to generate a minimal ctypes Python binding to Ville Laurikari's TRE regex engine, the one antirez adopted for Redis. TRE lacks backtracking, giving linear-time worst-case matching: it processed 'evil' regex patterns against 10-million-character inputs quickly, while Python's re module scaled exponentially. The binding is experimental, and no benchmark table, package release or performance figures beyond that input size are given.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

TRE Python Redis Claude Code Datasette Pyodide

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading