Skip to content

Warn when a new origin block silently steals the default vhost - #8

Merged
ralyodio merged 1 commit into
mainfrom
warn-default-vhost
Aug 1, 2026
Merged

Warn when a new origin block silently steals the default vhost#8
ralyodio merged 1 commit into
mainfrom
warn-default-vhost

Conversation

@ralyodio

@ralyodio ralyodio commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The second thing the first live run of setup-origin.sh got wrong — and unlike the reload race in #7, this one actually broke a working site.

What happened

nginx picks the first-parsed server block for a listen address as the default when nothing is marked default_server, and sites-enabled is parsed in filename order. chovy.hacker sorts ahead of userdirs.conf, so adding it made it the default vhost for :443 on a box that had never declared one.

Every request with no SNI, or with a Host matching no server_name, then got a self-signed certificate for a Moshpit name instead of the box's real Let's Encrypt cert:

$ openssl s_client -connect <box>:443 -noservername
subject=CN=chovy.hacker          ← was CN=dev.profullstack.com

The nasty part is how it presents: the name you just added works fine, and the other, untouched sites appear to break. Nothing in the script's output suggested it had touched them.

The fix

Ask the loaded config whether anything claims default_server for 443, and say plainly what to do if not:

warning: no server block on this box marks itself `default_server` for 443.
warning: adding chovy.hacker may have taken over as the default vhost, so requests
warning: with no SNI or an unmatched Host now get its self-signed certificate.
warning: fix by marking the intended default, e.g. `listen 443 ssl default_server;`

Deliberately not fixed automatically. The remedy is to edit a server block belonging to some other site, and a script that adds one name should not reach into unrelated config to do it unasked.

Verified

On the box it happened to. Marking the pre-existing block restored correct behaviour:

SNI before fix after fix
(none) CN=chovy.hacker CN=dev.profullstack.com
dev.profullstack.com CN=dev.profullstack.com CN=dev.profullstack.com
chovy.hacker CN=chovy.hacker CN=chovy.hacker

https://dev.profullstack.com/~anthony/ back to 200. sh -n clean.

🤖 Generated with Claude Code

Second thing the first live run got wrong, and this one broke a working site
rather than just misreporting.

nginx picks the first-parsed server block for a listen address as the default
when nothing is marked `default_server`, and sites-enabled is parsed in
filename order. `chovy.hacker` sorts ahead of `userdirs.conf`, so adding it
made it the default vhost for 443 on a box that had never declared one. Every
request with no SNI or an unmatched Host then got a self-signed certificate
for a Moshpit name instead of the box's real one -- which presents as the
*other*, untouched sites breaking.

Detected by asking the loaded config whether anything claims default_server
for 443, and saying plainly what to do if not. Not fixed automatically: the
remedy is to edit somebody else's server block, and this script should not
reach into unrelated config to do that unasked.

Verified on the box it happened to: marking the pre-existing block restored
the correct certificate for no-SNI and unmatched hosts, with chovy.hacker
still answering with its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

@ralyodio
ralyodio marked this pull request as ready for review August 1, 2026 18:32
@ralyodio
ralyodio merged commit 746851f into main Aug 1, 2026
3 checks passed
@ralyodio
ralyodio deleted the warn-default-vhost branch August 1, 2026 18:45
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.

1 participant