Skip to content

fix(policy): make allowedCodes/allowedCustomers fail closed - #9

Merged
Ectsang merged 1 commit into
mainfrom
fix/allowlist-fail-closed
Oct 12, 2026
Merged

Ectsang merged 1 commit into
mainfrom
fix/allowlist-fail-closed

Conversation

@Ectsang

@Ectsang Ectsang commented Oct 12, 2026

Copy link
Copy Markdown
Member

Fixes #8.

checkPolicy only enforced an allowlist when the request carried the field (if (metadata?.code && constraints.allowedCodes?.length)), so a request that omitted metadata.code or metadata.customer, or sent an empty string, skipped the allowlist and was approved once the amount and budget checks passed.

When a policy sets allowedCodes or allowedCustomers, a missing or empty field is now denied with CODE_NOT_ALLOWED / CUSTOMER_NOT_ALLOWED. Policies without allowlists behave as before. This is a behavior change for callers that set an allowlist but don't send the field, and the changelog says so.

The existing tests that relied on the old behavior now send a listed code. New tests cover no metadata, empty metadata and an empty-string field for both allowlists, and they fail against the unpatched src/policy.ts. npm test passes and npx tsc --noEmit is clean. The README example now sends a code.

checkPolicy only enforced an allowlist when the request carried the field:
`if (metadata?.code && constraints.allowedCodes?.length)`. A request that
omitted metadata.code (or metadata.customer), or sent an empty string,
skipped the allowlist and was approved once amount and budget passed.

When a policy sets an allowlist, a missing or empty field is now denied with
CODE_NOT_ALLOWED / CUSTOMER_NOT_ALLOWED. Policies without allowlists are
unchanged. The existing tests that relied on the old behavior now send a
listed code; new tests cover no metadata, empty metadata and empty-string
fields for both allowlists. README example updated to match.

Fixes #8
@Ectsang
Ectsang merged commit 00ca023 into main Oct 12, 2026
1 check passed
@Ectsang
Ectsang deleted the fix/allowlist-fail-closed branch October 12, 2026 21:22
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.

allowedCodes and allowedCustomers are skipped when metadata fields are omitted

1 participant