create-mercato-app 0.6.5-develop.5337.1.534b781eac → 0.6.5-develop.5382.1.f542de69af

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mercato-app",
3
- "version": "0.6.5-develop.5337.1.534b781eac",
3
+ "version": "0.6.5-develop.5382.1.f542de69af",
4
4
  "type": "module",
5
5
  "description": "Create a new Open Mercato application",
6
6
  "main": "./dist/index.js",
@@ -30,6 +30,10 @@ NEXTAUTH_SECRET=
30
30
  APP_URL=http://localhost:3000
31
31
  # Additional trusted origins for app requests that must pass host validation.
32
32
  # APP_URL is required in production for security-sensitive email links.
33
+ # In dev mode these values also govern the HMR WebSocket (/_next/webpack-hmr):
34
+ # add your public/reverse-proxy/Tailscale host here so remote dev access works,
35
+ # then restart the dev server. Non-allowlisted origins are still rejected.
36
+ # In Docker dev, the value must also be forwarded into the app container.
33
37
  # Example: APP_ALLOWED_ORIGINS=https://admin.example.com,https://ops.example.com
34
38
  # APP_ALLOWED_ORIGINS=
35
39
 
@@ -549,7 +553,7 @@ OCR_MODEL=gpt-4o
549
553
  # ============================================================================
550
554
  # Customer Portal Custom Domain (Phase 1–3)
551
555
  # ============================================================================
552
- # See .ai/specs/2026-04-08-portal-custom-domain-routing.md and
556
+ # See .ai/specs/implemented/2026-04-08-portal-custom-domain-routing.md and
553
557
  # docker/traefik/README.md. Required when custom-domain mappings are in use.
554
558
 
555
559
  # Primary platform host — excluded from the Traefik domain-check middleware
@@ -316,7 +316,7 @@ export const aiAgentOverrides: AiAgentOverridesMap = {
316
316
  }
317
317
  ```
318
318
 
319
- Example `modules.ts` inline override (preferred for app-level decisions that do not deserve a fake module). All module contract domains live under the same `entry.overrides` umbrella per the [unified spec](https://github.com/open-mercato/open-mercato/blob/main/.ai/specs/2026-05-04-modules-ts-unified-overrides.md):
319
+ Example `modules.ts` inline override (preferred for app-level decisions that do not deserve a fake module). All module contract domains live under the same `entry.overrides` umbrella per the [unified spec](https://github.com/open-mercato/open-mercato/blob/main/.ai/specs/implemented/2026-05-04-modules-ts-unified-overrides.md):
320
320
 
321
321
  ```ts
322
322
  // src/modules.ts
@@ -38,6 +38,8 @@ services:
38
38
  DATABASE_URL: postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-open-mercato}
39
39
  JWT_SECRET: ${JWT_SECRET:-JWT}
