Skip to content

fix(blueprints): pick the most specific domain for private resources - #4034

Open
Tyagiquamar wants to merge 1 commit into
fosrl:mainfrom
Tyagiquamar:fix/private-blueprint-most-specific-domain
Open

Tyagiquamar wants to merge 1 commit into
fosrl:mainfrom
Tyagiquamar:fix/private-blueprint-most-specific-domain

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

AI Disclosure

An AI coding agent assisted with locating the cause and writing the change and the test. I reviewed the result and ran the checks below.

Description

Fixes #3878.

When a Docker blueprinted private resource declared a full-domain that matched more than one verified domain, the resource was attached to whichever matching domain the database returned first. With both *.example.com and *.int.example.com verified, a resource for somename.int.example.com could be stored under *.example.com with subdomain set to somename.int instead of under *.int.example.com with subdomain set to somename. The certificate was then tracked against the wrong domain and showed up as failed in the dashboard even though the correct wildcard certificate was being served. Creating the same resource through the UI is unaffected because the domain is selected explicitly there.

The public resource blueprint path (getDomainId in server/lib/blueprints/publicResources.ts) already sorts the matching domains by the length of baseDomain for exactly this case. The private resource path did not.

Technical solution

  • Added server/lib/blueprints/domainSelection.ts with matchesFullDomain (same rules as before: ns and wildcard match their base domain and subdomains, cname matches only the exact base domain) and selectMostSpecificDomain, which picks the longest matching baseDomain.
  • getDomainForSiteResource in server/lib/blueprints/privateResources.ts now selects the domain through selectMostSpecificDomain instead of taking validDomains[0].

With the previous selection the regression test case below resolves to example.com; with the change it resolves to int.example.com.

How to test?

  • New regression test: server/lib/blueprints/domainSelection.test.ts covers a parent domain listed before a nested wildcard (the reported case), an exact base-domain match, a CNAME that only matches its base domain, and a full domain with no matching domain.
  • Add the test file is picked up automatically by npm test / node scripts/run-tests.mjs.

Commands run:

npx tsx server/lib/blueprints/domainSelection.test.ts   # pass
npx tsc --noEmit                                        # pass

On Windows the dependency install used npm ci --ignore-scripts because better-sqlite3 has no win32 prebuild for this Node version; neither tsc nor this test depends on the native module.

A private blueprint resource whose full-domain matched both a parent and a
nested wildcard domain was attached to whichever domain the query returned
first, so somename.int.example.com could be filed under *.example.com with
the subdomain "somename.int". The public resource path already selects the
longest matching base domain; use the same selection for private resources.
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.

Private HTTP resources wildcard certificates show as failed, despite working, when created via docker label blueprint

1 participant