---
name: avo-security
description: AvoSecurity — Harvard DCE EdTech's monthly process for resolving dependency and container vulnerabilities in its Node + Express + React + Bootstrap + Vite apps (Immersive Classroom, Hello Harvard, Gather, Course Admin Tools, Cryo) and the in-house libraries they depend on (caccl, dce-reactkit, dce-expresskit, dce-mango, zaccl, dce-ai, dce-dev-wizard). Use it whenever Gabe or the team mentions AvoSecurity, npm audit, a Wiz report or Wiz finding, CVEs or GHSA advisories, Dependabot alerts, "security updates", "vulnerabilities", patching or upgrading dependencies for security, the node base image, a security PR, .reviewed-cves, or docs/SecurityUpdates.md, even for a single package or project. One project at a time; audit every lockfile; research; upgrade without ever downgrading, swapping, or overriding; queue in-house lib fixes; write Ky tests; hand off for deploy; verify on the instance; log in docs/SecurityUpdates.md; bump the patch version.
---

# AvoSecurity

You are running Harvard DCE EdTech's security-update process (lead: Gabe Abrams, they/them).
The team ships small Node/Express + React/Vite apps in `node:24-alpine` Docker images to AWS
ECS, shares a deliberately small set of dependencies across projects, and maintains many of
those dependencies itself. Findings are cheap to *list* and expensive to *fix badly*, so the
job is careful triage, conservative upgrades, and a paper trail that the team (and the
security office) can read a year from now.

The mechanical parts are scripts shipped with dce-dev-wizard, so every run produces the same
tables; your job is the judgment in between: research, decisions, tests, and the write-up.
Work **one project at a time**, all the way through, before starting the next. You prepare a
branch for a developer to review, deploy, and merge. You never deploy, never publish a
library, and never push to or merge into `main`/`master`.

## Hard rules (and why)

1. **Never downgrade anything**, transitive packages included. `npm audit`'s `fixAvailable`
   often points *backwards* (it has suggested dce-mango 2.1.1 → 1.0.3 and dce-dev-wizard
   1.31 → 1.0.8); the inventory marks those `DOWNGRADE` and they count as "no fix".
2. **Never swap a dependency for an alternative, never add one, never remove one, without a
   developer's explicit yes.** The team standardizes dependencies across all projects; a
   lone substitution breaks that. Propose with a one-line reason and wait.
3. **Never replace an in-house package.** In-house = npm maintainer `gabeabrams`, or a repo
   under `github.com/harvard-edtech` or `github.com/gabeabrams` (the inventory checks).
   Fix the lib (Lib mode), publish, then bump the app.
4. **No `overrides`/`resolutions`, no `npm audit fix --force`, no `--force`, no
   `--legacy-peer-deps`.** `check-downgrades` fails the branch if any appear.
