Skip to content

refactor(infra-billing): dedupe the site-ownership check shared by GET and PORTAL - #6167

Merged
pedrofrxncx merged 1 commit into
mainfrom
refactor/infra-billing-dedupe-ownership-check-w2
Aug 18, 2026
Merged

refactor(infra-billing): dedupe the site-ownership check shared by GET and PORTAL#6167
pedrofrxncx merged 1 commit into
mainfrom
refactor/infra-billing-dedupe-ownership-check-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Source: C1 duplication — apps/api/src/tools/infra-billing/get.ts and portal.ts each contained the identical 8-line block (lowercase+dedupe requested slugs, load the org's owned slugs, reject any unowned slug) verbatim.

Payoff: one home for a security-relevant check (this is the gate that stops one org reading another org's infra usage/plan/invoices by guessing a site slug) means a future fix to it can't be applied to one call site and missed in the other.

Change: extracted the block into resolveOwnedSlugs(ctx, orgId, siteSlugs) in a new apps/api/src/tools/infra-billing/ownership.ts, and call it from both tools. Byte-identical logic, just relocated — no behavior change. Net diff: -20 duplicated lines / +23 shared-helper lines (one-time cost, future callers add zero).

Verify: cd apps/api && bunx tsc --noEmit (clean) and bun test apps/api/src/deco-legacy/infra-billing.test.ts (32 pass, unchanged) confirm nothing about the ownership check's behavior moved.

Checks run locally: bun run fmt, bunx tsc --noEmit (apps/api), bun test apps/api/src/deco-legacy/infra-billing.test.ts, bunx oxlint on the 3 changed files — all clean. Full CI validates the rest.


Summary by cubic

Deduplicates the infra-billing site-ownership check used by GET and PORTAL into a shared helper, keeping behavior identical. Centralizing this security gate avoids divergence and ensures fixes apply to both endpoints.

  • Add resolveOwnedSlugs(ctx, orgId, siteSlugs) in apps/api/src/tools/infra-billing/ownership.ts (lowercase + dedupe, load owned slugs, throw on unowned; returns slugs and ownedSlugs).
  • Replace inline checks in apps/api/src/tools/infra-billing/get.ts and apps/api/src/tools/infra-billing/portal.ts with the helper.
  • No behavior change; tests and type checks unchanged. No rollout or migration actions.

Written for commit 9bfaca0. Summary will update on new commits.

Review in cubic

…T and PORTAL

INFRA_BILLING_GET and INFRA_BILLING_PORTAL each hand-rolled the identical
lowercase+dedupe-slugs, load-owned-slugs, reject-unowned check. Extract it
into resolveOwnedSlugs() in a new ownership.ts and call it from both.

Net: -20 lines duplicated logic / +23 lines shared helper, behavior
unchanged (byte-identical logic, just relocated + parameterized on ctx/orgId).
@pedrofrxncx
pedrofrxncx merged commit 251eba0 into main Aug 18, 2026
25 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/infra-billing-dedupe-ownership-check-w2 branch August 18, 2026 14:08
decocms Bot pushed a commit that referenced this pull request Aug 18, 2026
PR: #6167 refactor(infra-billing): dedupe the site-ownership check shared by GET and PORTAL
Bump type: patch

- decocms (apps/api/package.json): 4.225.0 -> 4.225.1
- @decocms/native (apps/native/package.json): 4.225.0 -> 4.225.1

Deploy-Scope: server
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.

1 participant