Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Guard Point.from_string against ReDoS on very long inputs (#608) - #610

Merged
KostyaEsmukov merged 2 commits into
geopy:masterfrom
apoorvdarshan:fix-608-point-redos
Jul 10, 2026
Merged

Guard Point.from_string against ReDoS on very long inputs (#608)#610
KostyaEsmukov merged 2 commits into
geopy:masterfrom
apoorvdarshan:fix-608-point-redos

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Contributor

Summary

Fixes #608 (ReDoS in geopy.Point, CWE-1333). POINT_PATTERN starts with .*? (so a coordinate can appear after some leading text, e.g. UT: N 39°20' 0'') and matches whitespace in several overlapping places. On a long non-matching input it backtracks quadratically:

geopy.Point("<" + " " * 3000 + "X")   # ~0.2s, and grows with input size

An endpoint that forwards user input to geopy.Point() (as the docs suggest for coordinate strings) can be tied up with modest request volume.

Fix

A valid coordinate string is short (the longest in the test suite is 46 chars), so cap the input length in from_string() before matching and reject longer strings with the usual ValueError. This bounds the worst‑case matching time to well under a millisecond.

Atomic groups / possessive quantifiers would also help, but they require Python 3.11+ and geopy supports 3.7+; and because the leading .*? scans every position, the match is inherently O(n²) regardless — so bounding the length is the reliable mitigation.

The limit (256) is a generous ~5× the longest realistic coordinate string; happy to adjust it, or add a changelog entry, if you prefer.

Verification

  • Added test_point_from_string_rejects_overlong_input: a 100 000‑char adversarial string must raise ValueError in well under a second (it takes tens of seconds on master — the bound has a huge margin, so it isn't timing‑sensitive).
  • Full test/test_point.py passes (27); all documented from_string examples (including the UT:‑prefixed one) still parse; flake8 and isort clean.

Disclosure: prepared with AI assistance; reviewed and verified locally.

apoorvdarshan and others added 2 commits July 8, 2026 21:33
POINT_PATTERN begins with '.*?' (to allow a coordinate embedded after some
leading text) and matches whitespace in several overlapping places. On a long
non-matching input such as '<' + ' ' * 3000 + 'X' this backtracks
quadratically (CWE-1333): ~0.2s for 3 KB, growing with input size, so an
endpoint that passes user input to geopy.Point() can be tied up with modest
request volume.

A valid coordinate string is short, so cap the input length before matching
and reject longer strings with the usual ValueError. Atomic groups / possessive
quantifiers would help but require Python 3.11+, while geopy supports 3.7+.

Fixes geopy#608.

@KostyaEsmukov KostyaEsmukov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Regular Expression Denial of Service (ReDoS) in geopy.Point

2 participants