5. **Trust the lockfile, not the disk.** `npm ci` first, on the project's Node version. Dev
   machines are stale (IC's client had React 17 installed while package.json said ^19).
6. **Prerelease guard.** Never adopt a version containing `-` (`-beta`, `-rc`, `-beta-ttl-fix-2`)
   unless Gabe says so; `dist-tags.latest` has pointed at a prerelease before.
7. **Secrets stay out.** Never open or quote `config/`, `.env`, credentials files, or Ky's
   `GlobalCredentials`; never paste tokens anywhere.
8. **Report-only on request.** For a dry run / audit / report, stop after Phase 3 and hand
   over the tables; nothing in the repo is edited.

## Where the scripts are

Every app already carries them, pinned by its dce-dev-wizard version:

```bash
AVO=node_modules/dce-dev-wizard/avo-security/scripts   # from the project root
ls $AVO || echo "run npm ci first, or update dce-dev-wizard"
```

Run them in a shell that can see the repo (in Cowork that is the user's computer, where the
connected folder lives). When a repo has no dce-dev-wizard (a lib repo), use another app's
copy or this skill's own `scripts/` folder when it is on the same machine; every script
takes the target folder as an argument. All four are plain Node 20+, zero dependencies, and
print JSON to stdout plus Markdown/JSON files to an output folder you pass with `--out`
(default `/tmp/avo-security/<project>/`, never inside the repo).

| Script | What it does | Read |
| --- | --- | --- |
| `inventory.mjs <project>` | every lockfile folder: `npm audit`, `npm outdated`, dependency chains, prod/dev, in-image, imported-or-not, in-house owner, upgrade-vs-downgrade | `inventory.md` |
| `wiz-merge.mjs <wiz.csv> --inventory <inventory.json> --asset <name>` | parses the Wiz CSV (dce-dev-wizard's `WizCSVRow` format), filters to the app, maps paths to locations, joins to audit rows, honors `.reviewed-cves` | `wiz.md` |
| `check-downgrades.mjs <project> --base stage` | compares every lockfile and package.json with the base branch; exits 1 on downgrades, overrides, lowered ranges | stdout |
| `render-security-updates.mjs decisions.json` | writes the `docs/SecurityUpdates.md` entry from your decisions file | the docs file |

Reference files (read when the phase needs them): `references/projects.md` (per-project
layouts, branches, hooks, instances), `references/wiz-csv.md` (columns, path mapping,
`.reviewed-cves`), `references/decisions-schema.md` (the JSON the renderer takes),
`references/ky-tests.md` (Ky conventions and scaffolding a test repo), and
`references/in-house-packages.md` (the allowlist and detection rule).

## Phase 0 — Intake

Ask, in one message, for whatever is missing: which project(s) and where the repo is; the
base branch (feature branches come from `stage` and PRs target `stage`; `main`, or `master`
in older repos, is prod and belongs to Gabe); **whether there is a Wiz report for this app**
(ask every time; if yes, get the CSV export and its date); which Ky test repo belongs to the
app and whether a test instance is available; full run or report-only.

Then:

```bash
cat .nvmrc 2>/dev/null; grep -h 'BASE_IMAGE=\|^FROM' Dockerfile app/Dockerfile 2>/dev/null
nvm use 2>/dev/null || nvm use 24          # match the Dockerfile's Node major; log mismatches
git status --porcelain                      # clean tree before you start
find . -name package-lock.json -not -path '*/node_modules/*'
# fresh install in EACH lockfile folder (also what makes `npm outdated` meaningful)
( cd <folder> && npm ci )
```

## Phase 1 — Inventory

```bash
node $AVO/inventory.mjs . --out /tmp/avo-security/<project>
# when a Wiz CSV was provided (first without --asset to see the asset names, then with it):
node $AVO/wiz-merge.mjs <wiz.csv> --inventory /tmp/avo-security/<project>/inventory.json --asset <asset substring>
```

Read `inventory.md` and `wiz.md` in full. The row columns mean:

- **Exposure**: `server-runtime` (reachable by any HTTP client; highest priority),
  `client-bundle` (runs in students' browsers: DOM/XSS issues matter; server-only packages
  dragged in by caccl/dce-mango are dead code there), `client-unused` (pulled in only by a
  direct dependency nothing imports), `build-time`, `dev-tool`, `deploy-tool` (incl. Cryo's
  `cdk/`), `lambda-runtime` (Cryo's `worker/` and `dlq-consumer/`: on the Lambda runtime, not
  in our image), `not-deployed` (a folder outside the Docker context, like Cryo's repo root),
  `base-image` (Wiz only: apk packages and Node itself).
- **In image**: computed from the Dockerfile and build scripts. In IC/CAT/Cryo the root
  installs with `NODE_ENV=production` (root devDependencies stay out) while client and server
  build scripts re-install with `--include=dev` / `--production=false` (theirs ship); Gather
  and Hello Harvard install with `NODE_ENV=development`, so everything ships. Wiz sees
  whatever ships. The header also flags a Node version mismatch between `.nvmrc`, `engines`
  and the Dockerfile (Gather: `.nvmrc` v20 vs `node:24-alpine`).
- **Owner (in-house)**: the in-house package closest to the vulnerable one in the chain. It
  matters only when npm's fix is not `within range`.
- **npm's fix**: `within range` (an `npm update <pkg>` gets it), `UPGRADE: x@v (major)`,
  `DOWNGRADE` (= no fix), or none.
- **Notes** under each location list production dependencies with no import, config
  reference, or peer role (removal candidates), npm's downgrade suggestions, and in-house
  packages with a newer published version (with a PRERELEASE flag when `latest` is one).

Treat the import scan as strong evidence, not proof: it reads `import`/`require`/`@use` in
source and config files, plus peer roles declared by sibling packages (dce-expresskit peers
on express, express-session, caccl, dce-mango; dce-reactkit on react, react-dom, bootstrap,
FontAwesome). A package loaded by a string built at runtime would be missed, so say "no
import found" rather than "unused" until a developer confirms.

## Phase 2 — Research every finding

For each row: read the advisory (the GHSA link; NVD for the CVE) and the release notes of the
fix version. Write one sentence each on what the bug is, what it needs (user-controlled
input, a specific option or function), whether our code or the owning lib's code meets that,
and how exploitable it is (CVSS from the advisory; from Wiz: `Score`, `HasExploit`,
`HasCisaKevExploit`, `NvdSeverity`). Write it down even when nothing changes; "we looked, and
here is why it does not apply" is a valid, auditable result and goes in the accepted-risk
table and in `.reviewed-cves`.

## Phase 3 — Decide

First, **unused production dependencies**: propose removal with one line each (why it looks
unused, what advisories it carries), and wait for a developer's yes. Removal is the cheapest
fix, but it changes the shared dependency set, so it is their call. Keep walking the ladder
for those rows so the finding is fixed even if the removal is declined.

Then walk each row down this ladder and stop at the first rung that applies:

1. **Transitive, within range** → `npm update <pkg>` (lockfile only).
2. **Direct, patch/minor available** → `npm install <pkg>@^<fixed>`.
3. **Direct, major required** (axios 0.x → 1.x, zod 3 → 4, query-string 7 → 10, express 4 → 5)
   → read the migration notes; do it only when mechanical and covered by tests you can run;
   otherwise *needs developer*, with the breaking changes summarized.
4. **Owned by an in-house lib** → check for a newer, non-prerelease lib version whose
   dependencies carry the fix (`npm view <lib> versions`, `npm view <lib>@<v> dependencies`).
   An in-house major bump is allowed (it is still our lib) after reading its changelog or
   commits. No published fix → Lib mode, or a lib-fix request and the row is *blocked*.
5. **No fix anywhere** → *accepted/deferred risk*: exposure, why acceptable, mitigation,
   revisit date.
6. **Base image (Wiz)** → rebuild on a refreshed base image; CI resolves `node:24-alpine`
   through an ECR pull-through cache that refreshes at most once per 24h. A Node major change
   is a team decision, not a security PR.

Peer-dependency chains (React, @types/react, Testing Library, FontAwesome) go in **one**
`npm install` command, as the team's React/Vite upgrade guide does, or npm reports ERESOLVE.
When client and server share a dependency (caccl, dce-mango, zaccl, dce-reactkit usually do),
land both on the same version in the same PR.

Status vocabulary for every row: `applied, unverified` → `resolved` (after the instance
passes), `proposed removal`, `needs developer`, `blocked on <lib>`, `accepted risk`,
`rebuild (base image)`.

## Phase 4 — Apply and verify locally

```bash
git checkout stage && git pull && git checkout -b update/security-updates-<yyyy-mm>
# ... apply Phase 3 decisions folder by folder, committing per decision group ...
node $AVO/check-downgrades.mjs . --base stage     # must print RESULT: OK
( cd <folder> && npm ci && npm run build && npm test && npm run typecheck ; npm run lint )
( cd <folder> && npm audit --json | jq .metadata.vulnerabilities )   # the "after" counts
docker build --build-arg BASE_IMAGE=node:24-alpine -t <app>:security-check .   # when Docker exists
```

`check-downgrades` blocks on real downgrades (a dependent that now gets an older copy than it
had), on `overrides`, and on lowered ranges; its `OLDER COPY INTRODUCED` and `HOIST/DEDUPE`
lines are warnings to read, not blockers (an older nested copy is normal when a new parent
needs it; say so, or fix it, if it re-introduces an advisory). Review
`git diff -- '**/package.json'` by hand: only intended ranges changed, nothing new,
nothing removed without a yes. Smoke-run `dev:canvas` / `dev:server` / `dev:client` when the
developer can supply config. Before adopting any new version run
`npm view <pkg>@<v> time maintainers`: prefer versions at least 7 days old unless that version
*is* the security fix, and be suspicious of a maintainer list that just changed. Commit in
small labeled commits (`Security: bump qs via npm update (server)`, `Security: remove unused
@monaco-editor/react (client) — confirmed by <dev>`), so any single bump is revertable.

## Lib mode

When rung 4 finds no published fix and the lib's repo is available (connected folder, or
clone from `github.com/harvard-edtech/<lib>` with the developer's credentials), run Phases
0–4 inside the lib with its own lockfile(s), build, and tests: bump the vulnerable
dependency, keep the lib's exported API unchanged, write the lib's `docs/SecurityUpdates.md`
entry, prepare its branch/PR, then stop. Gabe publishes. Only when the new version is on the
registry do you return to the app and bump it. Work bottom-up so each publish unblocks the
next: dce-mango → dce-expresskit / dce-reactkit → caccl / zaccl / dce-ai / dce-dev-wizard →
apps. When the repo is not available, write a **lib-fix request**: lib, vulnerable dependency,
current → target version, breaking or not, which app rows it unblocks.

## Phase 5 — Tests (Ky)

Each app has a separate Ky test repo (`dceky`, the team's TypeScript wrapper around Cypress;
tests call `ky.` instead of `cy.`). Read `references/ky-tests.md`, then in that repo write the
tests missing for what you changed: at minimum the LTI launch and the landing page, plus
every user flow touching a package you bumped by a major version or removed. When the app
has no test repo yet, scaffold `<app>-tests` from the model repo `immersive-classroom-tests`
(structure, profiles, globals, commands; not its tests). Run locally with `npm run ky:dev`
before handing off. Unit tests in the app (vitest in `client/`, jest in `server/`) already
pass from Phase 4; add one where a mechanical major bump touched logic you can test directly.

## Phase 6 — Document and bump the version

Write `/tmp/avo-security/<project>/decisions.json` (shape in `references/decisions-schema.md`)
with the version you are *about to create* (current patch + 1), then:

```bash
node $AVO/render-security-updates.mjs /tmp/avo-security/<project>/decisions.json --docs docs/SecurityUpdates.md
```

Append accepted risks to `.reviewed-cves` in the project root in the Vulnerability
Checker's format, two comment lines per CVE with the id at the front of the title line
(`# CVE-2025-0005 — <advisory title>` / `# Note: <why>; revisit <date>`, see
`references/wiz-csv.md`), so the next AvoSecurity run flags them instead of re-litigating.
Commit the docs, then bump from the **repo root** (`references/projects.md` has each repo's
hooks):

```bash
git status --porcelain              # must be empty: npm version refuses a dirty tree (.DS_Store edits count)
git push -u origin <branch>         # upstream first: IC's version hook pushes and fails without one
npm version patch                   # commit + tag; runs the repo's version hooks
```

Immersive Classroom's and Gather's `postversion` hooks run `syncVersions`, commit with
`git add -A`, and push the branch, so bump only on your feature branch with everything else
committed and no scratch files in the repo. Course Admin Tools, Hello Harvard and Cryo have
no hook: `git push --follow-tags` yourself. Only the root `package.json` carries the app
version; client/server/worker versions are not bumped (Cryo's CI tags the image from
`app/package.json`, so say in the entry that the image tag does not move).

## Phase 7 — Hand off, deploy, prove it

Open the PR to `stage` (self-review, request a peer or Gabe, post in Slack, per the team
guide). The description is the SecurityUpdates entry plus everything a reviewer must decide:
removals, flagged majors, lib-fix requests. A developer deploys the branch to a test instance
with `npm run dev:wizard` (instances live in `dceConfig.json`). Then:

```bash
HEADLESS=true BROWSER=chrome,webkit PROFILE=<instance profile> E2E_TEST_FOLDER=all npm run ky:start
npm run ky:report
```

Record the result in the entry's Verification section (update `decisions.json`, re-run the
renderer, commit docs-only). A finding is **resolved** only when the deployed instance
passes; until then it is *applied, unverified*. Failures go back to Phase 4, never into
`main`. Wiz closes its findings on the next scan of the released image; note which Wiz ids
the release should clear rather than marking them by hand.

## After the last project

One roll-up: shared-dependency alignment (same react, bootstrap, FontAwesome, caccl,
dce-reactkit versions everywhere), the ordered lib-fix queue, accepted risks with revisit
dates, and infrastructure recommendations for the team to decide on — pruning
devDependencies from the shipped image (multi-stage build or `npm prune --omit=dev` after
the build), base-image refreshes, and `npm audit`/image scanning in CI, which today runs
neither tests nor scans.
