Skip to content

Feat/manifest constants and validation - #122

Open
a-d-j-i wants to merge 3 commits into
mainfrom
feat/manifest-constants-and-validation
Open

a-d-j-i wants to merge 3 commits into
mainfrom
feat/manifest-constants-and-validation

Conversation

@a-d-j-i

@a-d-j-i a-d-j-i commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Problem: the stringly-typed fields in a signed manifest mode,
pathRules[].type, contentRules[].action.type, signatureType,
logsMinLevel were authored as ad-hoc string literals in build
configs and dropped silently if misspelled: the loader's permissive
normalizer would warn+fallback at runtime, but the signer happily
produced the broken manifest and operators had no way to catch the
typo before deploy.

This change:

  1. Extracts the stringly-typed values into frozen enums in
    @dappfence/core/constants (MODE, PATH_RULE_TYPE,
    CONTENT_ACTION_TYPE, SIGNATURE_TYPE, LOG_LEVEL), each with a
    matching JSDoc @typedef. These are the single source of truth
    for both the signer and the SW loader.
  2. Adds @dappfence/manifest-tools/validate — a strict
    assertValidManifestPayload that throws on any unknown enum value,
    malformed sha256 hash, malformed URL, or type mismatch. Exposed via
    ./validate subpath export so build tools can call it directly.
  3. Wires signManifest to call the validator by default (with a
    skipValidation: true escape for tests that exercise malformed
    payloads on purpose).

…ants

Problem: the stringly-typed fields in a signed manifest — `mode`,
`pathRules[].type`, `contentRules[].action.type`, `signatureType`,
`logsMinLevel` were authored as ad-hoc string literals in build
configs and dropped silently if misspelled: the loader's permissive
normalizer would warn+fallback at runtime, but the signer happily
produced the broken manifest and operators had no way to catch the
typo before deploy.

This change:

1. Extracts the stringly-typed values into frozen enums in
   `@dappfence/core/constants` (`MODE`, `PATH_RULE_TYPE`,
   `CONTENT_ACTION_TYPE`, `SIGNATURE_TYPE`, `LOG_LEVEL`), each with a
   matching JSDoc `@typedef`. These are the single source of truth
   for both the signer and the SW loader.
2. Adds `@dappfence/manifest-tools/validate` — a strict
   `assertValidManifestPayload` that throws on any unknown enum value,
   malformed sha256 hash, malformed URL, or type mismatch. Exposed via
   `./validate` subpath export so build tools can call it directly.
3. Wires `signManifest` to call the validator by default (with a
   `skipValidation: true` escape for tests that exercise malformed
   payloads on purpose).
Wire the shared constants into the SW's manifest handling so string
literals can't drift, and extend signManifest to honor the
declared signatureType.
@a-d-j-i
a-d-j-i requested a review from a team as a code owner December 4, 2026 12:36
@netlify

netlify Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for dappfence-templates canceled.

Name Link
🔨 Latest commit eb9c0a5
🔍 Latest deploy log https://app.netlify.com/projects/dappfence-templates/deploys/6b130b1544b169801530879e

@friccobaldi

Copy link
Copy Markdown
Collaborator

When validation catches a config typo (e.g. mode: 'PROTECTED' instead of 'protected'), signManifest throws, but generateManifest catches it, only logs it, and writes the manifest without a signature. The build finishes successfully, so the unsigned manifest gets deployed. @a-d-j-i

emiliorizzo
emiliorizzo previously approved these changes Dec 4, 2026

@emiliorizzo emiliorizzo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The try/catch in generateManifest swallowed signing errors, logged
them at `logger.error`, and wrote an unsigned manifest. Builds still
exited 0, so a config typo like `mode: 'PROTECTED'` would silently
deploy an unsigned manifest — defeating the strict validator added
alongside signManifest in this PR.

Remove the catch: signing failures (validation, bad key, crypto) now
abort the build. The existing `else` branch still handles the unsigned
dev path when no secretKey is provided.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants