Repository navigation
fix(policy): make allowedCodes/allowedCustomers fail closed - #9
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8.
checkPolicyonly enforced an allowlist when the request carried the field (if (metadata?.code && constraints.allowedCodes?.length)), so a request that omittedmetadata.codeormetadata.customer, or sent an empty string, skipped the allowlist and was approved once the amount and budget checks passed.When a policy sets
allowedCodesorallowedCustomers, a missing or empty field is now denied withCODE_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 testpasses andnpx tsc --noEmitis clean. The README example now sends a code.