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

Skip to content

Fix wildcard redirect URI validation for Netlify double-dash deploy previews - #1750

Merged
dopry merged 3 commits into
django-oauth:masterfrom
apoorvdarshan:fix-1619-netlify-wildcard-double-dash
Jul 23, 2026
Merged

Fix wildcard redirect URI validation for Netlify double-dash deploy previews#1750
dopry merged 3 commits into
django-oauth:masterfrom
apoorvdarshan:fix-1619-netlify-wildcard-double-dash

Conversation

@apoorvdarshan

Copy link
Copy Markdown
Contributor

Fixes #1619.

Description of the Change

Wildcard redirect_uris for Netlify deploy previews were rejected by the application form / admin validator, even though the underlying authorization flow accepts them at runtime.

Netlify deploy-preview hostnames use a double dash, e.g. deploy-preview-42--sitename.netlify.app or 1234abcd--sitename.netlify.app. The natural wildcard for these is https://*--sitename.netlify.app. (As the reporter notes, a single-dash pattern like https://*-sitename.netlify.app would be too broad and could match unrelated something-sitename.netlify.app hosts, so the double dash is the correct, safe pattern.)

In oauth2_provider/validators.py, after stripping the leading *, the validator stripped only one leading hyphen:

if netloc.startswith("-"):
    netloc = netloc[1:]

For *--sitename.netlify.app this leaves -sitename.netlify.app, which begins with a hyphen and is rejected by Django's URIValidator ("Enter a valid URL."). This made the affected Application un-editable in the Django admin, since every save failed validation.

Fix

Strip all leading hyphens after the wildcard:

netloc = netloc.lstrip("-")

This accepts the double-dash Netlify form while leaving all previously-valid patterns unchanged. It does not over-broaden validation: bare wildcards, TLD/SLD-only wildcards (*.com, *-partial.com), all-hyphen labels (*--.com), multiple wildcards, and non-leading wildcards are all still rejected downstream by URIValidator, because only the leading hyphens (not the required domain labels) are removed.

Tests

Added https://*--sitename.netlify.app to the good_uris list in tests/test_validators.py::TestAllowedURIValidator::test_allow_hostname_wildcard. The test fails on master (the URI is rejected) and passes with the fix. The existing bad-URI assertions continue to pass, confirming no regression in what the validator rejects.

  • PR only contains one change
  • unit-test added
  • CHANGELOG.md updated
  • author name in AUTHORS

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes validation of wildcard redirect_uris that target Netlify deploy preview hostnames using a double dash (e.g. https://*--sitename.netlify.app), aligning form/admin validation with runtime wildcard support.

Changes:

  • Update AllowedURIValidator to strip all leading hyphens after removing a leading hostname * wildcard (fixing *--... cases).
  • Add unit test coverage for the Netlify double-dash wildcard hostname pattern.
  • Document the fix in CHANGELOG.md and add the author to AUTHORS.

Reviewed changes

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

File Description
oauth2_provider/validators.py Adjusts wildcard-hostname normalization to handle multiple leading hyphens after *.
tests/test_validators.py Adds a regression test for Netlify deploy-preview double-dash wildcard redirect URIs.
CHANGELOG.md Notes the Netlify wildcard redirect URI validation fix under “Fixed”.
AUTHORS Adds the contributor name.

Comment thread oauth2_provider/validators.py Outdated

@dopry dopry 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.

@apoorvdarshan thanks for this looks great. A few items to address,

  1. Add runtime-matching tests in tests/test_models.py, not just the validator test:
# valid_wildcard_redirect_to_params (line 1103)
("https://deploy-preview-42--sitename.netlify.app", ["https://*--sitename.netlify.app"]),
# invalid_wildcard_redirect_to_params (line 1117)
("https://x-sitename.netlify.app",      ["https://*--sitename.netlify.app"]),
("https://evil--othersite.netlify.app", ["https://*--sitename.netlify.app"]),
  1. Document the double-dash form in docs/settings.rst (ALLOW_URI_WILDCARDS, lines 76–84): add https://*--sitename.netlify.app as allowed, and note single-dash *-sitename.netlify.app is unsafe.
  2. lstrip("-") also accepts *---slug…; slightly broader than the comment's "double dash",

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dopry

dopry commented Jul 23, 2026

Copy link
Copy Markdown
Member

@apoorvdarshan do you have time to follow up and complete this PR?

Copilot AI review requested due to automatic review settings July 23, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread oauth2_provider/validators.py
Netlify deploy-preview redirect URIs use a double dash, e.g.
https://*--sitename.netlify.app (matching deploy-preview-42--sitename.
netlify.app). After removing the '*' wildcard the validator stripped only
a single leading hyphen, leaving a hostname starting with '-' that
Django's URIValidator rejects. Strip all leading hyphens so these hosts
validate, and add a regression test.

Fixes django-oauth#1619.
Copilot AI review requested due to automatic review settings July 23, 2026 22:29
@dopry
dopry force-pushed the fix-1619-netlify-wildcard-double-dash branch from 2504799 to d3f5f88 Compare July 23, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread docs/settings.rst Outdated
The settings docs listed https://*.sub.example.com as "not allowed", but the
validator accepts it (wildcard at the start, extra subdomain label, SLD/TLD
intact) — consistent with the stated rule that the wildcard only cannot be in
the top or second level domain. Flip the example to allowed and keep the two
genuinely-rejected examples (*.com, example.*.com).

Addresses Copilot review comment r3641805539.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y2KLHQubcBjXwc39fbgL8S
Copilot AI review requested due to automatic review settings July 23, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

oauth2_provider/validators.py:121

  • The PR description still states the fix is netloc = netloc.lstrip("-") / “strip all leading hyphens”, but the implementation intentionally strips up to two leading hyphens (rejecting longer runs like *---..., which is also now covered by a test). Please update the PR body’s “Fix” section to match the actual behavior/guarantees so future reviewers aren’t misled.
            # Domains cannot start with a hyphen, but can have them in the middle, so strip up to two
            # hyphens after the wildcard. This supports Netlify deploy previews
            # (e.g. *--sitename.netlify.app) while leaving longer runs for URIValidator to reject.
            if netloc.startswith("--"):
                netloc = netloc[2:]
            elif netloc.startswith("-"):

@dopry
dopry merged commit 82fc862 into django-oauth:master Jul 23, 2026
39 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.

Wildcard redirect URIs don't work with Netlify

4 participants