Core

Install packages through Core

Install @ziteox packages via Core’s npm registry proxy — no GitHub Packages tokens in client builds.

Install packages through Core

Status: implemented locally on the Core Worker (/npm/*). The production URL https://core.ziteox.com is not live yet — use http://localhost:8787 for local Core. Go-live steps: Go live.

Why

Client builds and consumer repos should not hold a long-lived GitHub Packages PAT (GITHUB_PACKAGES_TOKEN). Core keeps one upstream read credential (CORE_GITHUB_PACKAGES_TOKEN) and vends access through normal project tokens scoped with packages:read.

Flow (in words)

  1. Staff mint a project token with scope packages:read (and an environment) via the admin portal → POST /v1/admin/tokens.
  2. The consumer’s .npmrc points @ziteox at Core’s npm proxy and uses that zxcore_… token as _authToken.
  3. npm / pnpm request packuments from Core (GET /npm/...) and tarballs from Core (GET /download/..., also accepted at /npm/download/...).
  4. Core checks the project token (revoked / expired / scope), allowlists @ziteox/* only, then fetches GitHub Packages with the Core-held upstream token.
  5. Packument dist.tarball URLs are rewritten to Core /download/@ziteox/... URLs (same path shape as GitHub Packages). Tarball fetches follow upstream redirects without the upstream Authorization header (signed blob storage).
  6. Every allow and deny writes an audit row (npm.packument / npm.tarball; root download may set via: "root_download").

Scope: packages:read

Exact string — no glob. Opt-in and exclusive: request it alone on issue (and on rotate when sending explicit scopes). Mixing it with any other scope → 400 invalid_scope (packages:read must be requested alone…). New projects get packages:read on their allowed_scopes ceiling automatically (migration 0007 backfills existing projects); that only allows minting — tokens never receive it unless requested explicitly and alone. Issue/rotate are still capped by the ceiling (scope_exceeds_project if missing). Unknown scope strings still return 400 invalid_scope.

At request time, a token without packages:read gets 403 scope_denied on /npm/*.

The Portal must not include packages:read in its “all allowed scopes” default mint — that would mix it with path scopes and get 400. Request packages:read only when minting a dedicated package-install token.

Minting a package-read token

Same admin path as other project tokens. Example body (scopes must be exactly ["packages:read"]):

{
  "project_key": "my-app",
  "scopes": ["packages:read"],
  "environment": "development",
  "label": "npm-install"
}

POST /v1/admin/tokens with a forge_admin assertion (portal integration: Admin portal integration). Put the returned token (shown once) in the host env as ZITEOX_CORE_NPM_TOKEN — never commit it.

.npmrc

Production shape (URL not live yet):

@ziteox:registry=https://core.ziteox.com/npm/
//core.ziteox.com/:_authToken=${ZITEOX_CORE_NPM_TOKEN}

Local Core:

@ziteox:registry=http://localhost:8787/npm/
//localhost:8787/:_authToken=${ZITEOX_CORE_NPM_TOKEN}

Host-root _authToken covers both /npm/ packuments and /download tarballs. Helper in @ziteox/core-client: npmrcFor({ coreBaseUrl, tokenEnvVar? }) returns the same two lines.

Do not set replace-registry-host=always. npm (pacote remote.js builds resolved URLs with new URL(resolvedURL.pathname, this.registry), and arborist reify.js #registryResolved) only replaces lockfile hosts using the default registry, never a scoped @ziteox:registry. With always, @ziteox/ui tarball hosts were rewritten to registry.npmjs.org → 404. Making Core the default registry would open an open proxy — rejected.

Lockfiles

Swap only the host of @ziteox resolved entries; keep path and integrity unchanged. Example:

"resolved": "https://core.ziteox.com/download/@ziteox/ui/0.1.1/<sha>"

(was https://npm.pkg.github.com/download/@ziteox/ui/0.1.1/<sha>). Core serves the GitHub-shaped root /download/@ziteox/<pkg>/<ver>/<sha> (and /npm/download/...). Fresh installs through Core write this shape automatically — packument tarballs are rewritten to ${CORE_PUBLIC_URL}/download/....

Integrity is byte-identical (verified: tarball via GitHub blob sha512 == lockfile integrity).

Never commit localhost URLs in the lockfile. For local Core testing, override per-machine (local .npmrc / env), not in the repo.

Local-dev caveat: the local install proof was skipped by Laki; the install proof runs against live Core (go-live step 11). A Mac with a broken IPv6 route can make local workerd hang on GitHub’s blob host (pkg-npm.githubusercontent.com has AAAA); Core returns 504 upstream_timeout. Not an issue on deployed Workers.

Audit

ActionWhen
npm.packumentPackument GET (ok or denied)
npm.tarballTarball GET (ok or denied)

Meta includes package, version (tarball only; null on packument), reason when denied, and upstream_status when an upstream call was made. Project, token, and environment come from the caller token when known.

Errors (selected)

StatusCodeMeaning
401token_invalid / token_expired / token_revokedCaller Bearer missing or bad
400invalid_scopepackages:read mixed with other scopes, or unknown scope string
403scope_deniedToken lacks packages:read
404not_foundNon-@ziteox name, unknown package, or unknown /npm/* path (no upstream call for allowlist misses)
502upstream_deniedUpstream 401/403 or unsafe upstream response (body never leaked)
503upstream_not_configuredCORE_GITHUB_PACKAGES_TOKEN missing
504upstream_timeoutUpstream headers deadline exceeded (seen locally with IPv6/blob hangs; rare on Workers)

Security properties

  • Allowlist — only ^@ziteox/[a-z0-9][a-z0-9._-]*$; everything else is 404 with no upstream request (anti open-proxy).
  • Caller token never forwarded — upstream sees only Authorization: Bearer ${CORE_GITHUB_PACKAGES_TOKEN}.
  • Upstream token never returned — not in response bodies, error messages, or audit meta.
  • Redirect hop without auth — after upstream 3xx, Core follows Location without Authorization (https only; http allowed only when NPM_UPSTREAM_URL itself is http, for local mocks).
  • Admin assertions are not accepted on /npm/* — project tokens only.