When I first deployed EmDash on my self-hosted server behind Nginx reverse proxy, everything seemed to work — until I tried to publish a post through the admin UI. This is the story of debugging the issue, filing GitHub Issue #348, and seeing it resolved through two official PRs across four version upgrades.
The Setup
I run EmDash on a Tencent Cloud Lighthouse server (OpenCloudOS 9) with the following stack:
- Nginx reverse proxy with Let's Encrypt HTTPS
- EmDash v0.1.0 running in Astro dev mode on localhost:4321
- PM2 process manager
- Domain: data.vizwise.cn
The Bug
After completing the admin setup wizard and registering a passkey, I could log in successfully and create new posts. But when I clicked Publish, nothing happened — no visible error, no console output. The post would only save as a draft.
The puzzling part: publishing via the REST API worked perfectly.
POST /_emdash/api/content/posts/{id}/publish
Authorization: Bearer ec_pat_xxxx
200 OK ✓
Manual publish via Admin UI: broken ✗
Debugging Process
1. Initial Suspicion: Passkey / WebAuthn Origin
Since passkey login worked but publishing failed, I first suspected a CSRF issue. EmDash uses WebAuthn and the browser's navigator.credentials.get() API strictly validates origins. Behind a reverse proxy, the browser sees https://data.vizwise.cn but Node.js sees http://localhost:4321. I had already patched passkey-config.ts to make passkey registration work, but the publish button still failed silently.
2. CSRF Headers Investigation
The publish button triggers a POST to /_emdash/api/content/posts/{id}/publish with a custom header X-EmDash-Request. The server's CSRF middleware checks this against the request origin. The mismatch between the browser's Origin: https://data.vizwise.cn and the server's self-perceived http://localhost:4321 caused the CSRF check to silently reject the request.
3. Why Did the API Token Work?
The REST API uses Bearer token authentication, which bypasses CSRF checks entirely. That's why external API calls could publish while the browser admin UI could not.
Root Cause: The Origin Mismatch Problem
EmDash, running behind a TLS-terminating reverse proxy, had no way to know its public origin. Every subsystem comparing url.origin (which resolved to http://localhost:4321) against the browser-visible origin (https://data.vizwise.cn) was affected.
As identified in Discussion #315 by UpperM, the origin mismatch affected at least 31 call sites:
- Passkey / WebAuthn registration and verification
- CSRF checks for admin POST requests
- Auth redirect URLs
- Setup wizard (stored internal origin as site_url)
- OAuth consumer redirects, MCP/CLI discovery, sitemap, robots.txt, JSON-LD, and more
The Fix Journey
PR #382: siteUrl — Merged April 11, 2026 (v0.7.0)
Introduced a unified siteUrl config option telling EmDash its public-facing URL. A utility function getPublicOrigin() wraps all affected url.origin calls, preserving backward compatibility when not set.
⚠ Breaking: passkeyPublicOrigin → siteUrl
PR #800: Multiple-Origin Passkey Verification — Merged April 29, 2026 (v0.8.0)
Extended passkey verification to accept multiple valid origins via allowedOrigins, handling scenarios where the server sees different origins at different pipeline stages behind a proxy.
⚠ Breaking: trustedProxyHeaders object → array format
// v0.7.0 (object)
trustedProxyHeaders: {
xRealIP: true,
xForwardedFor: true,
xForwardedProto: true
}
// v0.8.0 (array)
trustedProxyHeaders: [
"x-real-ip",
"x-forwarded-for",
"x-forwarded-proto"
]
Working Configuration (v0.8.0)
After upgrading through the versions, here is the final working configuration:
// astro.config.mjs
import emdash from "emdash";
export default defineConfig({
integrations: [
emdash({
siteUrl: "https://data.vizwise.cn",
trustedProxyHeaders: [
"x-real-ip",
"x-forwarded-for",
"x-forwarded-proto"
]
})
]
});
# Nginx (unchanged)
server {
listen 443 ssl;
server_name data.vizwise.cn;
location / {
proxy_pass http://127.0.0.1:4321;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://localhost:4321/ https://data.vizwise.cn/;
}
}
Key points:
- Must run in
productionmode. Dev mode does not trust proxy headers. proxy_redirectin Nginx prevents admin login redirects to localhost.- PM2 with
ecosystem.config.cjsandORIGIN=https://data.vizwise.cn
Issue Timeline
- Apr 7: Issue #348 opened — manual publish broken on v0.1.0 behind Nginx
- Apr 8: UpperM linked to Discussion #315 — confirmed origin mismatch
- Apr 9: Workaround found: save as draft, then publish via REST API
- Apr 11: PR #382 merged —
siteUrlintroduced - Apr 25: Upgraded to v0.7.0
- Apr 29: PR #800 merged; Issue #348 closed by @ascorbic
- Apr 29: Upgraded to v0.8.0 with array-format
trustedProxyHeaders - Apr 30: Confirmed fully resolved ✓
Lessons Learned
- Diagnose before fixing: Using
curl -v | grep locationquickly revealed redirect issues without changing any code. - Fix at the right layer: Proxy redirects (Nginx
proxy_redirect) and app origin handling (siteUrl) are separate concerns. - Production mode matters: Dev mode does not trust proxy headers. Always use production mode behind a reverse proxy.
- Watch for silent breakages: When CSRF fails silently, the admin panel feels broken with no indication why.
- API tokens are an escape hatch: REST API publishing kept the workflow alive while waiting for the fix.
Conclusion
The EmDash team's response was excellent. Within a month, two comprehensive PRs (#382 and #800) addressed not just the specific publish issue, but the entire class of reverse-proxy origin mismatch problems.
If you're self-hosting behind a reverse proxy, ensure you:
- Are on v0.8.0 or later
- Configure
siteUrlto your public HTTPS domain - Set
trustedProxyHeadersas an array - Run in production mode
Issue #348 is now closed. Manual publish works. ✌
References
- Issue #348 — CANNOT publish post or page manually
- Discussion #315 — siteUrl: fix origin mismatch behind a reverse proxy
- PR #382 — siteUrl implementation
- PR #800 — Multiple-origin passkey verification