fix(cors): per-merchant CORS origin validation and DELETE endpoint#32
Open
Jaydbrown wants to merge 4 commits into
Open
fix(cors): per-merchant CORS origin validation and DELETE endpoint#32Jaydbrown wants to merge 4 commits into
Jaydbrown wants to merge 4 commits into
Conversation
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.
Closes #19
Summary
The
SetCorsOriginsDtolacked the security constraints described in the issue, and there was no way to remove a single origin without replacing the entire list. This PR adds all missing validation rules and theDELETE /merchants/me/cors/:originendpoint.Changes
src/merchants/merchants.dto.tsBefore:
After:
Validation added:
@ArrayMaxSize(10)— enforces the 10-origin cap at the DTO layer before any DB writeprotocols: ['https']— rejects HTTP originsrequire_protocol: true— prevents bare hostnames likeexample.comallow_localhost: false— blockslocalhostin all environments@Matches(/^[^*]+$/)— explicitly rejects wildcard stringssrc/merchants/merchants.service.tsAdded
deleteCorsOrigin(merchantId, origin):Delegates to
setCorsOriginsso the Redis cache is invalidated via the existingcorsCache.invalidateMerchantCache(merchantId)call — no separate cache logic needed.src/merchants/merchants.controller.tsAdded
DELETE /merchants/me/cors/:origin:decodeURIComponenthandles URL-encoded origins in the path (e.g.https%3A%2F%2Fexample.com). Returns the updated list so the caller does not need a follow-upGET.Validation matrix
https://myshop.comhttp://myshop.commyshop.comhttps://localhost:3000https://*.myshop.comTest plan
PUT /merchants/me/corswith an HTTP origin → 400PUT /merchants/me/corswith a localhost origin → 400PUT /merchants/me/corswith a wildcard origin → 400PUT /merchants/me/corswith 11 origins → 400PUT /merchants/me/corswith valid HTTPS origins → 200, saved and cachedDELETE /merchants/me/cors/:originwith an existing origin → 200, returns updated listDELETE /merchants/me/cors/:originwith a non-existent origin → 404