fix(security): default-deny generic MasterData CRUD on both invoke surfaces#325
Open
0xcucumbersalad wants to merge 1 commit into
Open
fix(security): default-deny generic MasterData CRUD on both invoke surfaces#3250xcucumbersalad wants to merge 1 commit into
0xcucumbersalad wants to merge 1 commit into
Conversation
…rfaces
The generic VTEX MasterData v2 CRUD actions (searchDocuments, createDocument,
patchDocument, getDocument, uploadAttachment) run with the store's admin
appKey/appToken and take a caller-controlled entity + _where filter. They were
exposed unauthenticated on TWO independent surfaces:
1. POST /_serverFn/<hash> — built by generate-invoke.ts / the migration
scaffold from @decocms/apps' invoke.ts
2. POST /deco/invoke/vtex/actions/masterData/<fn>
— registered at runtime by setupApps() walking
the whole app manifest
The two machines run at different times (build vs request) and share no
registry, so closing one left the action reachable via the other.
Introduce a single source of truth — src/admin/invokePolicy.ts — consulted by
BOTH machines so they can't drift:
- generate-invoke.ts: skip denied actions, never emit the createServerFn
const, so no _serverFn route is minted. New --exclude / --allow flags.
- migrate/templates/server-entry.ts: drop the hardcoded MasterData
imports/consts/map entries so a failed generator run can't fail open.
- setupApps(): skip denied keys before registering, closing /deco/invoke.
New optional policy param threaded through autoconfigApps().
Default-deny with an escape hatch: upgrading @decocms/start protects every
site with no per-site action; a site with a real need re-allows a specific
action via policy.allow / --allow (allow wins over deny).
Tests: invokePolicy unit tests, setupApps runtime-door integration test
(404 on MasterData, 200 on cart, allow re-opens), and generate-invoke build
tests (default-deny + --allow re-inclusion).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
The generic VTEX MasterData v2 CRUD actions —
searchDocuments,createDocument,patchDocument,getDocument,uploadAttachment(@decocms/apps/vtex/actions/masterData) — run with the store's adminappKey/appTokenand take a caller-controlledentity+_wherefilter. They were exposed unauthenticated on two independent surfaces:POST /_serverFn/<hash>— built at build time byscripts/generate-invoke.ts(and the migration scaffoldscripts/migrate/templates/server-entry.ts) from@decocms/apps'vtex/invoke.ts.POST /deco/invoke/vtex/actions/masterData/<fn>— registered at runtime bysetupApps()walking the whole app manifest.A
searchDocuments(entity="CL", filter="id=*")call therefore dumps the customer (CL) table's PII. The two machines run at different times (build vs. request) and share no registry, so closing one left the action reachable via the other.Fix
Introduce a single source of truth —
src/admin/invokePolicy.ts— consulted by both machines so they can't drift:generate-invoke.ts— skips denied actions; never emits thecreateServerFnconst, so no_serverFnroute is minted. New--exclude/--allowflags.migrate/templates/server-entry.ts— drops the hardcoded MasterData imports/consts/map entries so a failed generator run can't fail open.setupApps()— skips denied keys before registering, closing/deco/invoke. New optionalpolicyparam threaded throughautoconfigApps().Default-deny with an escape hatch: upgrading
@decocms/startprotects every site with no per-site action; a site with a real need re-allows a specific action viapolicy.allow(runtime) or--allow(build).allowwins overdeny.Tests
invokePolicyunit tests (both key shapes, allow/deny precedence).setupAppsruntime-door integration test —/deco/invoke/…/masterData/*→ 404, cart → 200,allowre-opens exactly one.generate-invokebuild tests — default-deny drops MasterData while keeping cart actions;--allowre-includes surgically.Verified live
Ran on
casaevideo-tanstack(real VTEX site) against this branch: default-deny shuts both doors (/deco/invoke404, no_serverFnconsts),--allow/policy.allowre-open each door surgically, homepage 200, no errors introduced.Summary by cubic
Default-deny the generic VTEX MasterData v2 CRUD actions across both invoke surfaces to block unauthenticated access. Adds a shared
invokePolicyused at build time and runtime, with--allow/--excludeescape hatches for audited opt-ins.Bug Fixes
/_serverFn/<hash>):scripts/generate-invoke.tsconsultssrc/admin/invokePolicy.tsand skips denied actions; adds--allowand--exclude./deco/invoke/...):src/sdk/setupApps.tsfilters manifest keys withinvokePolicybefore registering;autoconfigApps()accepts an optionalpolicyparam.Migration
@decocms/start.--allow <name>or pass{ allow: ["searchDocuments"] }toautoconfigApps/setupApps.Written for commit fc7fbb2. Summary will update on new commits.