@lunora/advisor 1.0.0-alpha.2 → 1.0.0-alpha.21
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/LICENSE.md +6 -0
- package/README.md +1 -1
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +2160 -4
- package/dist/index.d.ts +2160 -4
- package/dist/index.mjs +110 -8
- package/dist/packem_shared/{AE_METRIC_EVENTS-DexctYv6.mjs → AE_METRIC_EVENTS-BM14d0lm.mjs} +3 -1
- package/dist/packem_shared/actionFetchSsrf-wbmYgzmz.mjs +26 -0
- package/dist/packem_shared/aiRawRunEscapeHatch-C29jd32J.mjs +26 -0
- package/dist/packem_shared/aiToolSideEffectPromptInjection-BtD3alqB.mjs +33 -0
- package/dist/packem_shared/aiUnboundedGenerationPublic-CbAcSxLB.mjs +26 -0
- package/dist/packem_shared/allowUnauthenticatedShardAccessEnabled-BcASq-jP.mjs +30 -0
- package/dist/packem_shared/argument-derived-sink-C1xTTqAt.mjs +30 -0
- package/dist/packem_shared/authCsrfCheckDisabled-DCf9FSoD.mjs +26 -0
- package/dist/packem_shared/authEmailVerificationDisabled-Dk-Tc5oU.mjs +26 -0
- package/dist/packem_shared/authSecureCookiesDisabled-osJrHW9Y.mjs +26 -0
- package/dist/packem_shared/authSessionFreshageZero-CjufCc_Q.mjs +26 -0
- package/dist/packem_shared/authTrustedOriginsWildcard-ylv4PKzC.mjs +26 -0
- package/dist/packem_shared/browserAllowPrivateTargets-CBvQxLAM.mjs +26 -0
- package/dist/packem_shared/browserUserUrlWithoutAllowlist-CvhA6w59.mjs +26 -0
- package/dist/packem_shared/containerInstanceKeyFromUserInput-BUXj2J4w.mjs +19 -0
- package/dist/packem_shared/containerRuntimeEgressRelaxation-B0LlfmDA.mjs +26 -0
- package/dist/packem_shared/containerStartEnableInternetOverride-DDaHZQ1L.mjs +26 -0
- package/dist/packem_shared/externalSourceOnGlobal-Bg-NfCX9.mjs +30 -0
- package/dist/packem_shared/externalSourceUnscoped-5vT-Bup3.mjs +44 -0
- package/dist/packem_shared/flagGatesSecurityWithUnsafeDefault-BhIs0shr.mjs +41 -0
- package/dist/packem_shared/{fromServerSchema-DinF1nph.mjs → fromServerSchema-BiB6JSiW.mjs} +9 -0
- package/dist/packem_shared/helpers-BySnKhVB.mjs +31 -0
- package/dist/packem_shared/httpActionMissingAuthGuard-CxipddNx.mjs +35 -0
- package/dist/packem_shared/httpActionResponseHeaderInjection-DOFS7pFT.mjs +39 -0
- package/dist/packem_shared/identityUndeclaredClaimTrusted-D8nXV2dd.mjs +32 -0
- package/dist/packem_shared/imagesUrlSourceFromUserInput-YcDQ0b_Y.mjs +19 -0
- package/dist/packem_shared/{indexReferencesUnknownField-DH0_dbUY.mjs → indexReferencesUnknownField-BSWNngxX.mjs} +1 -1
- package/dist/packem_shared/insertManyUnsafeUserData-Dn77XpmX.mjs +26 -0
- package/dist/packem_shared/kvUnscopedUserKeyIdor-YWwmfE8X.mjs +19 -0
- package/dist/packem_shared/mailInboundDispatchWithoutVerify-CHSRA8zz.mjs +28 -0
- package/dist/packem_shared/mailRecipientFromRequestInput-Cka2qu5J.mjs +26 -0
- package/dist/packem_shared/maskWeakHashStrategyOnPii-1c4q8Opf.mjs +35 -0
- package/dist/packem_shared/maskedRelationLeakViaWith-CPI4s0sl.mjs +76 -0
- package/dist/packem_shared/mutatorFullRowReplace-BJnNDaIV.mjs +26 -0
- package/dist/packem_shared/normalizeIdUsedAsAuthorization-BVPtCpzT.mjs +50 -0
- package/dist/packem_shared/outputProjectionMissingOnPublicRead-Bl5IMx0k.mjs +51 -0
- package/dist/packem_shared/ownerFieldFromArgsNotAuth-mOw3hE5z.mjs +26 -0
- package/dist/packem_shared/paymentCreateWithoutAuthorize-BYm4JLxo.mjs +26 -0
- package/dist/packem_shared/paymentWebhookWideTolerance-D9QQJMJq.mjs +35 -0
- package/dist/packem_shared/plaintextSecretInWranglerVariables-NKO4YkKf.mjs +35 -0
- package/dist/packem_shared/privilegedDispatchUnvalidatedPayload-5Forjckt.mjs +37 -0
- package/dist/packem_shared/privilegedFanoutFromPublicProcedure-D3dL01B8.mjs +26 -0
- package/dist/packem_shared/{publicMutationWithoutRatelimit-xBpJ6GWK.mjs → publicMutationWithoutRatelimit-DbIhgi7j.mjs} +2 -2
- package/dist/packem_shared/publicTableRlsOptoutConfusion-Bn71yoD4.mjs +38 -0
- package/dist/packem_shared/queueWithoutDlq-CSkGNb_0.mjs +41 -0
- package/dist/packem_shared/ratelimitDefaultMemoryStore-BISChG5C.mjs +26 -0
- package/dist/packem_shared/ratelimitKeySpoofableOrGlobal-DqlHYQQ3.mjs +26 -0
- package/dist/packem_shared/ratelimitMiddlewareFailOpen-CJgDCaUw.mjs +33 -0
- package/dist/packem_shared/{relationReferencesUnknownField-YznyXt_7.mjs → relationReferencesUnknownField-CjbLScJ1.mjs} +1 -1
- package/dist/packem_shared/shapeTargetsGlobalTable-DHrf4Koi.mjs +34 -0
- package/dist/packem_shared/shapeUnknownTable-C8aDWFoe.mjs +34 -0
- package/dist/packem_shared/softDeleteIncludeDeletedFromArgs-BLqDKrkM.mjs +38 -0
- package/dist/packem_shared/storageGenerateUploadUrlNoContentTypePin-Da4L9Ge8.mjs +26 -0
- package/dist/packem_shared/storageKeyFromUserArgs-B86elJgS.mjs +19 -0
- package/dist/packem_shared/storagePresignedUrlForPrivateContent-yGmb8uqz.mjs +47 -0
- package/dist/packem_shared/storageUploadWithoutContentTypeAllowlist-BV-gF1lT.mjs +27 -0
- package/dist/packem_shared/storageUploadWithoutMaxSize-DpxO59wU.mjs +27 -0
- package/dist/packem_shared/{userCreatingMutationWithoutCaptcha-CH31YsUZ.mjs → userCreatingMutationWithoutCaptcha-2DZtWIPb.mjs} +2 -2
- package/dist/packem_shared/vectorsNamespaceFromUserInput-CQhr5bVn.mjs +19 -0
- package/dist/packem_shared/workflowDuplicateStepName-ioBxPBCy.mjs +48 -0
- package/package.json +4 -3
- package/dist/packem_shared/helpers-DNCkMWZQ.mjs +0 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const containerStartEnableInternetOverride = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "A runtime `.start({ enableInternet: true, … })` call overrides the static `defineContainer` declaration and re-opens public internet egress for that container instance, defeating the `container_public_internet` lint's assumption that the declaration is authoritative.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "WARN",
|
|
8
|
+
name: "container_start_enable_internet_override",
|
|
9
|
+
remediation: "Avoid overriding `enableInternet` at `.start()` time. Set it once on the `defineContainer` declaration in `lunora/containers.ts` so the static advisors can reason about it, and gate any runtime opt-in behind a server-trusted check rather than an unconditional literal.",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
if (context.containerOverrides === void 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return context.containerOverrides.filter((override) => override.kind === "enable_internet").map(
|
|
15
|
+
(override) => emit(containerStartEnableInternetOverride, {
|
|
16
|
+
cacheKey: `container_start_enable_internet_override:${override.file}:${override.line.toString()}`,
|
|
17
|
+
detail: `\`${override.exportName}\` calls \`.start({ enableInternet: true })\`, overriding the container's static egress posture.`,
|
|
18
|
+
metadata: { exportName: override.exportName, file: override.file, line: override.line }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
source: "static",
|
|
23
|
+
title: "Runtime .start() override re-enables container internet access"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { containerStartEnableInternetOverride as default };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const externalSourceOnGlobal = {
|
|
4
|
+
categories: ["SCHEMA"],
|
|
5
|
+
description: "A table is both `.source(...)` and `.global()`. A global table lives in the external/global tier; a sourced table is materialized into a shard DO's SQLite — the two are mutually exclusive.",
|
|
6
|
+
facing: "INTERNAL",
|
|
7
|
+
level: "ERROR",
|
|
8
|
+
name: "external_source_on_global",
|
|
9
|
+
remediation: 'Drop either `.source(...)` or `.global()`. To ingest an external database into per-tenant DOs, use `.source(...)` with `.shardBy(...)`; to read it in place as a global table, use `.global({ backend: "hyperdrive" })`.',
|
|
10
|
+
run: (context) => {
|
|
11
|
+
const findings = [];
|
|
12
|
+
for (const table of context.schema.tables) {
|
|
13
|
+
if (table.externalSource === void 0 || table.shardKind !== "global") {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
findings.push(
|
|
17
|
+
emit(externalSourceOnGlobal, {
|
|
18
|
+
cacheKey: `external_source_on_global:${table.name}`,
|
|
19
|
+
detail: `Table \`${table.name}\` is both \`.source(...)\` and \`.global()\` — contradictory. A sourced table materializes into a shard DO's SQLite; a global table lives in the external tier.`,
|
|
20
|
+
metadata: { table: table.name }
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return findings;
|
|
25
|
+
},
|
|
26
|
+
source: "static",
|
|
27
|
+
title: "Sourced table cannot also be global"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { externalSourceOnGlobal as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const externalSourceUnscoped = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "A `.source(...)` table that is also `.shardBy(...)` has no `tenantBy` mapper, so every tenant's Durable Object runs the same unscoped query and replicates the whole multitenant table — a cross-tenant data leak.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "ERROR",
|
|
8
|
+
name: "external_source_unscoped",
|
|
9
|
+
remediation: "Add `tenantBy: (shardKey) => [shardKey]` (matching the query's bound parameters) so each shard DO pulls only its own tenant's rows. The shard key MUST bind into the source `WHERE`.",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
const findings = [];
|
|
12
|
+
for (const table of context.schema.tables) {
|
|
13
|
+
if (table.externalSource === void 0 || table.shardKind !== "shardBy") {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (table.externalSource.unanalyzable) {
|
|
17
|
+
findings.push(
|
|
18
|
+
emit(externalSourceUnscoped, {
|
|
19
|
+
cacheKey: `external_source_unscoped:${table.name}`,
|
|
20
|
+
detail: `Table \`${table.name}\` is \`.source(...)\` + \`.shardBy(...)\` but its source config is not a static object literal, so \`tenantBy\` can't be verified. Confirm \`tenantBy\` binds the shard key into the query, or inline the config so the linter can check it — an unscoped query leaks every tenant's rows into each DO.`,
|
|
21
|
+
level: "WARN",
|
|
22
|
+
metadata: { table: table.name }
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (table.externalSource.hasTenantBy) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
findings.push(
|
|
31
|
+
emit(externalSourceUnscoped, {
|
|
32
|
+
cacheKey: `external_source_unscoped:${table.name}`,
|
|
33
|
+
detail: `Table \`${table.name}\` is \`.source(...)\` + \`.shardBy(...)\` but declares no \`tenantBy\` — every tenant DO would pull the whole table. Add a \`tenantBy\` that binds the shard key into the query.`,
|
|
34
|
+
metadata: { table: table.name }
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return findings;
|
|
39
|
+
},
|
|
40
|
+
source: "static",
|
|
41
|
+
title: "Sourced + sharded table is not tenant-scoped"
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { externalSourceUnscoped as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const PROTECT_TOKENS = /* @__PURE__ */ new Set(["enforce", "gate", "lockdown", "rls"]);
|
|
4
|
+
const PERMIT_TOKENS = /* @__PURE__ */ new Set(["allow", "bypass", "permit"]);
|
|
5
|
+
const ACRONYM_WORD_BOUNDARY = /(?<=[A-Z])(?=[A-Z][a-z])/gu;
|
|
6
|
+
const CAMEL_HUMP_BOUNDARY = /(?<=[a-z0-9])(?=[A-Z])/gu;
|
|
7
|
+
const NON_ALPHANUMERIC_RUN = /[^a-z0-9]+/u;
|
|
8
|
+
const tokenize = (key) => key.replaceAll(ACRONYM_WORD_BOUNDARY, " ").replaceAll(CAMEL_HUMP_BOUNDARY, " ").toLowerCase().split(NON_ALPHANUMERIC_RUN).filter((token) => token.length > 0);
|
|
9
|
+
const hasUnsafeDefault = (row) => {
|
|
10
|
+
const tokens = tokenize(row.key);
|
|
11
|
+
const isProtect = tokens.some((token) => PROTECT_TOKENS.has(token));
|
|
12
|
+
const isPermit = tokens.some((token) => PERMIT_TOKENS.has(token));
|
|
13
|
+
if (isProtect === isPermit) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return isProtect ? !row.defaultValue : row.defaultValue;
|
|
17
|
+
};
|
|
18
|
+
const flagGatesSecurityWithUnsafeDefault = {
|
|
19
|
+
categories: ["SECURITY"],
|
|
20
|
+
description: "A `ctx.flags.boolean(key, default)` read on a security-shaped key has a fail-open default that selects the permissive branch. OpenFeature returns the default when the provider errors, so an outage silently disables a protection (a `false` default on an `enforce`/`rls`/`gate`/`lockdown` key) or grants a permission (a `true` default on an `allow`/`permit`/`bypass` key).",
|
|
21
|
+
facing: "EXTERNAL",
|
|
22
|
+
level: "WARN",
|
|
23
|
+
name: "flag_gates_security_with_unsafe_default",
|
|
24
|
+
remediation: "Flip the default so a provider outage fails closed: default a protection flag (`enforce*`/`rls*`/`gate*`/`lockdown*`) to `true`, and a permission/bypass flag (`allow*`/`permit*`/`bypass*`) to `false`. The safe default is always the restrictive branch — never let an unreachable flag backend open access.",
|
|
25
|
+
run: (context) => {
|
|
26
|
+
if (context.flagSecurityDefaults === void 0) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return context.flagSecurityDefaults.filter((row) => hasUnsafeDefault(row)).map(
|
|
30
|
+
(row) => emit(flagGatesSecurityWithUnsafeDefault, {
|
|
31
|
+
cacheKey: `flag_gates_security_with_unsafe_default:${row.file}:${row.line.toString()}`,
|
|
32
|
+
detail: `\`ctx.flags.boolean("${row.key}", ${String(row.defaultValue)})\` in \`${row.exportName}\` (${row.file}:${row.line.toString()}) fails open to the permissive branch — a provider outage returns \`${String(row.defaultValue)}\`, ${row.defaultValue ? "granting the guarded permission" : "disabling the guarded protection"}.`,
|
|
33
|
+
metadata: { defaultValue: row.defaultValue, exportName: row.exportName, file: row.file, key: row.key, line: row.line }
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
source: "static",
|
|
38
|
+
title: "Security flag fails open to the permissive branch"
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { flagGatesSecurityWithUnsafeDefault as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fromServerSchema = (schema) => {
|
|
2
2
|
return {
|
|
3
|
+
rlsMode: schema.rlsMode,
|
|
3
4
|
tables: Object.entries(schema.tables).map(([name, table]) => {
|
|
4
5
|
const indexes = [
|
|
5
6
|
...table.indexes.map((index) => {
|
|
@@ -28,10 +29,18 @@ const fromServerSchema = (schema) => {
|
|
|
28
29
|
}
|
|
29
30
|
return {
|
|
30
31
|
externallyManaged: table.isExternallyManaged ?? false,
|
|
32
|
+
externalSource: table.externalSource ? {
|
|
33
|
+
hasReconcile: table.externalSource.reconcileEveryMs !== void 0,
|
|
34
|
+
hasTenantBy: table.externalSource.tenantBy !== void 0,
|
|
35
|
+
mode: table.externalSource.mode
|
|
36
|
+
} : void 0,
|
|
31
37
|
fields: Object.keys(table.shape),
|
|
32
38
|
indexes,
|
|
39
|
+
isPublic: table.isPublic ?? false,
|
|
33
40
|
name,
|
|
34
41
|
optionalFields,
|
|
42
|
+
shardKind: table.shardMode.kind,
|
|
43
|
+
softDelete: table.softDeleteMode,
|
|
35
44
|
relations: Object.entries(table.relationMap).map(([accessor, relation]) => {
|
|
36
45
|
return {
|
|
37
46
|
field: relation.field,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const OWNERSHIP_FIELD_NAMES = /* @__PURE__ */ new Set([
|
|
2
|
+
"accountId",
|
|
3
|
+
"authorId",
|
|
4
|
+
"createdBy",
|
|
5
|
+
"createdById",
|
|
6
|
+
"organizationId",
|
|
7
|
+
"orgId",
|
|
8
|
+
"ownerId",
|
|
9
|
+
"tenantId",
|
|
10
|
+
"updatedBy",
|
|
11
|
+
"userId",
|
|
12
|
+
"workspaceId"
|
|
13
|
+
]);
|
|
14
|
+
const PII_FIELD_NAMES = /* @__PURE__ */ new Set([
|
|
15
|
+
"address",
|
|
16
|
+
"dateOfBirth",
|
|
17
|
+
"dob",
|
|
18
|
+
"email",
|
|
19
|
+
"firstName",
|
|
20
|
+
"lastName",
|
|
21
|
+
"phone",
|
|
22
|
+
"phoneNumber",
|
|
23
|
+
"socialSecurityNumber",
|
|
24
|
+
"ssn"
|
|
25
|
+
]);
|
|
26
|
+
const SYSTEM_FIELDS = /* @__PURE__ */ new Set(["_creationTime", "_id"]);
|
|
27
|
+
const ownershipOrPiiColumns = (table) => table.fields.filter((field) => OWNERSHIP_FIELD_NAMES.has(field) || PII_FIELD_NAMES.has(field));
|
|
28
|
+
const tableColumnSet = (table) => /* @__PURE__ */ new Set([...SYSTEM_FIELDS, ...table.fields]);
|
|
29
|
+
const isPublicWrite = (procedure) => procedure.visibility === "public" && (procedure.kind === "mutation" || procedure.kind === "action");
|
|
30
|
+
|
|
31
|
+
export { PII_FIELD_NAMES as P, isPublicWrite as i, ownershipOrPiiColumns as o, tableColumnSet as t };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const surfaceLabel = (kind, method) => kind === "httpRoute" && method ? `\`httpRoute\` ${method} handler` : "`httpAction` handler";
|
|
4
|
+
const httpActionMissingAuthGuard = {
|
|
5
|
+
categories: ["SECURITY"],
|
|
6
|
+
description: "An `httpAction`/`httpRoute` handler performs a side effect (`ctx.runMutation`/`ctx.runAction`/a `ctx.db` write) but never reads `ctx.auth` — an unauthenticated HTTP endpoint driving a state change, bypassing the identity/RLS checks that guard the rest of the app.",
|
|
7
|
+
facing: "EXTERNAL",
|
|
8
|
+
level: "WARN",
|
|
9
|
+
name: "http_action_missing_auth_guard",
|
|
10
|
+
remediation: "Read `ctx.auth` in the handler before the side effect — call `await ctx.auth.getIdentity()` (or check `ctx.auth.userId`) and reject unauthenticated/unauthorized requests, or forward through a `mutation`/`action` whose RLS policies enforce access. If the endpoint is intentionally public (e.g. a signed webhook), verify the provider signature before the write.",
|
|
11
|
+
run: (context) => {
|
|
12
|
+
if (context.httpActionGuards === void 0) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return context.httpActionGuards.filter((row) => !row.readsAuth).map((row) => {
|
|
16
|
+
const surface = surfaceLabel(row.kind, row.method);
|
|
17
|
+
return emit(httpActionMissingAuthGuard, {
|
|
18
|
+
cacheKey: `http_action_missing_auth_guard:${row.file}:${row.line.toString()}`,
|
|
19
|
+
detail: `${surface} \`${row.exportName}\` (${row.file}:${row.line.toString()}) calls \`ctx.${row.sideEffect}\` but never reads \`ctx.auth\` — an anonymous caller can drive this write. Authenticate the request before the side effect.`,
|
|
20
|
+
metadata: {
|
|
21
|
+
exportName: row.exportName,
|
|
22
|
+
file: row.file,
|
|
23
|
+
kind: row.kind,
|
|
24
|
+
line: row.line,
|
|
25
|
+
sideEffect: row.sideEffect,
|
|
26
|
+
...row.method ? { method: row.method } : {}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
source: "static",
|
|
32
|
+
title: "Unauthenticated HTTP handler performs a side effect"
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { httpActionMissingAuthGuard as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const VIA_LABELS = {
|
|
4
|
+
"headers-append": "a `headers.append(...)` call",
|
|
5
|
+
"headers-ctor": "a `new Headers({...})` initializer",
|
|
6
|
+
"headers-set": "a `headers.set(...)` call",
|
|
7
|
+
"response-init": "a `Response` init `headers` object"
|
|
8
|
+
};
|
|
9
|
+
const httpActionResponseHeaderInjection = {
|
|
10
|
+
categories: ["SECURITY"],
|
|
11
|
+
description: "An `httpAction` handler writes a response-header value derived from raw request input (`request.headers`/URL/query/body) with no CR/LF sanitizer. A `Request`-derived string placed verbatim into a response header lets a caller smuggle `\\r\\n` and inject extra headers or split the response (HTTP response splitting / header injection).",
|
|
12
|
+
facing: "EXTERNAL",
|
|
13
|
+
level: "WARN",
|
|
14
|
+
name: "http_action_response_header_injection",
|
|
15
|
+
remediation: "Never place a raw request value into a response header. Route it through a CR/LF guard (`isSafeHeaderValue` from `@lunora/server`, rejecting values containing `\\r`/`\\n`/`\\0`), URL-encode it (`encodeURIComponent`), or coerce it to a number — before writing the header. `String(...)` / `.toString()` do NOT strip CR/LF and are not sufficient.",
|
|
16
|
+
run: (context) => {
|
|
17
|
+
if (context.httpHeaderWrites === void 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return context.httpHeaderWrites.map((row) => {
|
|
21
|
+
const header = row.headerName === "" ? "a response header" : `the \`${row.headerName}\` response header`;
|
|
22
|
+
return emit(httpActionResponseHeaderInjection, {
|
|
23
|
+
cacheKey: `http_action_response_header_injection:${row.file}:${row.line.toString()}`,
|
|
24
|
+
detail: `\`${row.exportName}\` (${row.file}:${row.line.toString()}) writes ${header} from raw request input via ${VIA_LABELS[row.via]} with no CR/LF guard — a caller can smuggle \`\\r\\n\` to inject headers or split the response. Route the value through \`isSafeHeaderValue\` or \`encodeURIComponent\` first.`,
|
|
25
|
+
metadata: {
|
|
26
|
+
exportName: row.exportName,
|
|
27
|
+
file: row.file,
|
|
28
|
+
headerName: row.headerName,
|
|
29
|
+
line: row.line,
|
|
30
|
+
via: row.via
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
source: "static",
|
|
36
|
+
title: "Response header written from unsanitized request input"
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { httpActionResponseHeaderInjection as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const identityUndeclaredClaimTrusted = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "An authorization read of `auth.identity.<key>` for a claim outside the declared `defineIdentity({ ... })` contract. `defineIdentity` validates only declared claims and forwards undeclared ones verbatim, so the value the policy trusts was never validated — an attacker's token can forge it.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "WARN",
|
|
8
|
+
name: "identity_undeclared_claim_trusted",
|
|
9
|
+
remediation: "Declare the claim in `defineIdentity({ ... })` (e.g. `role: v.optional(v.string())`) so the worker validates it at the trust boundary before a policy reads it, or stop trusting it for authorization. Declared claims (and `userId`) are validated; undeclared claims are forwarded unchecked.",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
if (context.identityClaimReads === void 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return context.identityClaimReads.filter((row) => !row.declared).map((row) => {
|
|
15
|
+
const location = `\`${row.exportName}\` (${row.file}:${row.line.toString()})`;
|
|
16
|
+
return emit(identityUndeclaredClaimTrusted, {
|
|
17
|
+
cacheKey: `identity_undeclared_claim_trusted:${row.file}:${row.line.toString()}:${row.key}`,
|
|
18
|
+
detail: `\`${row.key}\` in ${location} is read off \`identity\` but is not declared in \`defineIdentity({ ... })\`. Undeclared claims are forwarded unvalidated, so this authorization decision trusts a forgeable value.`,
|
|
19
|
+
metadata: {
|
|
20
|
+
exportName: row.exportName,
|
|
21
|
+
file: row.file,
|
|
22
|
+
key: row.key,
|
|
23
|
+
line: row.line
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
source: "static",
|
|
29
|
+
title: "Authorization trusts an undeclared identity claim"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { identityUndeclaredClaimTrusted as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { m as makeArgumentDerivedSinkLint } from './argument-derived-sink-C1xTTqAt.mjs';
|
|
2
|
+
|
|
3
|
+
const imagesUrlSourceFromUserInput = makeArgumentDerivedSinkLint({
|
|
4
|
+
cacheKey: (access) => `images_url_source_from_user_input:${access.file}:${access.line.toString()}`,
|
|
5
|
+
categories: ["SECURITY"],
|
|
6
|
+
description: "A `buildImageDeliveryUrl({ key, … })` call's `key` — the CDN transform's source image, an absolute URL or an origin-relative key — is derived from the handler's `args` with no server-side scoping, so any caller can point the CDN's on-the-fly transform at an attacker-chosen origin (SSRF / open proxy) or an arbitrary key under the account's own store.",
|
|
7
|
+
detail: (access) => `\`buildImageDeliveryUrl\` in \`${access.exportName}\` (${access.file}:${access.line.toString()}) builds its delivery URL from a \`key\` derived from \`args\` with no server-side scoping — any caller can point the CDN's on-the-fly transform at an attacker-chosen origin or store key. Validate \`key\` against an allowlist, or derive it from server-trusted state.`,
|
|
8
|
+
facing: "EXTERNAL",
|
|
9
|
+
getAccesses: (context) => context.imageDeliveryUrlAccesses,
|
|
10
|
+
level: "WARN",
|
|
11
|
+
metadata: (access) => {
|
|
12
|
+
return { exportName: access.exportName, file: access.file, line: access.line };
|
|
13
|
+
},
|
|
14
|
+
name: "images_url_source_from_user_input",
|
|
15
|
+
remediation: "Validate `key` against an allowlist of known origins/prefixes before calling `buildImageDeliveryUrl`, or derive it from server-trusted state (a stored record's own image key) rather than passing `args` straight through.",
|
|
16
|
+
title: "Image delivery URL built from unscoped user input"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export { imagesUrlSourceFromUserInput as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const insertManyUnsafeUserData = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "A public procedure calls `ctx.db.insertManyUnsafe(...)`, which writes rows straight to storage and bypasses both the per-row validators and the schema's insert triggers (server-trusted columns, ownership stamping, RLS write checks). On a public entry point the rows are request-shaped, so a caller can write columns they shouldn't control and skip every trigger-enforced invariant.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "WARN",
|
|
8
|
+
name: "insert_many_unsafe_user_data",
|
|
9
|
+
remediation: "Use the validated `ctx.db.insert(...)` path in public procedures so validators and insert triggers run. If you need the unsafe bulk write, move it into an internal function (`internalMutation`/`internalAction`) that is fed only server-constructed rows, never request input.",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
if (context.procedureProtections === void 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return context.procedureProtections.filter((procedure) => procedure.usesInsertManyUnsafe && procedure.visibility === "public").map(
|
|
15
|
+
(procedure) => emit(insertManyUnsafeUserData, {
|
|
16
|
+
cacheKey: `insert_many_unsafe_user_data:${procedure.file}:${procedure.exportName}`,
|
|
17
|
+
detail: `\`${procedure.exportName}\` (${procedure.file}) is public and calls \`ctx.db.insertManyUnsafe(...)\`, bypassing validators and insert triggers on request-shaped rows. Switch to \`ctx.db.insert(...)\`, or move the bulk write into an internal function fed server-built rows.`,
|
|
18
|
+
metadata: { exportName: procedure.exportName, file: procedure.file, kind: procedure.kind }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
source: "static",
|
|
23
|
+
title: "Public procedure uses insertManyUnsafe (bypasses validators and triggers)"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { insertManyUnsafeUserData as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { m as makeArgumentDerivedSinkLint } from './argument-derived-sink-C1xTTqAt.mjs';
|
|
2
|
+
|
|
3
|
+
const kvUnscopedUserKeyIdor = makeArgumentDerivedSinkLint({
|
|
4
|
+
cacheKey: (access) => `kv_unscoped_user_key_idor:${access.file}:${access.line.toString()}`,
|
|
5
|
+
categories: ["SECURITY"],
|
|
6
|
+
description: "A `ctx.kv` read/write uses a namespace key derived from the handler's `args` with no server-side scoping. Workers KV is a flat namespace, so an unscoped key lets any caller read, overwrite, or delete another user's entry — an insecure direct object reference (IDOR).",
|
|
7
|
+
detail: (access) => `\`ctx.kv.${access.method}\` in \`${access.exportName}\` (${access.file}:${access.line.toString()}) uses a KV key derived from \`args\` with no server-side scoping — any caller can read/overwrite/delete another user's entry (IDOR). Prefix the key with a server-trusted identity (e.g. \`\${ctx.auth.userId}:…\`).`,
|
|
8
|
+
facing: "EXTERNAL",
|
|
9
|
+
getAccesses: (context) => context.kvKeyAccesses,
|
|
10
|
+
level: "ERROR",
|
|
11
|
+
metadata: (access) => {
|
|
12
|
+
return { exportName: access.exportName, file: access.file, line: access.line, method: access.method };
|
|
13
|
+
},
|
|
14
|
+
name: "kv_unscoped_user_key_idor",
|
|
15
|
+
remediation: `Prefix every \`ctx.kv\` key with a server-trusted identity (e.g. \`\${ctx.auth.userId}:\${args.id}\`) so a caller can only address their own entries. Never pass request input straight to \`ctx.kv.get\`/\`put\`/\`delete\`.`,
|
|
16
|
+
title: "Possible IDOR from arg-derived unscoped KV key"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export { kvUnscopedUserKeyIdor as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const mailInboundDispatchWithoutVerify = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "`createInboundEmailHandler({...})` has no `verify` hook, so it trusts every inbound message — the `from` address is spoofable and DKIM/SPF/DMARC verdicts go unchecked. If the handler dispatches into a Lunora function (admin bearer, RLS disabled), a forged sender can drive privileged writes (a confused-deputy escalation).",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "ERROR",
|
|
8
|
+
// eslint-disable-next-line no-secrets/no-secrets -- the lint's rule id, not a credential
|
|
9
|
+
name: "mail_inbound_dispatch_without_verify",
|
|
10
|
+
remediation: "Pass a `verify` hook to `createInboundEmailHandler({...})` that rejects the message unless its DKIM/SPF/DMARC authentication verdicts pass and the sender is expected — before any dispatch into a Lunora function. Never trust the `from` header alone.",
|
|
11
|
+
run: (context) => {
|
|
12
|
+
if (context.configCalls === void 0) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return context.configCalls.filter((call) => call.callee === "createInboundEmailHandler" && call.analyzable && !call.presentKeys.includes("verify")).map(
|
|
16
|
+
(call) => emit(mailInboundDispatchWithoutVerify, {
|
|
17
|
+
// eslint-disable-next-line no-secrets/no-secrets -- the lint's rule id, not a credential
|
|
18
|
+
cacheKey: `mail_inbound_dispatch_without_verify:${call.file}:${call.line.toString()}`,
|
|
19
|
+
detail: `\`createInboundEmailHandler({...})\` in ${call.file}:${call.line.toString()} has no \`verify\` hook — it trusts the spoofable \`from\` address and unchecked DKIM/SPF/DMARC verdicts. A forged sender can then reach whatever the handler dispatches to (a Lunora function runs with the admin bearer and RLS disabled). Add a \`verify\` gate that enforces the authentication verdicts before dispatch.`,
|
|
20
|
+
metadata: { callee: call.callee, file: call.file, line: call.line }
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
source: "static",
|
|
25
|
+
title: "Inbound email handler without a verify hook"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { mailInboundDispatchWithoutVerify as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const mailRecipientFromRequestInput = {
|
|
4
|
+
categories: ["SECURITY"],
|
|
5
|
+
description: "A `ctx.mail`/`ctx.email` `send`/`queue` call sets a recipient field (to/cc/bcc) from the handler's `args` with no server-side scoping. Sending to an address taken straight from request input turns the deployment into an open relay / spam amplifier.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "WARN",
|
|
8
|
+
name: "mail_recipient_from_request_input",
|
|
9
|
+
remediation: "Derive recipients from server-trusted state (e.g. the authenticated user's own record via `ctx.auth`), never straight from `args`. If user-chosen recipients are intended, gate the path behind authentication and rate limiting.",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
if (context.mailRecipientAccesses === void 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return context.mailRecipientAccesses.map(
|
|
15
|
+
(access) => emit(mailRecipientFromRequestInput, {
|
|
16
|
+
cacheKey: `mail_recipient_from_request_input:${access.file}:${access.line.toString()}`,
|
|
17
|
+
detail: `\`ctx.mail.${access.method}\` in \`${access.exportName}\` (${access.file}:${access.line.toString()}) sets a recipient field (to/cc/bcc) derived from \`args\` with no server-side scoping — any caller can direct mail to an arbitrary address (open relay / spam amplifier). Derive the recipient from server-trusted state instead (e.g. \`ctx.auth.user.email\`).`,
|
|
18
|
+
metadata: { exportName: access.exportName, file: access.file, line: access.line, method: access.method }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
source: "static",
|
|
23
|
+
title: "Mail recipient derived from request input"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { mailRecipientFromRequestInput as default };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const PII_COLUMN_RE = /address|birthdate|creditcard|dateofbirth|dob|driverslicense|email|firstname|fullname|lastname|nationalid|passport|phone|socialsecurity|ssn|taxid/u;
|
|
4
|
+
const isPiiColumn = (column) => PII_COLUMN_RE.test(column.replaceAll(/[^a-z0-9]/giu, "").toLowerCase());
|
|
5
|
+
const maskWeakHashStrategyOnPii = {
|
|
6
|
+
categories: ["SECURITY"],
|
|
7
|
+
description: 'A `mask(policies)` column named like PII (email, SSN, phone, …) uses the `"hash"` strategy. `"hash"` is an unsalted 32-bit FNV-1a digest — brute-force-recoverable and cross-row-correlatable — not a confidentiality control, so it does not actually hide the value.',
|
|
8
|
+
facing: "EXTERNAL",
|
|
9
|
+
level: "WARN",
|
|
10
|
+
name: "mask_weak_hash_strategy_on_pii",
|
|
11
|
+
remediation: 'Use `"redact"` instead of `"hash"` for this column — e.g. `mask({ <table>: { <column>: "redact" } })`. Reserve `"hash"` for columns where a stable, joinable pseudonym is the goal and the value itself is not sensitive.',
|
|
12
|
+
run: (context) => {
|
|
13
|
+
if (context.maskStrategies === void 0) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const findings = [];
|
|
17
|
+
for (const strategy of context.maskStrategies) {
|
|
18
|
+
if (strategy.strategy !== "hash" || !isPiiColumn(strategy.column)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
findings.push(
|
|
22
|
+
emit(maskWeakHashStrategyOnPii, {
|
|
23
|
+
cacheKey: `mask_weak_hash_strategy_on_pii:${strategy.file}:${strategy.line.toString()}`,
|
|
24
|
+
detail: `\`${strategy.exportName}\` in ${strategy.file} masks \`${strategy.table === "" ? strategy.column : `${strategy.table}.${strategy.column}`}\` with \`"hash"\` — its name suggests PII, and \`"hash"\` is brute-force-recoverable and leaks cross-row equality. Use \`"redact"\` instead.`,
|
|
25
|
+
metadata: { column: strategy.column, exportName: strategy.exportName, file: strategy.file, table: strategy.table }
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return findings;
|
|
30
|
+
},
|
|
31
|
+
source: "static",
|
|
32
|
+
title: 'Weak "hash" mask strategy on a PII column'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { maskWeakHashStrategyOnPii as default };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const maskedTablesOf = (context) => {
|
|
4
|
+
const tables = /* @__PURE__ */ new Set();
|
|
5
|
+
for (const procedure of context.maskProcedures ?? []) {
|
|
6
|
+
for (const { table } of procedure.maskColumns) {
|
|
7
|
+
if (table !== "") {
|
|
8
|
+
tables.add(table);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const strategy of context.maskStrategies ?? []) {
|
|
13
|
+
if (strategy.table !== "") {
|
|
14
|
+
tables.add(strategy.table);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return tables;
|
|
18
|
+
};
|
|
19
|
+
const relationTargetsOf = (context) => {
|
|
20
|
+
const targets = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const table of context.schema.tables) {
|
|
22
|
+
for (const relation of table.relations) {
|
|
23
|
+
targets.set(`${table.name} ${relation.name}`, relation.table);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return targets;
|
|
27
|
+
};
|
|
28
|
+
const maskedRelationLeakViaWith = {
|
|
29
|
+
categories: ["SECURITY"],
|
|
30
|
+
description: "A public read hydrates a masked table through a `with` relation. Column masking does not descend into `with`-hydrated relations, so the related table's masked columns are returned in the clear.",
|
|
31
|
+
facing: "EXTERNAL",
|
|
32
|
+
level: "INFO",
|
|
33
|
+
name: "masked_relation_leak_via_with",
|
|
34
|
+
remediation: "Don't hydrate a masked table through `with` on an unprotected read: drop the relation, project only non-sensitive columns, or route the parent read through a procedure that re-applies masking to the joined table. Masking is per-procedure and top-level only — it never reaches `with`-loaded relations.",
|
|
35
|
+
run: (context) => {
|
|
36
|
+
if (context.relationLoads === void 0) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const maskedTables = maskedTablesOf(context);
|
|
40
|
+
if (maskedTables.size === 0) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const relationTargets = relationTargetsOf(context);
|
|
44
|
+
const findings = [];
|
|
45
|
+
for (const row of context.relationLoads) {
|
|
46
|
+
if (row.visibility !== "public" || row.parentTable === "") {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
for (const relation of row.relations) {
|
|
50
|
+
const target = relationTargets.get(`${row.parentTable} ${relation}`);
|
|
51
|
+
if (target === void 0 || !maskedTables.has(target)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
findings.push(
|
|
55
|
+
emit(maskedRelationLeakViaWith, {
|
|
56
|
+
cacheKey: `masked_relation_leak_via_with:${row.file}:${row.line.toString()}:${row.parentTable}:${relation}`,
|
|
57
|
+
detail: `The public read in \`${row.exportName}\` (${row.file}:${row.line.toString()}) hydrates relation \`${relation}\` (masked table \`${target}\`) via \`with\` on \`${row.parentTable}\`. Masking is top-level only and does not descend into \`with\`, so \`${target}\`'s masked columns are returned in the clear.`,
|
|
58
|
+
metadata: {
|
|
59
|
+
exportName: row.exportName,
|
|
60
|
+
file: row.file,
|
|
61
|
+
line: row.line,
|
|
62
|
+
parentTable: row.parentTable,
|
|
63
|
+
relation,
|
|
64
|
+
relationTable: target
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return findings;
|
|
71
|
+
},
|
|
72
|
+
source: "static",
|
|
73
|
+
title: "Masked table surfaced unmasked through a with-relation on a public read"
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { maskedRelationLeakViaWith as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const mutatorFullRowReplace = {
|
|
4
|
+
categories: ["SCHEMA"],
|
|
5
|
+
description: "A custom mutator's `server` impl writes with `ctx.db.replace(id, document)` — a whole-row overwrite. On a synced table this clobbers a concurrent edit to a different column; `ctx.db.patch(id, { field })` merges at the column level so independent field edits coexist.",
|
|
6
|
+
facing: "EXTERNAL",
|
|
7
|
+
level: "WARN",
|
|
8
|
+
name: "mutator_full_row_replace",
|
|
9
|
+
remediation: "Prefer `ctx.db.patch(id, { onlyTheChangedField })` so a concurrent edit to another column isn't lost. Keep `replace` only when the mutator genuinely owns the entire row (e.g. a full-form save).",
|
|
10
|
+
run: (context) => {
|
|
11
|
+
if (context.mutatorWrites === void 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
return context.mutatorWrites.map(
|
|
15
|
+
(write) => emit(mutatorFullRowReplace, {
|
|
16
|
+
cacheKey: `mutator_full_row_replace:${write.exportName}:${String(write.line)}`,
|
|
17
|
+
detail: `Mutator \`${write.exportName}\` (${write.file}:${String(write.line)}) writes with \`ctx.db.replace(...)\`, overwriting the whole row. A concurrent edit to a different column is clobbered — use \`ctx.db.patch(id, { field })\` to merge at the column level.`,
|
|
18
|
+
metadata: { exportName: write.exportName, file: write.file, line: write.line }
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
source: "static",
|
|
23
|
+
title: "Mutator overwrites the whole row (clobbers concurrent column edits)"
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { mutatorFullRowReplace as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { e as emit } from './finding-Dm_zvzS1.mjs';
|
|
2
|
+
|
|
3
|
+
const SINK_LABELS = {
|
|
4
|
+
delete: "deletes the row",
|
|
5
|
+
get: "reads the row",
|
|
6
|
+
patch: "patches the row"
|
|
7
|
+
};
|
|
8
|
+
const normalizeIdUsedAsAuthorization = {
|
|
9
|
+
categories: ["SECURITY"],
|
|
10
|
+
description: "A `.public()` `query`/`mutation` gates a `ctx.db.get`/`patch`/`delete` on a null-checked `ctx.db.normalizeId(table, id)` result with no ownership predicate and no RLS. `normalizeId` validates id *shape* only — it never reads the database — so a non-null result proves the id is well-formed, never that the caller owns the row (an IDOR).",
|
|
11
|
+
facing: "EXTERNAL",
|
|
12
|
+
level: "INFO",
|
|
13
|
+
name: "normalize_id_used_as_authorization",
|
|
14
|
+
remediation: 'Don\'t treat a non-null `normalizeId` result as authorization — it only validates id shape. After loading the row, compare its ownership column (`userId`/`ownerId`/…) against the server-trusted identity (`ctx.auth.userId`), or protect the procedure with `.use(rls(...))` / put the schema in `.rls("required")` mode so the row policy runs on every access.',
|
|
15
|
+
run: (context) => {
|
|
16
|
+
if (context.normalizeIdAuthorizations === void 0) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const rlsRequired = context.schema.rlsMode === "required";
|
|
20
|
+
const rlsOptOutTables = new Set(context.schema.tables.filter((table) => table.isPublic).map((table) => table.name));
|
|
21
|
+
const findings = [];
|
|
22
|
+
for (const row of context.normalizeIdAuthorizations) {
|
|
23
|
+
if (row.visibility !== "public" || row.usesRls || row.mentionsOwnership) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (rlsRequired && (row.table === "" || !rlsOptOutTables.has(row.table))) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const target = row.table === "" ? "the row" : `the \`${row.table}\` row`;
|
|
30
|
+
findings.push(
|
|
31
|
+
emit(normalizeIdUsedAsAuthorization, {
|
|
32
|
+
cacheKey: `normalize_id_used_as_authorization:${row.file}:${row.line.toString()}`,
|
|
33
|
+
detail: `Public procedure \`${row.exportName}\` (${row.file}:${row.line.toString()}) gates access on \`ctx.db.normalizeId(...)\` and then ${SINK_LABELS[row.sinkMethod]} — but \`normalizeId\` only validates id shape, it never reads the database or checks ownership. Any caller supplying a well-formed id of ${target} reaches it (IDOR). Compare the loaded row's ownership column against \`ctx.auth\`, or cover the procedure with \`.use(rls(...))\`.`,
|
|
34
|
+
metadata: {
|
|
35
|
+
exportName: row.exportName,
|
|
36
|
+
file: row.file,
|
|
37
|
+
line: row.line,
|
|
38
|
+
sinkMethod: row.sinkMethod,
|
|
39
|
+
table: row.table
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return findings;
|
|
45
|
+
},
|
|
46
|
+
source: "static",
|
|
47
|
+
title: "normalizeId result used as authorization (validates id shape, not ownership)"
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { normalizeIdUsedAsAuthorization as default };
|