in reviewhumanPR #317Other

fix(dashboard): stop probing submitted links and bound catalog submissions again

fix(dashboard): stop probing submitted links and bound catalog submissions again

Author

Status
In review
Opened on
Nov 2
Branch
fix/dashboard-catalog-submission-boundary

Description

The pitch.

fix(dashboard): stop probing submitted links and bound catalog submissions again

---

# 1. The dashboard fetches user-submitted URLs again

The restore of the deployed frontend in 1975fb9 brought back the `checkReachable` probe that #253 had removed. On `main` today, `submitSkill` in `apps/nest-dashboard/src/app/skills/actions.ts` fetches whatever URL a visitor types into the form, with `redirect: "follow"`, before saving the entry. Only the URL scheme is validated first.

That is the same boundary as before: a submission can make the server request `http://localhost`, a private address, or the cloud metadata endpoint at `169.254.169.254`, directly or through a redirect. Of the four catalog fixes the restore undid, only the scheme check on the JSON API was re-landed (3cce846).

**Fix:** The probe is deleted and new links are stored with `reachable: null`, exactly as #253 did. The catalog page gets back the three-state badge from #246, so a link that was never checked is shown as "link not checked" instead of the red "couldn't reach link", which asserted a failure that was never observed. Saving is never blocked, and a saved entry is not a claim that the link is live or safe.

## 2. `POST /api/skills` accepts bodies of any size and fields of any length

The same restore dropped the request bound and field limits from #257 (0336b86). The route reads the whole body with `request.json()` and the only check on `content` is a minimum. Against a local `next start` of `main` with no database configured, a 3 MB body and a 100,000-character `name` both passed validation and reached `createSkill` (500 only because there was no database to write to), while `file:///etc/passwd` was refused with 400.

The consequence is the outage mode the code already names. `listSkillsCached` serves the full catalog, including every entry's `content`, from a 30-second cache, and the comment in `src/lib/skills.ts` says serving it uncached "took the site down during the submission rush". Next's fetch cache refuses entries over 2 MB, so one anonymous submission larger than that makes every `/skills` view and every `GET /api/skills` re-read the full catalog from Neon until someone deletes the row by hand. There is no delete endpoint (#203).

**Fix:** The JSON body is read through a streamed 256 KiB bound and refused with 413 past it, before parsing. One validator, `src/lib/skill-submission.ts`, is shared by the API route and the form: it bounds every field (200 characters for `name` and `author`, 254 for `email`, 39 for `github_username`, 2,000 for `description`, 2,048 for `source_url`, 200,000 for `content`, 8,192 for `endpoints`, 512 for `tags`), keeps the syntax-only URL check, and always records `reachable: null`. The form keeps its own wording for each refusal; the API names the field.

## 3. A catalog row and its audit record are written separately

`createSkill` inserts the public `skills` row and then its `skill_history` snapshot as two autocommitted statements. If the second one fails, the public row stays with no audit record, the client gets an error, and its retry creates a duplicate.

**Fix:** The two inserts run in one transaction, in the form 0336b86 used, with the snapshot built from the committed row.

## 4. The dashboard tests and their CI steps

The restore also removed the vitest suite, `vitest.config.mts`, and the `test` and `typecheck` scripts, while `CONTRIBUTING.md` still tells dashboard contributors to run `npm test` and `npm run typecheck`. That is how the fixes above could disappear without a failing check.

**Fix:** vitest is back with three test files that cover exactly the behaviours in this PR (the real route handler, server action and rendered page, with persistence and request context replaced by doubles and any network request failing the test), and the CI dashboard job runs `npm test` and `npm run typecheck` again before the build.

## Scope

Everything here re-lands code the maintainers already merged in #246, #253 and #25

…

Try it

Open PR on GitHubView diff

Checkout locally

git fetch origin pull/317/head:pr-317
git checkout pr-317