uploadthing/unauthenticated-file-router
UploadThing route has no auth in `.middleware()`
npx @pitcheye/check . --pack webhookswhyItBreaks
UploadThing endpoints are public: `.middleware()` is the only place a caller is identified, and an empty one lets anyone on the internet mint upload URLs against your app key and storage quota. The same hole appears on the read side when a mutation accepts any URL — an operator can attach a phishing link or third-party host as a licence document.
f({ pdf: {} }).middleware(async () => ({ uploadedAt: Date.now() }))f({ pdf: {} }).middleware(async () => {
const { userId } = await auth();
if (!userId) throw new UploadThingError("Unauthorized");
return { userId };
})suggestedFix
Resolve the caller in `.middleware()` (`const { userId } = await auth()`, throw `UploadThingError` when absent) and return `{ userId }` so `onUploadComplete` can scope the row. For URL fields, replace `z.string().url()` with a schema that checks the hostname against `utfs.io` / `*.ufs.sh`.
explain_rule({"uploadthing/unauthenticated-file-router"})Agent & MCP JSON output contract
{
"ruleId": "uploadthing/unauthenticated-file-router",
"pack": "webhooks",
"severity": "error",
"file": "apps/web/src/app/api/uploadthing/core.ts",
"line": 6,
"message": "a file-route `.middleware(async () => …)` with no `auth()` call, or a bare `z.string().url()` for a document/image field",
"whyItBreaks": "UploadThing endpoints are public: `.middleware()` is the only place a caller is identified, and an empty one lets anyone on the internet mint upload URLs against your app key and storage quota. The same hole appears on the read side when a mutation accepts any URL — an operator can attach a phishing link or third-party host as a licence document.",
"suggestedFix": "Resolve the caller in `.middleware()` (`const { userId } = await auth()`, throw `UploadThingError` when absent) and return `{ userId }` so `onUploadComplete` can scope the row. For URL fields, replace `z.string().url()` with a schema that checks the hostname against `utfs.io` / `*.ufs.sh`.",
"docsUrl": "https://pitcheye.dev/rules/uploadthing-unauthenticated-file-router"
}Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/uploadthing-unauthenticated-file-router
raw markdown
# uploadthing/unauthenticated-file-router
- **severity:** error
- **pack:** webhooks
- **docs:** https://pitcheye.dev/rules/uploadthing-unauthenticated-file-router
## whyItBreaks
UploadThing endpoints are public: `.middleware()` is the only place a caller is identified, and an empty one lets anyone on the internet mint upload URLs against your app key and storage quota. The same hole appears on the read side when a mutation accepts any URL — an operator can attach a phishing link or third-party host as a licence document.
## bad
```ts
f({ pdf: {} }).middleware(async () => ({ uploadedAt: Date.now() }))
```
## good
```ts
f({ pdf: {} }).middleware(async () => {
const { userId } = await auth();
if (!userId) throw new UploadThingError("Unauthorized");
return { userId };
})
```
## suggestedFix
Resolve the caller in `.middleware()` (`const { userId } = await auth()`, throw `UploadThingError` when absent) and return `{ userId }` so `onUploadComplete` can scope the row. For URL fields, replace `z.string().url()` with a schema that checks the hostname against `utfs.io` / `*.ufs.sh`.
## commands
```bash
npx @pitcheye/check . --pack webhooks
```
```json
{"tool":"explain_rule","arguments":{"ruleId":"uploadthing/unauthenticated-file-router"}}
```