Skip to content

fix valid_url?/1 backtracking that accepted invalid trailing TLDs#17

Merged
jaimeiniesta merged 1 commit into
masterfrom
fix-14
May 4, 2026
Merged

fix valid_url?/1 backtracking that accepted invalid trailing TLDs#17
jaimeiniesta merged 1 commit into
masterfrom
fix-14

Conversation

@jaimeiniesta

Copy link
Copy Markdown
Owner

The trailing \/?.* in @url_regexp let .* swallow leftover characters as a path, so URLs like https://example.com.ñ and https://example.abcdef matched via TLD backtracking. Restrict the path part to start with /, ?, or # so no domain-label leftovers can be absorbed.

Fixes #14

The trailing `\/?.*` in @url_regexp let `.*` swallow leftover characters
as a path, so URLs like `https://example.com.ñ` and `https://example.abcdef`
matched via TLD backtracking. Restrict the path part to start with `/`,
`?`, or `#` so no domain-label leftovers can be absorbed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens Funkspector.Utils.valid_url?/1 so trailing characters after the TLD can no longer be backtracked into the old catch-all path suffix. It fits into the codebase by improving the URL gatekeeper used before loading or resolving documents.

Changes:

  • Updated the URL validation regex to require any optional suffix to start with /, ?, or #.
  • Added regression tests for invalid URLs like https://example.com.ñ and https://example.abcdef.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/funkspector/utils.ex Narrows the regex used by valid_url?/1 to block the reported trailing-TLD backtracking case.
test/utils_test.exs Adds regression coverage for invalid trailing segments after otherwise valid-looking domains.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/funkspector/utils.ex
@jaimeiniesta
jaimeiniesta merged commit b947485 into master May 4, 2026
18 checks passed
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.

valid_url?/1 accepts URLs with invalid TLDs due to regex backtracking

2 participants