-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The handler reads its own input twice\n\nRead the pre-patch `/api/extensions/delete` handler from `src/endpoints/extensions.js` at SillyTavern 1.17.0:\n\n```javascript\nrouter.post('/delete', async (request, response) => {\n if (!request.body.extensionName) {\n return response.status(400).send('Bad Request: extensionName is required in the request body.');\n }\n\n try {\n const { extensionName, global } = request.body;\n\n if (global && !request.user.profile.admin) {\n console.error(`User ${request.user.profile.handle} does not have permission to delete global extensions.`);\n return response.status(403).send('Forbidden: No permission to delete global extensions.');\n }\n\n const basePath = global ? PUBLIC_DIRECTORIES.globalExtensions : request.user.directories.extensions;\n const extensionPath = path.join(basePath, sanitize(extensionName));\n\n if (!fs.existsSync(extensionPath)) {\n return response.status(404).send(`Directory does not exist at ${extensionPath}`);\n }\n\n await fs.promises.rm(extensionPath, { recursive: true });\n // ...\n```\n\nThe handler reads `extensionName` twice. The first read is the gate on line 2: it asks \"is the field present and truthy?\" The second read is the action on line 14: it asks \"what filename does this string become after `sanitize-filename` runs?\" Nothing about the value changes between those two reads. The gate ran against the raw request body, and the action runs against the same string. They produce different answers for `\".\"` because they ask different questions about it. `\".\"` is truthy, so the gate passes. `sanitize(\".\")` is `\"\"`, so the action joins against the empty string. CVE-2026-44650 is in the gap between those two answers.\n\n## `sanitize-filename` does exactly what it documents\n\n`sanitize-filename@1.6.4`, the package SillyTavern depends on, is four regexes and a truncation. The substantive body of `sanitize()`:\n\n```javascript\nvar illegalRe = /[\\/\\?<>\\\\:\\*\\|\"]/g;\nvar controlRe = /[\\x00-\\x1f\\x80-\\x9f]/g;\nvar reservedRe = /^\\.+$/;\nvar windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\\..*)?$/i;\n\nfunction sanitize(input, replacement) {\n if (typeof input !== 'string') {\n throw new Error('Input must be string');\n }\n var sanitized = input\n .replace(illegalRe, replacement)\n .replace(controlRe, replacement)\n .replace(reservedRe, replacement)\n .replace(windowsReservedRe, replacement);\n sanitized = replaceTrailingDotsAndSpaces(sanitized, replacement);\n return truncate(sanitized, 255);\n}\n```\n\nThe header comment on the file enumerates the cases the regexes implement. `reservedRe` carries the inline label \"Reserved filenames on Unix-based systems (`.`, `..`)\". When `sanitize` is called with the default empty-string replacement, the match against that regex is replaced with nothing. `sanitize('.')` returns `''`. `sanitize('..')` returns `''`. `sanitize('...')` returns `''`. The package's test suite asserts each of these returns.\n\nThis is not undocumented behavior. It is the documented behavior of the package SillyTavern imports to produce a safe path segment. The package's promise is that whatever it returns is a string that can safely be used as a filename component. For inputs that are reserved filenames on Unix, the safe component is the empty string, because there is no character `sanitize-filename` can substitute that would produce a useful filename out of `.`. The package told its caller exactly what it would do.\n\n## `path.join(base, '')` is `base`\n\nNode's `path.join` documents what it does with empty segments:\n\n> Zero-length path segments are ignored. If the joined path string is a zero-length string then `'.'` will be returned, representing the current working directory.\n\nThe first sentence carries the load. `path.join('/data/default-user/extensions', '')` ignores the empty second argument and returns `'/data/default-user/extensions'`. Not a subdirectory. Not a sibling. The parent itself. There is no signal to the caller that the resulting path is shorter than they intended.\n\n## The chain\n\nStack the three documented behaviors in the order the handler runs them, with `request.body.extensionName = \".\"`:\n\n1. `if (!request.body.extensionName)`. `\".\"` is truthy, the gate passes.\n2. `sanitize(\".\")` matches `reservedRe = /^\\.+$/`, gets replaced with `\"\"`, returns `\"\"`.\n3. `path.join(basePath, \"\")` ignores the empty segment, returns `basePath`.\n4. `fs.existsSync(basePath)` finds the extensions directory, returns `true`.\n5. `fs.promises.rm(basePath, { recursive: true })` recursively removes the user's entire extensions directory.\n\nEvery step is doing its documented job. The composition is what the handler got wrong.\n\nThe advisory ships a browser-console PoC that is six lines:\n\n```javascript\nfetch('/api/extensions/delete', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-CSRF-Token': document.querySelector('meta[name=\"csrf-token\"]').content,\n },\n body: JSON.stringify({ extensionName: '.' }),\n});\n```\n\nStatus 200. Response body: `Extension has been deleted at data/default-user/extensions`. The directory and everything under it is gone.\n\n## The default SillyTavern user is admin with no password\n\nThe advisory frames the vulnerability as exploitable by unauthenticated attackers. The runtime path is more specific than that. `src/server-main.js` mounts `setUserDataMiddleware` on every request, which checks the `ENABLE_ACCOUNTS` flag first:\n\n```javascript\nexport async function setUserDataMiddleware(request, response, next) {\n // If user accounts are disabled, use the default user\n if (!ENABLE_ACCOUNTS) {\n const handle = DEFAULT_USER.handle;\n const directories = getUserDirectories(handle);\n request.user = {\n profile: DEFAULT_USER,\n directories: directories,\n };\n return next();\n }\n // ...\n}\n```\n\nWhen accounts are off (the shipped default), every request gets `DEFAULT_USER` attached. The constant is declared in `src/constants.js`:\n\n```javascript\nexport const DEFAULT_USER = Object.freeze({\n handle: 'default-user',\n name: 'User',\n created: Date.now(),\n password: '',\n admin: true,\n enabled: true,\n salt: '',\n});\n```\n\n`admin: true`. `password: ''`. `requireLoginMiddleware` is satisfied because `request.user` is attached on every request. The `if (global && !request.user.profile.admin)` branch inside the delete handler is satisfied because the default user is admin. Both the per-user extensions directory and the global third-party extensions directory are reachable from the same payload by toggling `global: true`.\n\nCSRF protection is on by default and enforced via `csrf-csrf` in the same middleware chain, so the browser-console PoC's `X-CSRF-Token` lookup is not decorative. The advisory's \"unauthenticated\" wording is true in the sense that no password is involved; the in-browser request still has to clear the same-origin token. The exploitation paths that close that distance are an extension or character renderer that runs JavaScript inside the SillyTavern page, an operator who runs the PoC in their own dev console without reading it, or any deployment that ran SillyTavern with `--disableCsrfProtection`, which the project's own startup banner warns about but does not refuse to honour.\n\n## Six handlers in this file have the same gate\n\nThe patch is one half of commit [5512473b](https://github.com/SillyTavern/SillyTavern/commit/5512473b294f60982bc5ef6252977cadec590690), shipped in SillyTavern 1.18.0 under the title \"Extension management improvements.\" The substantive security fix is identical across six handlers in the same file:\n\n```diff\n- if (!request.body.extensionName) {\n- return response.status(400).send('Bad Request: extensionName is required in the request body.');\n- }\n-\n- try {\n- const { extensionName, global } = request.body;\n+ try {\n+ if (typeof request.body.extensionName !== 'string') {\n+ return response.status(400).send('Bad Request: A valid extensionName is required in the request body.');\n+ }\n+\n+ const { extensionName, global } = request.body;\n+ const extensionNameSanitized = sanitize(extensionName);\n+ if (!extensionNameSanitized) {\n+ return response.status(400).send('Bad Request: A valid extensionName is required in the request body.');\n+ }\n // ...\n- const extensionPath = path.join(basePath, sanitize(extensionName));\n+ const extensionPath = path.join(basePath, extensionNameSanitized);\n```\n\n`/update`, `/branches`, `/switch`, `/move`, `/version`, and `/delete` all carried the same gate-then-sanitize shape. The bug class is not specific to `/delete`; the file repeats it six times. `/delete` is the handler with the catastrophic sink, because `fs.promises.rm` does not care whether its target is a git repository, a user-owned subdirectory, or the parent of every extension on disk. The other five handlers feed `extensionPath` to `simpleGit({ baseDir: extensionPath, ... })`, which throws when the directory is not a repository root. That throw is not a security property. It is an accident that `simpleGit` validates its working directory and `fs.rm` does not.\n\nThe patched handler reorders the same two operations. Sanitize first. Check truthy second. The check now reads the value the action will read. The two reads no longer disagree because they are the same read.\n\n## This is [gate-before-canonicalize](/patterns/gate-before-canonicalize), compressed onto one source line\n\nCVE-2026-44650 is the simplest possible exhibit of the [gate-before-canonicalize](/patterns/gate-before-canonicalize) pattern. The prior exhibits have already laid the pattern across multi-layer stacks: Gotenberg's case-sensitive regex against a scheme Go's `net/url.Parse` lowercases, Alfresco's `..` regex against a URL Tomcat resolves `..;/` from, s3-proxy's encoded auth path against its decoded handler path. The pattern's class signature is \"any defense that string-inspects an input the next layer is going to canonicalize.\" The SillyTavern case is that signature minus the layers: the gate and the canonicalizer execute in the same handler, separated by four lines of source. The truthy check is the gate. `sanitize-filename` is the canonicalizer. The canonicalizer produces the empty string, which is the form the gate would have rejected if the gate had run on the same value.\n\nThe closest cousin is [CVE-2025-6218 in WinRAR](/posts/winrar-cve-2025-6218-sanitizer-produced-the-traversal), where `file_name_check` held both the path-traversal discrimination logic and the trailing-whitespace canonicalisation, and the deletion produced the traversal the discrimination was supposed to block. The same dynamic, compressed onto a single function. SillyTavern compresses it further: the canonicalisation is a third-party library call, the gate is a one-line truthy check, and the destruction is `fs.promises.rm` recursive. There is no two-parser disagreement and no timing window. There is one string, two reads of it in the same handler, and a sanitizer call between them that turned the first read's answer into the form the action would treat as \"the whole directory.\"\n\nThe pattern's prescription is the same in every exhibit. Canonicalize before checking. The patch applies it.\n\n## What is in the directory that gets deleted\n\n`request.user.directories.extensions` resolves to `data/default-user/extensions` for the default user; this is where every extension the user has installed via the in-app installer lives, each as its own git clone. Per-extension persisted state lives inside those subdirectories, on a per-extension convention rather than a SillyTavern-managed schema. Vector Storage's embeddings, the chat-completion preset extensions' configurations, and any custom extension a user wrote themselves and didn't push to a remote all live inside the directory that `{\"extensionName\": \".\"}` removes. `data/backups` does not include the extensions directory.\n\nThe recursive delete fires from one HTTP request the user's own browser is allowed to make.\n\nPoC: [GHSA-886q-f44j-h6wh](https://github.com/advisories/GHSA-886q-f44j-h6wh)","closing_line":"The gate read `extensionName`. The action read `sanitize(extensionName)`. The patch is the same call sequence in the opposite order.","hook_md":"CVE-2026-44650 is one POST to `/api/extensions/delete` with the body `{\"extensionName\": \".\"}`. The handler's gate is `if (!request.body.extensionName)`. A single dot is truthy, so the gate passes. The handler's action four lines later is `path.join(basePath, sanitize(extensionName))`. `sanitize('.')` is the empty string. `path.join(basePath, '')` is `basePath`. `fs.promises.rm(basePath, { recursive: true })` then erases the user's entire extensions directory.\nThe gate read `extensionName`. The action read `sanitize(extensionName)`. The patch is the same call sequence in the opposite order.","post_id":367,"slug":"sillytavern-cve-2026-44650-gate-ran-before-sanitize","title":"CVE-2026-44650: SillyTavern's Delete Gate Ran Before sanitize-filename Did","type":"initial","unreadable_sentence":"`sanitize('.')` returns the empty string by documented behavior. `path.join(basePath, '')` returns `basePath` by documented behavior. CVE-2026-44650 lives between two documented behaviors that nobody composed."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaklAzQAKCRDeZjl4jgkQ JvVxAQDnQogpU7ASVrCGyl7O5WykKak2mp7NLPG2pqbURn6xUgEArTbVokpLMPFn eOebM3kG4yXT2qL3STOiOpHRSTiNvgY= =1NE2 -----END PGP SIGNATURE-----