`_TITLE_REGEX` takes quadratic time on unclosed `<title>` tags, stalling the scan

Open Beginner friendly
#3,679 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
performance

Research direction

Start at response_to_event_dict in bbot/core/helpers/web/response_event.py:53 and the _TITLE_REGEX compiled just above it; run the reproduction snippet in the issue to confirm the quadratic blow-up, then measure any replacement the same way. The extraction is only used for the page title, so check the other callers named in the issue (http, wayback, lightfuzz) still get the same title values. Done means a 128 KiB body of repeated <title> tags returns quickly and the existing web helper tests still pass.

Written by the indexing model from the issue text.

Description

bug

response_to_event_dict (bbot/core/helpers/web/response_event.py:53) extracts the page title by running _TITLE_REGEX (<title[^>]*>(.*?)</title>, IGNORECASE | DOTALL) over the whole response body. On a body with many <title> tags and no </title>, every opening tag scans to the end of the body, so the search takes quadratic time.

Body (<title> repeated) Time
16 KiB 0.16 s
32 KiB 0.65 s
64 KiB 2.69 s
128 KiB 11.66 s

The search runs synchronously on the event loop, so the whole scan stalls while it runs, not just the module. In the http module it runs before the 4xx and WAF discard, so every response pays for it. wayback and lightfuzz call the same function. Bodies can be up to 10 MiB, so a single response can stall the scan for hours.

To reproduce:

import re, time
_TITLE_REGEX = re.compile(r"<title[^>]*>(.*?)</title>", re.IGNORECASE | re.DOTALL)
body = "<title>" * (128 * 1024 // 7)
t = time.perf_counter(); _TITLE_REGEX.search(body); print(time.perf_counter() - t)
Dominant language
Python
Stars
10.9k
Forks
959
Avg merge
2d 7h
Merged PRs (30d)
84

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from blacklanternsecurity/bbot

All issues in blacklanternsecurity/bbot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.