mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-04 05:30:18 +01:00
Behind Caddy a Next.js app never sees its own public URL, so next-auth builds sign-in and callback URLs from the INTERNAL origin unless NEXTAUTH_URL (v4) or AUTH_URL (v5) is pinned in the box env. AUTH_TRUST_HOST=true does NOT cover this path, which is exactly what makes a broken app look configured. Nothing 500s when it happens. The site renders, and only Google sign-in and sign-out are impossible. petvity shipped this, fixed it in petvity#39 around 2026-08-14 with a per-app assertion supposedly added — and on 2026-09-10 was serving https://localhost:4013/api/auth/callback/google again. The regression stated itself in public JSON for weeks and nothing read it. next-auth publishes GET /api/auth/providers unauthenticated, and every entry carries the app's configured origin, so the detector needs no secret, no login and no box access: fetch it per site, fail if any signinUrl/callbackUrl origin is not the origin that served the JSON. 404 is a site without next-auth and SKIPs; 5xx FAILs, because an auth stack that cannot answer is broken too and reading "no data" as "no problem" is how this check would certify a dead auth. Sites come from fleetcrown's footer, the same SSOT ui-defect-audit.mjs reads, so this adds no second app list and no exclusion list — a repo that is not a deployment is absent by construction. Self-tested from captured payloads, both sides pinned: the real localhost regression is caught, the real repaired payload stays silent. The self-test runs in this repo's CI and again before each scheduled sweep, because a detector that has quietly stopped detecting prints a ✓ over a broken fleet. Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
88 lines
3.6 KiB
YAML
88 lines
3.6 KiB
YAML
# next-auth origin guard — a fix that can silently revert is not a fix.
|
|
#
|
|
# Behind Caddy a Next.js app never sees its own public URL, so next-auth
|
|
# resolves relative redirects against the INTERNAL origin unless NEXTAUTH_URL
|
|
# (v4) / AUTH_URL (v5) is pinned in the box env. AUTH_TRUST_HOST=true does NOT
|
|
# cover this path — which is what makes a broken app look configured.
|
|
#
|
|
# petvity shipped exactly that, it was fixed in petvity#39 (~2026-08-14), and
|
|
# on 2026-09-10 petvity was again advertising
|
|
# https://localhost:4013/api/auth/callback/google in production: Google
|
|
# sign-in impossible, sign-out landing on a dead page. The regression sat in
|
|
# public JSON for weeks and nothing looked. This is the thing that looks.
|
|
#
|
|
# Daily, unauthenticated, no secrets, no quota: next-auth publishes
|
|
# /api/auth/providers, and every entry carries the app's CONFIGURED origin.
|
|
# Any failure pings Telegram via the org-wide alert bot.
|
|
name: next-auth origin
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "34 6 * * *" # daily, 06:34 UTC (off the :00 GH cron rush)
|
|
workflow_dispatch:
|
|
inputs:
|
|
sites:
|
|
description: "Comma-separated URLs (default: discovered from the fleet footer)"
|
|
type: string
|
|
default: ""
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
audit:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
|
|
- uses: actions/setup-node@v7
|
|
with:
|
|
node-version: 22
|
|
|
|
# BEFORE the sweep, deliberately. A detector that has quietly stopped
|
|
# detecting reports a clean fleet, and a ✓ from a dead check is worse
|
|
# than no check — it is precisely how the first petvity fix "held" for
|
|
# four weeks while being false. Fixtures pin both sides: the real
|
|
# localhost regression is caught, the repaired payload stays silent.
|
|
- name: Self-test the detector
|
|
run: node scripts/ci/test-nextauth-origin-audit.mjs
|
|
|
|
- name: Audit every next-auth app's advertised origin
|
|
env:
|
|
SITES: ${{ inputs.sites }}
|
|
run: |
|
|
set -uo pipefail
|
|
# Report goes to the job summary, not just the log: a finding nobody
|
|
# scrolls to is the same as no finding.
|
|
{
|
|
echo '## next-auth advertised origin'
|
|
echo
|
|
echo '```'
|
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
set +e
|
|
node scripts/ci/nextauth-origin-audit.mjs 2>&1 | tee -a "$GITHUB_STEP_SUMMARY"
|
|
status=${PIPESTATUS[0]}
|
|
set -e
|
|
|
|
echo '```' >> "$GITHUB_STEP_SUMMARY"
|
|
exit "$status"
|
|
|
|
- name: Alert Telegram on failure
|
|
if: failure()
|
|
env:
|
|
TG_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
TG_CHAT: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
run: |
|
|
set -euo pipefail
|
|
# An alert that reaches nobody defeats the workflow's whole purpose:
|
|
# missing secrets or a Telegram 4xx must make THIS step red too, so
|
|
# the broken alert path is itself visible.
|
|
[ -n "$TG_TOKEN" ] && [ -n "$TG_CHAT" ] || { echo "TELEGRAM_* secrets missing — alert undeliverable" >&2; exit 1; }
|
|
curl -sS --fail --max-time 20 "https://api.telegram.org/bot${TG_TOKEN}/sendMessage" \
|
|
-d chat_id="${TG_CHAT}" \
|
|
-d text="🚨 Fleet next-auth ORIGIN guard failed — an app advertises the wrong sign-in/callback origin (OAuth sign-in cannot complete, sign-out lands dead), or its /api/auth/providers is 5xx. Fix: pin NEXTAUTH_URL/AUTH_URL in the app's env on the box and restart. Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
|
|
>/dev/null
|
|
echo "telegram alerted"
|