{"record":{"id":"27e3072db74169e8","repo":"sveltejs/kit","slug":"cookies-deleted-in-remote-functions-must-have-an-a","errorCode":null,"errorMessage":"Cookies deleted in remote functions must have an absolute path","messagePattern":"Cookies deleted in remote functions must have an absolute path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/server/remote/shared.js","lineNumber":108,"sourceCode":"\t\t\t...event.cookies,\n\t\t\tset: (name, value, opts) => {\n\t\t\t\tif (!allow_cookies) {\n\t\t\t\t\tthrow new Error('Cannot set cookies in `query` or `prerender` functions');\n\t\t\t\t}\n\n\t\t\t\tif (opts.path && !opts.path.startsWith('/')) {\n\t\t\t\t\tthrow new Error('Cookies set in remote functions must have an absolute path');\n\t\t\t\t}\n\n\t\t\t\treturn event.cookies.set(name, value, opts);\n\t\t\t},\n\t\t\tdelete: (name, opts) => {\n\t\t\t\tif (!allow_cookies) {\n\t\t\t\t\tthrow new Error('Cannot delete cookies in `query` or `prerender` functions');\n\t\t\t\t}\n\n\t\t\t\tif (opts.path && !opts.path.startsWith('/')) {\n\t\t\t\t\tthrow new Error('Cookies deleted in remote functions must have an absolute path');\n\t\t\t\t}\n\n\t\t\t\treturn event.cookies.delete(name, opts);\n\t\t\t}\n\t\t}\n\t};\n\n\tif (state.is_in_remote_query) {\n\t\tfor (const property of ['url', 'params', 'route']) {\n\t\t\t// non-enumerable so spreading for a nested derivation doesn't invoke the getter\n\t\t\tObject.defineProperty(derived, property, {\n\t\t\t\tenumerable: false,\n\t\t\t\tget() {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot access event.${property} in a query. Pass the value as an argument to the query instead`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/server/remote/shared.js#L90-L126","documentation":"Remote functions (`query`, `form`, `command`, `prerender`) allow deleting cookies through the derived event, but the options passed to `cookies.delete` must specify an absolute path (starting with `/`). SvelteKit throws this because a relative path would be ambiguous across remote function invocations. Supply `path: '/'` (or another absolute path) when deleting.","triggerScenarios":"Calling `event.cookies.delete('name', { path: 'sub' })` or any opts.path not beginning with '/' inside a remote `query`/`form`/`command` function (with allow_cookies enabled).","commonSituations":"Copy-pasting cookie deletion code from a `load` function into a remote function; assuming the default relative-path semantics of other cookie APIs; deleting a cookie scoped to a subpath like 'admin' instead of '/admin'.","solutions":["Change the delete options to use an absolute path, e.g. `{ path: '/' }` or `{ path: '/admin' }`","If the cookie was set with a specific path, delete it with exactly that absolute path","If you don't need path scoping, omit nothing and pass `{ path: '/' }` explicitly"],"exampleFix":"// before\nevent.cookies.delete('session', { path: 'account' });\n// after\nevent.cookies.delete('session', { path: '/account' });","handlingStrategy":"validation","validationCode":"function assertAbsolutePath(opts = {}) {\n  if (opts.path && !opts.path.startsWith('/')) {\n    throw new TypeError(`cookie path must be absolute, got: ${opts.path}`);\n  }\n}\n// call before event.cookies.delete(name, opts)","typeGuard":"const hasAbsolutePath = (opts) => !opts?.path || opts.path.startsWith('/');","tryCatchPattern":"try {\n  event.cookies.delete(name, opts);\n} catch (e) {\n  if (e.message.includes('absolute path')) {\n    event.cookies.delete(name, { ...opts, path: '/' });\n  } else throw e;\n}","preventionTips":["Always pass an explicit absolute path when deleting cookies in remote functions","Use the same constant for a cookie's set and delete path","Add a lint rule or helper wrapper that rejects relative cookie paths"],"tags":["cookies","remote-functions","validation"],"backgroundTag":"invalid-cookie-path","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}