40
40
  APP_URL: ${APP_URL:-http://localhost:3000}
41
+ # Additional trusted app/dev origins for the Open Mercato origin allowlist (resolveAllowedDevOrigins)
42
+ APP_ALLOWED_ORIGINS: ${APP_ALLOWED_ORIGINS:-}
41
43
  CACHE_REDIS_URL: redis://redis:6379
42
44
  CACHE_STRATEGY: ${CACHE_STRATEGY:-redis}
43
45
  ENABLE_CRUD_API_CACHE: ${ENABLE_CRUD_API_CACHE:-true}
@@ -40,6 +40,8 @@ services:
40
40
  DATABASE_URL: postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:5432/${POSTGRES_DB:-open-mercato}
41
41
  JWT_SECRET: ${JWT_SECRET:-JWT}
42
42
  APP_URL: ${APP_URL:-http://localhost:3000}
43
+ # Additional trusted app/dev origins for the Open Mercato origin allowlist (resolveAllowedDevOrigins)
44
+ APP_ALLOWED_ORIGINS: ${APP_ALLOWED_ORIGINS:-}
43
45
  CACHE_REDIS_URL: redis://redis:6379
44
46
  CACHE_STRATEGY: ${CACHE_STRATEGY:-redis}
45
47
  ENABLE_CRUD_API_CACHE: ${ENABLE_CRUD_API_CACHE:-true}
@@ -139,7 +139,7 @@ function normalizeLoadedMetadata(
139
139
  return { [method]: metadata }
140
140
  }
141
141
 
142
- async function checkAuthorization(
142
+ export async function checkAuthorization(
143
143
  methodMetadata: MethodMetadata | null,
144
144
  auth: AuthContext,
145
145
  req: NextRequest
@@ -167,24 +167,31 @@ async function checkAuthorization(
167
167
  }
168
168
 
169
169
  if (auth && requiresAuthentication) {
170
- const rawTenantCandidate = await extractTenantCandidate(req)
171
- if (rawTenantCandidate !== undefined) {
170
+ // HTTP parameter pollution hardening (issue #2665): a request can carry `tenantId`
171
+ // more than once — repeated `?tenantId=` query params, or in both the query string
172
+ // and the body. The dispatcher and downstream handlers may disagree on which
173
+ // occurrence wins (here historically `getAll().last`, handlers use `get()` first),
174
+ // so the authorization gate must validate EVERY distinct candidate. If any one
175
+ // targets a tenant the actor may not select, the request is rejected — making this
176
+ // decision binding regardless of how a handler later parses the same request.
177
+ const rawTenantCandidates = await extractTenantCandidates(req)
178
+ const actorTenant = normalizeTenantId(auth.tenantId ?? null) ?? null
179
+ const enforcedCandidates = new Set<string | null>()
180
+ for (const rawTenantCandidate of rawTenantCandidates) {
172
181
  const tenantCandidate = sanitizeTenantCandidate(rawTenantCandidate)
173
- if (tenantCandidate !== undefined) {
174
- const normalizedCandidate = normalizeTenantId(tenantCandidate) ?? null
175
- const actorTenant = normalizeTenantId(auth.tenantId ?? null) ?? null
176
- const tenantDiffers = normalizedCandidate !== actorTenant
177
- if (tenantDiffers) {
178
- try {
179
- const guardContainer = await ensureContainer()
180
- await enforceTenantSelection({ auth, container: guardContainer }, tenantCandidate)
181
- } catch (error) {
182
- if (isCrudHttpError(error)) {
183
- return NextResponse.json(error.body ?? { error: t('api.errors.forbidden', 'Forbidden') }, { status: error.status })
184
- }
185
- throw error
186
- }
182
+ if (tenantCandidate === undefined) continue
183
+ const normalizedCandidate = normalizeTenantId(tenantCandidate) ?? null
184
+ if (normalizedCandidate === actorTenant) continue
185
+ if (enforcedCandidates.has(normalizedCandidate)) continue
186
+ enforcedCandidates.add(normalizedCandidate)
187
+ try {
188
+ const guardContainer = await ensureContainer()
189
+ await enforceTenantSelection({ auth, container: guardContainer }, tenantCandidate)
190
+ } catch (error) {
191
+ if (isCrudHttpError(error)) {
192
+ return NextResponse.json(error.body ?? { error: t('api.errors.forbidden', 'Forbidden') }, { status: error.status })
187
193
  }
194
+ throw error
188
195
  }
189
196
  }
190
197
  }
@@ -248,17 +255,12 @@ function sanitizeTenantCandidate(candidate: unknown): unknown {
248
255
  return candidate
249
256
  }
250
257
 
251
- export async function extractTenantCandidate(req: NextRequest): Promise<unknown> {
252
- const tenantParams = req.nextUrl?.searchParams?.getAll?.('tenantId') ?? []
253
- if (tenantParams.length > 0) {
254
- return tenantParams[tenantParams.length - 1]
255
- }
256
-
258
+ function bodyCarriesTenantId(req: NextRequest): boolean {
257
259
  const method = (req.method || 'GET').toUpperCase()
258
- if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS') {
259
- return undefined
260
- }
260
+ return method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS'
261
+ }
261
262
 
263
+ async function extractBodyTenantCandidate(req: NextRequest): Promise<unknown> {
262
264
  const rawContentType = req.headers.get('content-type')
263
265
  if (!rawContentType) return undefined
264
266
  const contentType = rawContentType.split(';')[0].trim().toLowerCase()
@@ -284,6 +286,35 @@ export async function extractTenantCandidate(req: NextRequest): Promise<unknown>
284
286
  return undefined
285
287
  }
286
288
 
289
+ export async function extractTenantCandidate(req: NextRequest): Promise<unknown> {
290
+ const tenantParams = req.nextUrl?.searchParams?.getAll?.('tenantId') ?? []
291
+ if (tenantParams.length > 0) {
292
+ return tenantParams[tenantParams.length - 1]
293
+ }
294
+
295
+ if (!bodyCarriesTenantId(req)) {
296
+ return undefined
297
+ }
298
+
299
+ return extractBodyTenantCandidate(req)
300
+ }
301
+
302
+ // Returns every `tenantId` candidate the request carries — each repeated `?tenantId=`
303
+ // query param plus any body-level value. The dispatcher enforces tenant selection
304
+ // against all of them so a downstream handler that reads a different occurrence
305
+ // (e.g. `searchParams.get()` first vs. `getAll()` last) cannot be tricked into using a
306
+ // candidate that was never authorized (issue #2665).
307
+ export async function extractTenantCandidates(req: NextRequest): Promise<unknown[]> {
308
+ const candidates: unknown[] = [...(req.nextUrl?.searchParams?.getAll?.('tenantId') ?? [])]
309
+
310
+ if (bodyCarriesTenantId(req)) {
311
+ const bodyCandidate = await extractBodyTenantCandidate(req)
312
+ if (bodyCandidate !== undefined) candidates.push(bodyCandidate)
313
+ }
314
+
315
+ return candidates
316
+ }
317
+
287
318
  async function handleRequest(
288
319
  method: HttpMethod,
289
320
  req: NextRequest,
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { z } from 'zod'
3
3
  import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
4
+ import { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'
4
5
  import { Todo } from '../../data/entities'
5
6
 
6
7
  const ENTITY_ID = 'example:todo' as const
@@ -105,7 +106,7 @@ export const { metadata, GET, POST, PUT, DELETE } = makeCrudRoute({
105
106
  if (ids.length > 0) F.id = { $in: ids }
106
107
  }
107
108
  if (q.id) F.id = q.id
108
- if (q.title) F.title = { $ilike: `%${q.title}%` }
109
+ if (q.title) F.title = { $ilike: `%${escapeLikePattern(q.title)}%` }
109
110
  if (q.isDone !== undefined) F.is_done = q.isDone as any
110
111
  if (q.organizationId) F.organization_id = q.organizationId
111
112
  if (q.createdFrom || q.createdTo) {
@@ -4,7 +4,7 @@
4
4
  // - overrides: optional unified per-app override surface — replace or
5
5
  // disable any contract a module presents: AI, routes, events, workers,
6
6
  // widgets, notifications, interceptors, setup, ACL, DI, encryption, etc.
7
- // See `.ai/specs/2026-05-04-modules-ts-unified-overrides.md` and
7
+ // See `.ai/specs/implemented/2026-05-04-modules-ts-unified-overrides.md` and
8
8
  // `apps/docs/docs/framework/modules/overrides.mdx`.
9
9
  import { parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'
10
10
  import type { ModuleOverrides } from '@open-mercato/shared/modules/overrides'