@quatronic/sdk 0.9.0-test.0c53b6d → 0.9.0-test.ab218af
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/README.md +6 -0
- package/dist/chunk-7XIDABOQ.js +83 -0
- package/dist/chunk-7XIDABOQ.js.map +1 -0
- package/dist/{chunk-YFZB5EW6.js → chunk-P5GBQVO7.js} +2 -2
- package/dist/{chunk-IFESUTF2.js → chunk-VQKYPW5V.js} +7 -3
- package/dist/chunk-VQKYPW5V.js.map +1 -0
- package/dist/{chunk-POZI4OKJ.js → chunk-WOFBDOMY.js} +2 -2
- package/dist/{chunk-TPBRMW5N.js → chunk-YCKDMG4B.js} +30 -1
- package/dist/chunk-YCKDMG4B.js.map +1 -0
- package/dist/chunk-YXIYI7R2.js +23 -0
- package/dist/chunk-YXIYI7R2.js.map +1 -0
- package/dist/cli/skills-postinstall.js +12 -5
- package/dist/cli/skills.js +10 -4
- package/dist/context-B_u-vpkw.d.ts +111 -0
- package/dist/eslint/index.d.ts +11 -1
- package/dist/eslint/index.js +123 -4
- package/dist/eslint/index.js.map +1 -1
- package/dist/expo/auth/index.d.ts +8 -0
- package/dist/expo/auth/index.js +177 -0
- package/dist/expo/auth/index.js.map +1 -0
- package/dist/expo/config/index.d.ts +16 -0
- package/dist/expo/config/index.js +17 -0
- package/dist/expo/config/index.js.map +1 -0
- package/dist/expo/log/index.d.ts +9 -0
- package/dist/expo/log/index.js +16 -0
- package/dist/expo/log/index.js.map +1 -0
- package/dist/expo/query/index.d.ts +15 -0
- package/dist/expo/query/index.js +52 -0
- package/dist/expo/query/index.js.map +1 -0
- package/dist/expo/sentry/index.d.ts +29 -0
- package/dist/expo/sentry/index.js +93 -0
- package/dist/expo/sentry/index.js.map +1 -0
- package/dist/expo/testing/index.d.ts +32 -0
- package/dist/expo/testing/index.js +57 -0
- package/dist/expo/testing/index.js.map +1 -0
- package/dist/next/auth/index.d.ts +50 -0
- package/dist/next/auth/index.js +504 -101
- package/dist/next/auth/index.js.map +1 -1
- package/dist/next/boot/index.js +3 -3
- package/dist/next/db/index.js +1 -1
- package/dist/next/sentry/client.js +3 -3
- package/dist/next/sentry/client.js.map +1 -1
- package/dist/next/sentry/index.js +1 -1
- package/dist/next/sentry/register.js +3 -3
- package/dist/node/sentry/index.js +1 -1
- package/dist/node/sentry/register.js +2 -2
- package/package.json +75 -2
- package/skills/catalog.json +3 -0
- package/skills/qore-add-api-route/SKILL.md +1 -1
- package/skills/qore-add-feature/SKILL.md +1 -1
- package/skills/qore-add-page/SKILL.md +1 -1
- package/skills/qore-debug-issue/SKILL.md +10 -0
- package/skills/qore-mobile-add-screen/SKILL.md +58 -0
- package/skills/qore-mobile-call-server/SKILL.md +74 -0
- package/skills/qore-mobile-run-on-device/SKILL.md +41 -0
- package/skills/qore-observability/SKILL.md +17 -0
- package/skills/qore-secure-io/SKILL.md +15 -0
- package/skills/qore-ship-checklist/SKILL.md +10 -0
- package/skills/qore-translate-strings/SKILL.md +10 -0
- package/skills/qore-use-design-system/SKILL.md +1 -1
- package/skills/qore-use-permissions/SKILL.md +10 -0
- package/dist/chunk-IFESUTF2.js.map +0 -1
- package/dist/chunk-TPBRMW5N.js.map +0 -1
- /package/dist/{chunk-YFZB5EW6.js.map → chunk-P5GBQVO7.js.map} +0 -0
- /package/dist/{chunk-POZI4OKJ.js.map → chunk-WOFBDOMY.js.map} +0 -0
package/dist/eslint/index.js
CHANGED
|
@@ -334,6 +334,101 @@ var RULE_IDS = {
|
|
|
334
334
|
"integration-static-call": "QDC-NET-003"
|
|
335
335
|
};
|
|
336
336
|
|
|
337
|
+
// src/eslint/mobile.ts
|
|
338
|
+
var WEB_ONLY = ["@quatronic/sdk/next/", "@quatronic/sdk/node/", "react-dom", "next", "next/"];
|
|
339
|
+
var DEVICE_ONLY = ["@quatronic/sdk/expo/", "react-native", "react-native/", "expo-", "@react-native/", "@react-native-community/"];
|
|
340
|
+
var matches = (source, prefixes) => prefixes.some((p) => p.endsWith("/") || p.endsWith("-") ? source.startsWith(p) : source === p || source.startsWith(`${p}/`));
|
|
341
|
+
function banPrefixes(id, message, prefixes) {
|
|
342
|
+
const text = `${id} - ${message}`;
|
|
343
|
+
return {
|
|
344
|
+
meta: meta(text, "problem"),
|
|
345
|
+
create(context) {
|
|
346
|
+
const report = reporter(context, text);
|
|
347
|
+
const flag = (node) => {
|
|
348
|
+
const source = node.source;
|
|
349
|
+
if (source?.type === "Literal" && typeof source.value === "string" && matches(source.value, prefixes)) report(node);
|
|
350
|
+
};
|
|
351
|
+
return listener({ ImportDeclaration: flag, ImportExpression: flag, ExportAllDeclaration: flag, ExportNamedDeclaration: flag });
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function envName(node) {
|
|
356
|
+
const object = node.object;
|
|
357
|
+
if (object?.type !== "MemberExpression") return null;
|
|
358
|
+
if (object.object?.type !== "Identifier" || object.object.name !== "process") return null;
|
|
359
|
+
if (object.property?.type !== "Identifier" || object.property.name !== "env") return null;
|
|
360
|
+
if (node.property?.type === "Identifier" && !node.computed) return node.property.name ?? null;
|
|
361
|
+
if (node.property?.type === "Literal" && typeof node.property.value === "string") return node.property.value;
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
var SECRET_WORD = /SECRET|TOKEN|PASSWORD|PRIVATE|(^|_)KEY($|_)/;
|
|
365
|
+
var PUBLIC_ALLOWED = /* @__PURE__ */ new Set(["EXPO_PUBLIC_SENTRY_DSN"]);
|
|
366
|
+
var noSecretPublicEnv = {
|
|
367
|
+
meta: meta("QDC-MOB-002 - no secret in an EXPO_PUBLIC_* variable", "problem"),
|
|
368
|
+
create(context) {
|
|
369
|
+
const report = reporter(
|
|
370
|
+
context,
|
|
371
|
+
"QDC-MOB-002 - every EXPO_PUBLIC_* value is compiled into the app and readable by anyone who installs it. A secret belongs on the app's server; call it through apiFetch."
|
|
372
|
+
);
|
|
373
|
+
return listener({
|
|
374
|
+
MemberExpression: (node) => {
|
|
375
|
+
const name = envName(node);
|
|
376
|
+
if (name?.startsWith("EXPO_PUBLIC_") && !PUBLIC_ALLOWED.has(name) && SECRET_WORD.test(name.slice(12))) report(node);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
var noPrivateEnv = {
|
|
382
|
+
meta: meta("QDC-MOB-003 - the phone only has EXPO_PUBLIC_* variables", "problem"),
|
|
383
|
+
create(context) {
|
|
384
|
+
const report = reporter(
|
|
385
|
+
context,
|
|
386
|
+
"QDC-MOB-003 - only EXPO_PUBLIC_* variables reach the phone; anything else is undefined at runtime. Server configuration stays on the server."
|
|
387
|
+
);
|
|
388
|
+
return listener({
|
|
389
|
+
MemberExpression: (node) => {
|
|
390
|
+
const name = envName(node);
|
|
391
|
+
if (name && !name.startsWith("EXPO_PUBLIC_") && name !== "NODE_ENV") report(node);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
var noRawFetch = {
|
|
397
|
+
meta: meta("QDC-MOB-004 - the phone calls its server through apiFetch", "problem"),
|
|
398
|
+
create(context) {
|
|
399
|
+
const report = reporter(
|
|
400
|
+
context,
|
|
401
|
+
"QDC-MOB-004 - call the app's own server through apiFetch from @quatronic/sdk/expo/auth: it adds the session, the app version and the trace, and refuses any other host. A third-party API is called from the server."
|
|
402
|
+
);
|
|
403
|
+
return listener({
|
|
404
|
+
"CallExpression[callee.name='fetch']": report,
|
|
405
|
+
"CallExpression[callee.type='MemberExpression'][callee.property.name='fetch'][callee.object.name=/^(globalThis|window|global)$/]": report
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
var mobileRules = {
|
|
410
|
+
"no-web-import": banPrefixes(
|
|
411
|
+
"QDC-MOB-001",
|
|
412
|
+
"This is the phone app. Server and web entries (@quatronic/sdk/next/*, node/*, react-dom, next) do not run in React Native; use @quatronic/sdk/expo/*.",
|
|
413
|
+
WEB_ONLY
|
|
414
|
+
),
|
|
415
|
+
"no-secret-public-env": noSecretPublicEnv,
|
|
416
|
+
"no-private-env": noPrivateEnv,
|
|
417
|
+
"no-raw-fetch": noRawFetch,
|
|
418
|
+
"no-mobile-import": banPrefixes(
|
|
419
|
+
"QDC-MOB-005",
|
|
420
|
+
"This is the Next app. @quatronic/sdk/expo/*, react-native and expo-* run on the phone only and belong in mobile/.",
|
|
421
|
+
DEVICE_ONLY
|
|
422
|
+
)
|
|
423
|
+
};
|
|
424
|
+
var MOBILE_RULE_IDS = {
|
|
425
|
+
"no-web-import": "QDC-MOB-001",
|
|
426
|
+
"no-secret-public-env": "QDC-MOB-002",
|
|
427
|
+
"no-private-env": "QDC-MOB-003",
|
|
428
|
+
"no-raw-fetch": "QDC-MOB-004",
|
|
429
|
+
"no-mobile-import": "QDC-MOB-005"
|
|
430
|
+
};
|
|
431
|
+
|
|
337
432
|
// src/eslint/observability.ts
|
|
338
433
|
var SENTRY_MODULE = /^@sentry\//;
|
|
339
434
|
var BANNED = /* @__PURE__ */ new Set(["init", "withSentryConfig"]);
|
|
@@ -467,7 +562,7 @@ var OBSERVABILITY_RULE_IDS = {
|
|
|
467
562
|
// src/eslint/index.ts
|
|
468
563
|
var plugin = {
|
|
469
564
|
meta: { name: "@quatronic/sdk/eslint" },
|
|
470
|
-
rules: { ...rules, ...observabilityRules }
|
|
565
|
+
rules: { ...rules, ...observabilityRules, ...mobileRules }
|
|
471
566
|
};
|
|
472
567
|
var SRC_FILES = ["src/**/*.{ts,tsx}"];
|
|
473
568
|
var TEST_FILES = ["**/*.test.{ts,tsx}", "**/*.spec.{ts,tsx}"];
|
|
@@ -495,7 +590,9 @@ var recommended = [
|
|
|
495
590
|
"qdc/safe-fetch": "warn",
|
|
496
591
|
"qdc/no-undeclared-external-call": "warn",
|
|
497
592
|
// Advisory too: the call works either way, the portal just cannot list it.
|
|
498
|
-
"qdc/integration-static-call": "warn"
|
|
593
|
+
"qdc/integration-static-call": "warn",
|
|
594
|
+
// The web half of the web/mobile boundary; `configs.expo` holds the other.
|
|
595
|
+
"qdc/no-mobile-import": "error"
|
|
499
596
|
}
|
|
500
597
|
},
|
|
501
598
|
{
|
|
@@ -556,14 +653,36 @@ var observability = [
|
|
|
556
653
|
rules: { "no-console": "off" }
|
|
557
654
|
}
|
|
558
655
|
];
|
|
559
|
-
var
|
|
560
|
-
|
|
656
|
+
var expo = [
|
|
657
|
+
{
|
|
658
|
+
files: SRC_FILES,
|
|
659
|
+
plugins: { qdc: plugin },
|
|
660
|
+
rules: {
|
|
661
|
+
"qdc/no-web-import": "error",
|
|
662
|
+
"qdc/no-secret-public-env": "error",
|
|
663
|
+
"qdc/no-private-env": "error",
|
|
664
|
+
"qdc/no-raw-fetch": "error",
|
|
665
|
+
"qdc/no-string-eval": "error",
|
|
666
|
+
// Phone logs go through `log` from @quatronic/sdk/expo/log, which reaches Sentry.
|
|
667
|
+
"no-console": "error"
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
// Tests stub fetch and print on purpose; the jest setup reads its own env.
|
|
672
|
+
files: [...TEST_FILES, "**/__tests__/**"],
|
|
673
|
+
rules: { "qdc/no-raw-fetch": "off", "qdc/no-private-env": "off", "no-console": "off" }
|
|
674
|
+
}
|
|
675
|
+
];
|
|
676
|
+
var configs = { recommended, warn, observability, expo };
|
|
677
|
+
var qdcSecurity = { ...plugin, configs, RULE_IDS: { ...RULE_IDS, ...MOBILE_RULE_IDS } };
|
|
561
678
|
var eslint_default = qdcSecurity;
|
|
562
679
|
export {
|
|
680
|
+
MOBILE_RULE_IDS,
|
|
563
681
|
OBSERVABILITY_RULE_IDS,
|
|
564
682
|
RULE_IDS,
|
|
565
683
|
configs,
|
|
566
684
|
eslint_default as default,
|
|
685
|
+
mobileRules,
|
|
567
686
|
observabilityRules,
|
|
568
687
|
rules
|
|
569
688
|
};
|
package/dist/eslint/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/eslint/ast.ts","../../src/eslint/rules.ts","../../src/eslint/observability.ts","../../src/eslint/index.ts"],"sourcesContent":["// A deliberately narrow view of the AST, for rules that are deliberately\n// syntactic.\n//\n// ESLint's own `Rule.Node` is the ESTree union. It does not describe JSX at\n// all, and it forces a narrowing cascade for every property access — in rules\n// whose whole job is to read three or four fields off a node and report it.\n// So these rules declare exactly the fields they read and cast once, at the\n// visitor boundary, rather than per line.\n//\n// Anything that has to follow a value across functions or files is a Semgrep\n// rule instead; that pack ships in `semgrep/` alongside this plugin.\nexport interface AstNode {\n type: string\n /** `Identifier.name` and `MemberExpression.property.name`. Never a JSX name. */\n name?: string\n value?: unknown\n callee?: AstNode\n object?: AstNode\n property?: AstNode\n source?: AstNode\n arguments?: (AstNode | undefined)[]\n expressions?: (AstNode | undefined)[]\n /** `TemplateLiteral.quasis`: the fixed text between the `${}` holes. */\n quasis?: { value?: { cooked?: string | null; raw?: string } }[]\n /** `BinaryExpression.left`; the rule that reads it only follows the left edge. */\n left?: AstNode\n operator?: string\n /** `ImportDeclaration.specifiers`. */\n specifiers?: AstNode[]\n /** `ImportSpecifier.imported` / `.local`. */\n imported?: AstNode\n local?: AstNode\n /** `ObjectExpression.properties`; a `Property` has `key` and `computed`. */\n properties?: AstNode[]\n key?: AstNode\n computed?: boolean\n /** Set by ESLint on every node it visits. */\n parent?: AstNode\n}\n\n/** Calls whose result is a URL this app decided on, not one a caller supplied. */\nexport const VETTED_CALLS = [\"safeRedirect\", \"safeFetch\", \"vetTarget\", \"clone\"]\n\n/** POSIX form of the file being linted, so the checks read the same on Windows. */\nexport function pathOf(filename: string): string {\n return filename.replaceAll(\"\\\\\", \"/\")\n}\n\n/** Is the linted file at, or inside, one of these project paths? */\nexport function isUnder(filename: string, paths: readonly string[]): boolean {\n const file = pathOf(filename)\n return paths.some((path) => file.endsWith(`/${path}`) || file.includes(`/${path}/`))\n}\n\n/** The called name, whether the callee is `f()` or `x.f()`. */\nexport function calleeName(node: AstNode): string {\n const callee = node.callee\n if (!callee) return \"\"\n if (callee.type === \"Identifier\") return callee.name ?? \"\"\n if (callee.type === \"MemberExpression\" && callee.property?.type === \"Identifier\") {\n return callee.property.name ?? \"\"\n }\n return \"\"\n}\n\n/**\n * A target this app wrote down, rather than one that arrived with the request.\n *\n * `allowIdentifier` is the whole difference between the two advisory rules:\n * judging what a bare variable holds takes dataflow, which is what the Semgrep\n * taint rules do. `qdc/safe-redirect` lets a variable through because\n * `NextResponse.redirect(url)` after `req.nextUrl.clone()` is the canonical\n * Next redirect and appears in every generated app; `qdc/safe-fetch` does not.\n */\nexport function isFixedTarget(node: AstNode | undefined, allowIdentifier: boolean): boolean {\n if (!node) return false\n if (node.type === \"Literal\") return typeof node.value === \"string\"\n if (node.type === \"TemplateLiteral\") return (node.expressions?.length ?? 0) === 0\n if (node.type === \"Identifier\") return allowIdentifier\n if (node.type === \"NewExpression\") {\n // `new URL(\"/login\", req.url)` fixes the path; the base only ever\n // contributes this app's own origin.\n return node.callee?.name === \"URL\" && isFixedTarget(node.arguments?.[0], allowIdentifier)\n }\n if (node.type === \"CallExpression\") return VETTED_CALLS.includes(calleeName(node))\n return false\n}\n","import type { Rule } from \"eslint\"\n\nimport { isPlatformManagedHost } from \"../integrations-core/platform-hosts\"\nimport { type AstNode, calleeName, isFixedTarget, isUnder } from \"./ast\"\n\n/**\n * The fourteen QDC security lint rules.\n *\n * One rule per id, rather than fourteen entries in `no-restricted-syntax`, for\n * two reasons that only show up after the fact:\n *\n * - **Severity is per rule.** `no-restricted-syntax` carries one severity for\n * its whole array, and three of these are advisory on purpose — they fire on\n * shapes that are usually fine, and the Semgrep pack does the dataflow they\n * can only approximate.\n * - **Suppression is per rule.** `// eslint-disable-next-line\n * no-restricted-syntax` switches off every selector on that line, so\n * silencing \"no inline styles\" would silently also silence the\n * `dangerouslySetInnerHTML` ban sitting next to it.\n *\n * Suppress one by its own name, and say why:\n *\n * // eslint-disable-next-line qdc/no-dangerous-html -- sanitised in renderPost()\n */\n\n/** Modules that talk to the database directly, and where that is allowed. */\nconst DB_DRIVERS = [\"pg\", \"postgres\", \"mysql2\", \"mysql2/promise\"]\nconst DB_LAYER = [\"src/db\", \"src/lib/db.ts\"]\n\n/** Node's filesystem API, and where a generated app is expected to use it. */\nconst FS_MODULES = [\"fs\", \"node:fs\", \"fs/promises\", \"node:fs/promises\"]\n// `src/lib/migrate.ts` is the migration runner: it reads the migration files\n// off disk at boot, which is the sanctioned use, and it is not reachable from\n// a request. The backend recipes put it there rather than under src/db.\nconst FS_CALLERS = [\"src/scripts\", \"src/db\", \"src/lib/migrate.ts\"]\n\n/** Where a fetch goes out with the server's own network position. */\nconst SERVER_PATHS = [\"src/app/api\", \"src/lib/server\", \"src/proxy.ts\"]\n\n/** One cast, at the boundary, instead of one per `context.report` call. */\nexport function reporter(context: Rule.RuleContext, message: string): (node: AstNode) => void {\n return (node: AstNode) => {\n context.report({ node: node as unknown as Rule.Node, message })\n }\n}\n\nexport function listener(visitor: Record<string, (node: AstNode) => void>): Rule.RuleListener {\n return visitor as unknown as Rule.RuleListener\n}\n\nexport function meta(description: string, type: \"problem\" | \"suggestion\"): Rule.RuleModule[\"meta\"] {\n return { type, docs: { description }, schema: [] }\n}\n\n/** A rule that reports every node matching one of `selectors`. */\nfunction ban(id: string, message: string, selectors: string[]): Rule.RuleModule {\n const text = `${id} - ${message}`\n return {\n meta: meta(text, \"problem\"),\n create(context) {\n const report = reporter(context, text)\n return listener(Object.fromEntries(selectors.map((selector) => [selector, report])))\n },\n }\n}\n\n/** A rule that bans importing any of `modules`, except from `allowed` paths. */\nfunction banImports(\n id: string,\n message: string,\n modules: string[],\n allowed: string[],\n): Rule.RuleModule {\n const text = `${id} - ${message}`\n return {\n meta: meta(text, \"problem\"),\n create(context) {\n if (isUnder(context.filename, allowed)) return {}\n const report = reporter(context, text)\n const flag = (node: AstNode) => {\n const source = node.source\n if (source?.type === \"Literal\" && typeof source.value === \"string\") {\n if (modules.includes(source.value)) report(node)\n }\n }\n return listener({ ImportDeclaration: flag, ImportExpression: flag })\n },\n }\n}\n\nconst noStringEval: Rule.RuleModule = {\n meta: meta(\"QDC-XSS-005 - no code compiled from a string\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-XSS-005 - compiling a string into code runs whatever the string turned out to be. Pass a function.\",\n )\n const isStringy = (node: AstNode | undefined) =>\n node?.type === \"TemplateLiteral\" ||\n node?.type === \"BinaryExpression\" ||\n (node?.type === \"Literal\" && typeof node.value === \"string\")\n return listener({\n \"CallExpression[callee.name='eval']\": report,\n \"CallExpression[callee.name='Function']\": report,\n \"NewExpression[callee.name='Function']\": report,\n \"CallExpression[callee.name=/^set(Timeout|Interval)$/]\": (node) => {\n if (isStringy(node.arguments?.[0])) report(node)\n },\n })\n },\n}\n\nconst safeRedirect: Rule.RuleModule = {\n meta: meta(\"QDC-URL-001 - redirect to a target this app decided on\", \"suggestion\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-URL-001 - redirecting to a value that came with the request is an open redirect. Wrap it in safeRedirect from @quatronic/sdk/next/auth.\",\n )\n return listener({\n \"CallExpression[callee.object.name='NextResponse'][callee.property.name='redirect']\": (\n node,\n ) => {\n if (isFixedTarget(node.arguments?.[0], true)) return\n report(node)\n },\n })\n },\n}\n\nconst safeFetch: Rule.RuleModule = {\n meta: meta(\"QDC-NET-001 - server-side fetch of a caller-supplied URL\", \"suggestion\"),\n create(context) {\n if (!isUnder(context.filename, SERVER_PATHS)) return {}\n const report = reporter(\n context,\n \"QDC-NET-001 - a URL the server did not decide on reaches the private network too. Use safeFetch from @quatronic/sdk/node/net, or connection(alias).fetch for a wired module.\",\n )\n return listener({\n \"CallExpression[callee.name='fetch']\": (node) => {\n if (isFixedTarget(node.arguments?.[0], false)) return\n report(node)\n },\n })\n },\n}\n\n/** Outbound HTTP clients a generated app might reach for. */\nconst HTTP_CLIENTS = [\"fetch\", \"axios\", \"got\", \"ky\"]\nconst HTTP_LIBS = [\"axios\", \"got\", \"ky\"]\nconst HTTP_METHODS = /^(get|post|put|patch|delete|head|request)$/\n\n/** A host that is this cluster or this machine, so not an external API. */\nconst LOCAL_HOST_SUFFIXES = [\".local\", \".internal\", \".svc\", \".cluster.local\"]\nconst ENV_KEY = /^[A-Z][A-Z0-9_]*$/\n\nfunction isLocalHost(host: string): boolean {\n const h = host.toLowerCase()\n if (h === \"localhost\" || h === \"::1\" || h === \"0.0.0.0\" || h.startsWith(\"127.\")) return true\n return LOCAL_HOST_SUFFIXES.some((suffix) => h.endsWith(suffix))\n}\n\n/** The host of an `http(s)://` string, or null when it has none or a `${}` hole cuts it off. */\nfunction hostOf(text: string): string | null {\n const m = /^https?:\\/\\/(?:[^@/?#]*@)?(\\[[^\\]]*\\]|[^/?#:]+)/i.exec(text)\n if (!m?.[1]) return null\n return m[1].replace(/^\\[|\\]$/g, \"\")\n}\n\n/** `process.env.X`, `env.X`, `serverEnv().X` — the env key, when `X` looks like one. */\nfunction envKeyOf(node: AstNode | undefined): string | null {\n if (node?.type !== \"MemberExpression\" || node.property?.type !== \"Identifier\") return null\n const key = node.property.name ?? \"\"\n if (!ENV_KEY.test(key)) return null\n const object = node.object\n if (!object) return null\n if (object.type === \"Identifier\") return object.name === \"env\" ? key : null\n if (object.type === \"MemberExpression\") {\n const isProcessEnv =\n object.object?.type === \"Identifier\" &&\n object.object.name === \"process\" &&\n object.property?.name === \"env\"\n return isProcessEnv ? key : null\n }\n if (object.type === \"CallExpression\") {\n const name = calleeName(object)\n return name === \"env\" || name.endsWith(\"Env\") ? key : null\n }\n return null\n}\n\ntype ExternalTarget = { host: string } | { envKey: string } | null\n\n/**\n * Where a call is going, read off its first argument: a host when the code\n * spells the URL out, an env key when the base comes from the environment,\n * null when the shape says nothing (a bare variable, a relative path).\n */\nfunction externalTargetOf(node: AstNode | undefined): ExternalTarget {\n if (!node) return null\n if (node.type === \"Literal\" && typeof node.value === \"string\") {\n const host = hostOf(node.value)\n return host ? { host } : null\n }\n if (node.type === \"TemplateLiteral\") {\n const head = node.quasis?.[0]?.value?.cooked ?? node.quasis?.[0]?.value?.raw ?? \"\"\n const host = hostOf(head)\n if (host) return { host }\n // `${process.env.SAP_BASE_URL}/path` — the base is the first hole.\n if (head === \"\") {\n const key = envKeyOf(node.expressions?.[0])\n if (key) return { envKey: key }\n }\n return null\n }\n if (node.type === \"BinaryExpression\" && node.operator === \"+\") return externalTargetOf(node.left)\n if (node.type === \"MemberExpression\") {\n const key = envKeyOf(node)\n return key ? { envKey: key } : null\n }\n if (node.type === \"NewExpression\" && node.callee?.name === \"URL\") {\n // new URL(path, base): the base decides the host; new URL(absolute) has no base.\n const args = node.arguments ?? []\n return externalTargetOf(args[1]) ?? externalTargetOf(args[0])\n }\n return null\n}\n\nfunction isHttpClientCall(node: AstNode): boolean {\n const callee = node.callee\n if (!callee) return false\n if (callee.type === \"Identifier\") return HTTP_CLIENTS.includes(callee.name ?? \"\")\n if (callee.type === \"MemberExpression\") {\n return (\n callee.object?.type === \"Identifier\" &&\n HTTP_LIBS.includes(callee.object.name ?? \"\") &&\n callee.property?.type === \"Identifier\" &&\n HTTP_METHODS.test(callee.property.name ?? \"\")\n )\n }\n return false\n}\n\n/**\n * An outbound call to a host this app has not declared. Advisory: the rule\n * reads one argument, so it sees a spelled-out host or an env-backed base and\n * nothing more. The manifest extractor does the same classification at deploy\n * time and the portal shows the result; this is the editor-time echo of it.\n */\nconst noUndeclaredExternalCall: Rule.RuleModule = {\n meta: meta(\"QDC-NET-002 - outbound call to an external API this app has not declared\", \"suggestion\"),\n create(context) {\n return listener({\n CallExpression: (node) => {\n if (!isHttpClientCall(node)) return\n const target = externalTargetOf(node.arguments?.[0])\n if (!target) return\n let label: string\n if (\"host\" in target) {\n if (isLocalHost(target.host) || isPlatformManagedHost(target.host)) return\n label = target.host\n } else {\n // CONN_* is a wired module connection: the portal already knows the other end.\n if (target.envKey.startsWith(\"CONN_\")) return\n label = `$${target.envKey}`\n }\n context.report({\n node: node as unknown as Rule.Node,\n message: `QDC-NET-002 - ${label} is an external API this app has not declared. Declare it in src/config/integrations.ts and call integration(alias).get/post, so the portal can see and manage it.`,\n })\n },\n })\n },\n}\n\n/** The calls on an integration handle that send a request, and where their path sits. */\nconst INTEGRATION_PATH_ARG: Record<string, number> = { get: 0, post: 0, put: 0, patch: 0, delete: 0, request: 1 }\n/** Reads off a handle that send nothing, so taking them through a variable hides no endpoint. */\nconst INTEGRATION_READS = [\"config\", \"alias\", \"definition\"]\n\nconst isStringLiteral = (node: AstNode | undefined): boolean =>\n node?.type === \"Literal\" && typeof node.value === \"string\"\n\n/**\n * An integration call the portal cannot read. The manifest extractor reads\n * exactly `integration(\"alias\").get(\"/path\")`, alias and path written at the\n * call site, because it reads source, not values. A path passed in through a\n * helper, an alias held in a variable, or a handle stored and called later all\n * reach the API fine and leave the portal's Integrations tab short of that\n * endpoint, with nothing failing to say so. Advisory, like QDC-NET-002.\n */\nconst integrationStaticCall: Rule.RuleModule = {\n meta: meta(\"QDC-NET-003 - an integration call whose alias or path the portal cannot read\", \"suggestion\"),\n create(context) {\n const report = (node: AstNode, message: string) => {\n context.report({ node: node as unknown as Rule.Node, message: `QDC-NET-003 - ${message}` })\n }\n return listener({\n CallExpression: (node) => {\n if (node.callee?.type !== \"Identifier\" || node.callee.name !== \"integration\") return\n if (!isStringLiteral(node.arguments?.[0])) {\n report(\n node,\n 'the alias is not a string literal, so the portal cannot tell which integration this calls. Write integration(\"alias\") here.',\n )\n return\n }\n const member = node.parent\n const method =\n member?.type === \"MemberExpression\" && member.object === node && member.property?.type === \"Identifier\"\n ? (member.property.name ?? \"\")\n : \"\"\n if (INTEGRATION_READS.includes(method)) return\n const call = member?.parent\n const index = INTEGRATION_PATH_ARG[method]\n if (index === undefined || call?.type !== \"CallExpression\" || call.callee !== member) {\n report(\n node,\n 'the integration handle is stored or passed on instead of called here, so the portal cannot see the endpoints called through it. Write integration(\"alias\").get(\"/path\") at each call site.',\n )\n return\n }\n const path = call.arguments?.[index]\n if (path === undefined || isStringLiteral(path) || path.type === \"TemplateLiteral\") return\n report(\n path,\n \"the path is not written at the call site, so the portal cannot list this endpoint. Write it as a string or template literal here, e.g. `/orders/${id}`. A helper may share options, never the path.\",\n )\n },\n })\n },\n}\n\nexport const rules: Record<string, Rule.RuleModule> = {\n \"no-dangerous-html\": ban(\n \"QDC-XSS-001\",\n \"dangerouslySetInnerHTML renders unescaped markup. Render text, or sanitise it first.\",\n [\"JSXAttribute[name.name='dangerouslySetInnerHTML']\"],\n ),\n \"no-inner-html\": ban(\n \"QDC-XSS-002\",\n \"Assigning innerHTML parses the string as markup. Use textContent.\",\n [\n \"AssignmentExpression[left.type='MemberExpression'][left.property.name=/^(innerHTML|outerHTML)$/]\",\n ],\n ),\n \"no-insert-adjacent-html\": ban(\n \"QDC-XSS-003\",\n \"insertAdjacentHTML parses its argument as markup. Build the nodes instead.\",\n [\"CallExpression[callee.property.name='insertAdjacentHTML']\"],\n ),\n \"no-document-write\": ban(\n \"QDC-XSS-004\",\n \"document.write parses its argument as markup and blocks the parser. Render it in React.\",\n [\"CallExpression[callee.object.name='document'][callee.property.name=/^write(ln)?$/]\"],\n ),\n \"no-string-eval\": noStringEval,\n \"no-raw-script-tag\": ban(\n \"QDC-CSP-001\",\n \"A hand-written <script> gets no nonce, and this app's CSP uses 'strict-dynamic', so it will not run. Use next/script.\",\n [\"JSXElement[openingElement.name.name='script']\"],\n ),\n \"no-sql-interpolation\": ban(\n \"QDC-SQL-001\",\n \"An interpolated string reaching .execute() is the injection. Use the sql tag, which parameterises.\",\n [\n \"CallExpression[callee.property.name='execute'] > TemplateLiteral[expressions.length>0]\",\n \"CallExpression[callee.property.name='execute'] > BinaryExpression[operator='+']\",\n ],\n ),\n \"no-sql-raw\": ban(\n \"QDC-SQL-002\",\n \"sql.raw() puts its argument into the query verbatim and sanitises nothing. Interpolate through the sql tag.\",\n [\"MemberExpression[object.name='sql'][property.name='raw']\"],\n ),\n \"no-driver-import\": banImports(\n \"QDC-SQL-003\",\n \"The database driver belongs in the db layer. Everywhere else, go through Drizzle.\",\n DB_DRIVERS,\n DB_LAYER,\n ),\n \"no-fs-import\": banImports(\n \"QDC-FS-001\",\n \"Request handlers should not reach the filesystem. If one must, use safeJoin from @quatronic/sdk/node/fspath.\",\n FS_MODULES,\n FS_CALLERS,\n ),\n \"safe-redirect\": safeRedirect,\n \"safe-fetch\": safeFetch,\n \"no-undeclared-external-call\": noUndeclaredExternalCall,\n \"integration-static-call\": integrationStaticCall,\n}\n\n/**\n * Rule name to QDC id, for docs and for anything that wants to assert the set\n * without re-deriving it from the messages.\n */\nexport const RULE_IDS: Record<string, string> = {\n \"no-dangerous-html\": \"QDC-XSS-001\",\n \"no-inner-html\": \"QDC-XSS-002\",\n \"no-insert-adjacent-html\": \"QDC-XSS-003\",\n \"no-document-write\": \"QDC-XSS-004\",\n \"no-string-eval\": \"QDC-XSS-005\",\n \"no-raw-script-tag\": \"QDC-CSP-001\",\n \"no-sql-interpolation\": \"QDC-SQL-001\",\n \"no-sql-raw\": \"QDC-SQL-002\",\n \"no-driver-import\": \"QDC-SQL-003\",\n \"no-fs-import\": \"QDC-FS-001\",\n \"safe-redirect\": \"QDC-URL-001\",\n \"safe-fetch\": \"QDC-NET-001\",\n \"no-undeclared-external-call\": \"QDC-NET-002\",\n \"integration-static-call\": \"QDC-NET-003\",\n}\n","import type { Rule } from \"eslint\"\n\nimport type { AstNode } from \"./ast\"\nimport { listener, meta, reporter } from \"./rules\"\n\nconst SENTRY_MODULE = /^@sentry\\//\nconst BANNED = new Set([\"init\", \"withSentryConfig\"])\nconst SPAN_STARTERS = new Set([\"startSpan\", \"startSpanManual\", \"startInactiveSpan\"])\nconst CAPTURES = new Set([\"captureException\", \"captureMessage\"])\nconst LOG_LEVELS = new Set([\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"])\nconst KEY_SETTERS = new Set([\"setAttribute\", \"setTag\"])\nconst OBJECT_SETTERS = new Set([\"setAttributes\", \"setTags\"])\nconst SPAN_RECEIVER = /^(span|\\w*Span)$/\nconst SCOPE_RECEIVER = /^(scope|\\w*Scope)$/\nconst SPAN_GETTERS = new Set([\"getActiveSpan\", \"getRootSpan\"])\nconst SCOPE_GETTERS = new Set([\"getCurrentScope\", \"getIsolationScope\"])\nconst PII =\n /(^|[._-])(e-?mail|phone|password|passwd|token|secret|iban|bsn|ssn|ip_?address|first_?name|last_?name|full_?name|username)($|[._-])/i\n\n/** Local names bound to `@sentry/*` (namespace, default, or a named export). */\nfunction trackSentry() {\n const namespaces = new Set<string>()\n const named = new Map<string, string>()\n return {\n namespaces,\n named,\n onImport(node: AstNode, onBanned?: (n: AstNode) => void) {\n const src = node.source?.value\n if (typeof src !== \"string\" || !SENTRY_MODULE.test(src)) return\n for (const s of node.specifiers ?? []) {\n const local = s.local?.name ?? \"\"\n if (s.type === \"ImportNamespaceSpecifier\" || s.type === \"ImportDefaultSpecifier\") namespaces.add(local)\n else if (s.type === \"ImportSpecifier\") {\n const imported = s.imported?.name ?? \"\"\n named.set(local, imported)\n if (BANNED.has(imported)) onBanned?.(s)\n }\n }\n },\n }\n}\n\nconst keyOf = (prop: AstNode): string | undefined => {\n if (prop.type !== \"Property\" || prop.computed) return undefined\n if (prop.key?.type === \"Identifier\") return prop.key.name\n return typeof prop.key?.value === \"string\" ? prop.key.value : undefined\n}\n\nconst objectKeys = (node: AstNode | undefined): [string, AstNode][] =>\n node?.type === \"ObjectExpression\"\n ? (node.properties ?? []).flatMap((p) => {\n const k = keyOf(p)\n return k === undefined ? [] : [[k, p] as [string, AstNode]]\n })\n : []\n\nconst propertyNamed = (node: AstNode | undefined, name: string): AstNode | undefined =>\n node?.type === \"ObjectExpression\"\n ? ((node.properties ?? []).find((p) => keyOf(p) === name)?.value as AstNode | undefined)\n : undefined\n\n/** Reports every attribute, tag or log-field key the app hands Sentry. */\nfunction attributeKeyRule(\n id: string,\n description: string,\n check: (key: string) => string | undefined,\n): Rule.RuleModule {\n return {\n meta: meta(`${id} - ${description}`, \"suggestion\"),\n create(context) {\n const sentry = trackSentry()\n const flag = (key: string, node: AstNode) => {\n const problem = check(key)\n if (problem) reporter(context, `${id} - ${problem}`)(node)\n }\n return listener({\n ImportDeclaration: (node) => sentry.onImport(node),\n CallExpression: (node) => {\n const callee = node.callee\n const args = node.arguments ?? []\n let name: string | undefined\n let viaSentry = false\n if (callee?.type === \"Identifier\") {\n name = sentry.named.get(callee.name ?? \"\")\n viaSentry = name !== undefined\n } else if (callee?.type === \"MemberExpression\") {\n name = callee.property?.name\n const obj = callee.object\n viaSentry =\n (obj?.type === \"Identifier\" && sentry.namespaces.has(obj.name ?? \"\")) ||\n (obj?.type === \"MemberExpression\" &&\n obj.property?.name === \"logger\" &&\n obj.object?.type === \"Identifier\" &&\n sentry.namespaces.has(obj.object.name ?? \"\")) ||\n (obj?.type === \"Identifier\" && sentry.named.get(obj.name ?? \"\") === \"logger\")\n }\n if (!name) return\n const obj = callee?.type === \"MemberExpression\" ? callee.object : undefined\n const sentryCall = (names: Set<string>) =>\n obj?.type === \"CallExpression\" &&\n ((obj.callee?.type === \"Identifier\" && names.has(sentry.named.get(obj.callee.name ?? \"\") ?? \"\")) ||\n (obj.callee?.type === \"MemberExpression\" &&\n obj.callee.object?.type === \"Identifier\" &&\n sentry.namespaces.has(obj.callee.object.name ?? \"\") &&\n names.has(obj.callee.property?.name ?? \"\")))\n const recv = obj?.type === \"Identifier\" ? (obj.name ?? \"\") : \"\"\n const spanRecv = SPAN_RECEIVER.test(recv) || sentryCall(SPAN_GETTERS)\n const tagRecv = viaSentry || SCOPE_RECEIVER.test(recv) || sentryCall(SCOPE_GETTERS)\n const keys: [string, AstNode][] = []\n if (\n KEY_SETTERS.has(name) &&\n (name === \"setAttribute\" ? spanRecv : tagRecv) &&\n args[0]?.type === \"Literal\" &&\n typeof args[0].value === \"string\"\n ) {\n keys.push([args[0].value, args[0]])\n } else if (OBJECT_SETTERS.has(name) && (name === \"setAttributes\" ? spanRecv : tagRecv)) {\n keys.push(...objectKeys(args[0]))\n } else if (viaSentry && SPAN_STARTERS.has(name)) {\n keys.push(...objectKeys(propertyNamed(args[0], \"attributes\")))\n } else if (viaSentry && CAPTURES.has(name)) {\n keys.push(...objectKeys(propertyNamed(args[1], \"tags\")))\n } else if (viaSentry && LOG_LEVELS.has(name) && callee?.type === \"MemberExpression\") {\n keys.push(...objectKeys(args[1]))\n }\n for (const [key, at] of keys) flag(key, at)\n },\n })\n },\n }\n}\n\nconst noSentryInit: Rule.RuleModule = {\n meta: meta(\"QDC-OBS-001 - the SDK owns Sentry.init and withSentryConfig\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-OBS-001 - @quatronic/sdk owns Sentry.init and withSentryConfig. Use Sentry.* directly; see the qore-observability skill.\",\n )\n const sentry = trackSentry()\n return listener({\n ImportDeclaration: (node) => sentry.onImport(node, report),\n CallExpression: (node) => {\n const c = node.callee\n if (\n c?.type === \"MemberExpression\" &&\n c.object?.type === \"Identifier\" &&\n sentry.namespaces.has(c.object.name ?? \"\") &&\n BANNED.has(c.property?.name ?? \"\")\n ) {\n report(node)\n }\n },\n })\n },\n}\n\nexport const observabilityRules: Record<string, Rule.RuleModule> = {\n \"no-sentry-init\": noSentryInit,\n \"sentry-attribute-namespace\": attributeKeyRule(\n \"QDC-OBS-002\",\n \"custom attribute, tag and log keys are qore.<area>.<name>\",\n (key) =>\n key.startsWith(\"qore.\") ? undefined : `'${key}' is not namespaced. Use qore.<area>.<name>, e.g. qore.invoice.id.`,\n ),\n \"no-pii-attributes\": attributeKeyRule(\"QDC-OBS-003\", \"no personal data in telemetry keys\", (key) =>\n PII.test(key)\n ? `'${key}' looks like personal data. Send an id instead; see the qore-observability skill.`\n : undefined,\n ),\n}\n\nexport const OBSERVABILITY_RULE_IDS: Record<string, string> = {\n \"no-sentry-init\": \"QDC-OBS-001\",\n \"sentry-attribute-namespace\": \"QDC-OBS-002\",\n \"no-pii-attributes\": \"QDC-OBS-003\",\n}\n","import type { Linter, Rule } from \"eslint\"\n\nimport { observabilityRules } from \"./observability\"\nimport { RULE_IDS, rules } from \"./rules\"\n\nexport { OBSERVABILITY_RULE_IDS, observabilityRules } from \"./observability\"\nexport { RULE_IDS, rules } from \"./rules\"\n\n/**\n * The QDC security ESLint plugin.\n *\n * It lives here rather than in each generated app because a lint rule is the\n * cheapest security control QDC has, and a rule copied into every app can only\n * be tightened by editing every app. Shipped from the SDK, a corrected rule\n * reaches an app on its next `@quatronic/sdk` bump — the same bump the app\n * pays for everything else in the package.\n *\n * Usage in a generated app's `eslint.config.mjs`:\n *\n * import qdcSecurity from \"@quatronic/sdk/eslint\"\n *\n * export default [\n * ...whatever,\n * ...qdcSecurity.configs.recommended,\n * ]\n *\n * A repository that predates the pack spreads `configs.warn` instead — the\n * same rules and scopes, reporting rather than blocking — and promotes itself\n * to `recommended` once its backlog is clear.\n *\n * The rules are syntactic by design. Anything that has to follow a value\n * across functions and files is a Semgrep rule instead, in this package's\n * `semgrep/` directory, run by the same CI job.\n */\nconst plugin = {\n meta: { name: \"@quatronic/sdk/eslint\" },\n rules: { ...rules, ...observabilityRules },\n}\n\n/** Where a generated app keeps the code these rules are about. */\nconst SRC_FILES = [\"src/**/*.{ts,tsx}\"]\nconst TEST_FILES = [\"**/*.test.{ts,tsx}\", \"**/*.spec.{ts,tsx}\"]\n\nexport interface QdcSecurityConfigs {\n recommended: Linter.Config[]\n /**\n * The same rules, in the same scopes, with every enabled one demoted to\n * \"warn\".\n *\n * For a codebase that predates the pack. Adopting fourteen rules at \"error\"\n * into an existing tree means either a red build on day one or a hand-copied\n * override block in that repo — and a hand-copied block stops covering the\n * pack the moment a fifteenth rule ships, while still reporting green. So\n * the demotion lives here, next to the list it demotes.\n *\n * It is a starting position, not a destination: a pack that warns forever is\n * not a control. Promote the repo to `recommended` once its backlog is clear.\n */\n warn: Linter.Config[]\n /**\n * Telemetry rules for apps whose runtime code logs through Sentry only.\n * Separate from `recommended` so a bump does not turn an older app's lint red.\n */\n observability: Linter.Config[]\n}\n\n/**\n * The plugin object, typed explicitly: an inferred type here reaches into\n * `@eslint/core` and TypeScript refuses to name it in a `.d.ts`.\n */\nexport interface QdcSecurityPlugin {\n meta: { name: string }\n rules: Record<string, Rule.RuleModule>\n configs: QdcSecurityConfigs\n RULE_IDS: Record<string, string>\n}\n\n/**\n * Two blocks, spread into a flat config in this order.\n *\n * The second one is not decoration: a test that proves escaping works has to\n * build the markup it escapes, so the XSS bans are off there. It is a separate\n * block because flat-config rule options **replace** rather than merge — a\n * later block naming a rule wins outright — so the exemption has to come after\n * the block that switches the rules on, and has to name only what it exempts.\n */\nconst recommended: Linter.Config[] = [\n {\n files: SRC_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-dangerous-html\": \"error\",\n \"qdc/no-inner-html\": \"error\",\n \"qdc/no-insert-adjacent-html\": \"error\",\n \"qdc/no-document-write\": \"error\",\n \"qdc/no-string-eval\": \"error\",\n \"qdc/no-raw-script-tag\": \"error\",\n \"qdc/no-sql-interpolation\": \"error\",\n \"qdc/no-sql-raw\": \"error\",\n \"qdc/no-driver-import\": \"error\",\n \"qdc/no-fs-import\": \"error\",\n // Advisory, and `eslint .` does not fail on warnings. All three fire on\n // shapes that are often fine, so they prompt a look rather than block a\n // merge; qdc.redirect.tainted and qdc.ssrf.tainted-fetch in the Semgrep\n // pack follow the value and are what actually decide, and the manifest\n // extractor classifies the same hosts at deploy time for the portal.\n \"qdc/safe-redirect\": \"warn\",\n \"qdc/safe-fetch\": \"warn\",\n \"qdc/no-undeclared-external-call\": \"warn\",\n // Advisory too: the call works either way, the portal just cannot list it.\n \"qdc/integration-static-call\": \"warn\",\n },\n },\n {\n // Tests build markup on purpose, to prove the escaping works.\n files: TEST_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-dangerous-html\": \"off\",\n \"qdc/no-inner-html\": \"off\",\n \"qdc/no-insert-adjacent-html\": \"off\",\n \"qdc/no-document-write\": \"off\",\n \"qdc/no-raw-script-tag\": \"off\",\n // The two location bans are off here for a different reason than the\n // XSS ones above. They do not say \"this is dangerous\"; they say \"this\n // capability belongs in `src/db` or `src/scripts`, not scattered through\n // the app\", and that argument is about the shape of the *application*. A\n // test reads a fixture off disk and an integration test opens a real\n // connection; neither ships, and neither can be reached by a request, so\n // neither is the traversal or injection surface the ban exists for.\n //\n // Found by running the pack over five live tenant repositories before it\n // started blocking merges: `no-fs-import` fired six times in one repo and\n // every hit was a test reading its own fixture.\n \"qdc/no-fs-import\": \"off\",\n \"qdc/no-driver-import\": \"off\",\n // A test that stubs fetch names the host it stubs; nothing leaves the\n // process, and the portal is told about deploys, not test runs.\n \"qdc/no-undeclared-external-call\": \"off\",\n // A test calls a handle it built itself; no deploy reads it.\n \"qdc/integration-static-call\": \"off\",\n },\n },\n]\n\n/**\n * \"off\" is an exemption, not a severity. Demoting it to \"warn\" would switch a\n * rule back on in the scope that deliberately turned it off — the test-file\n * block below being the whole reason that distinction matters.\n */\nconst demote = (config: Linter.Config): Linter.Config => ({\n ...config,\n rules: Object.fromEntries(\n Object.entries(config.rules ?? {}).map(([id, level]) => [\n id,\n level === \"off\" ? \"off\" : \"warn\",\n ]),\n ),\n})\n\nconst warn: Linter.Config[] = recommended.map(demote)\n\nconst observability: Linter.Config[] = [\n {\n files: SRC_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-sentry-init\": \"error\",\n \"no-console\": \"error\",\n \"qdc/sentry-attribute-namespace\": \"warn\",\n \"qdc/no-pii-attributes\": \"warn\",\n },\n },\n {\n // CLI tools and tests print on purpose.\n files: [\"**/seed.ts\", \"src/scripts/**\", ...TEST_FILES],\n rules: { \"no-console\": \"off\" },\n },\n]\n\nexport const configs: QdcSecurityConfigs = { recommended, warn, observability }\n\nconst qdcSecurity: QdcSecurityPlugin = { ...plugin, configs, RULE_IDS }\n\nexport default qdcSecurity\n"],"mappings":";;;;;AAyCO,IAAM,eAAe,CAAC,gBAAgB,aAAa,aAAa,OAAO;AAGvE,SAAS,OAAO,UAA0B;AAC/C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AAO;AAAA,IACZ,OAAO,QAAQ,OAAO,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;AAAA,MACtD;AAAA,MACA,UAAU,QAAQ,QAAQ;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;AAEA,IAAM,OAAwB,YAAY,IAAI,MAAM;AAEpD,IAAM,gBAAiC;AAAA,EACrC;AAAA,IACE,OAAO;AAAA,IACP,SAAS,EAAE,KAAK,OAAO;AAAA,IACvB,OAAO;AAAA,MACL,sBAAsB;AAAA,MACtB,cAAc;AAAA,MACd,kCAAkC;AAAA,MAClC,yBAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EACA;AAAA;AAAA,IAEE,OAAO,CAAC,cAAc,kBAAkB,GAAG,UAAU;AAAA,IACrD,OAAO,EAAE,cAAc,MAAM;AAAA,EAC/B;AACF;AAEO,IAAM,UAA8B,EAAE,aAAa,MAAM,cAAc;AAE9E,IAAM,cAAiC,EAAE,GAAG,QAAQ,SAAS,SAAS;AAEtE,IAAO,iBAAQ;","names":["obj"]}
|
|
1
|
+
{"version":3,"sources":["../../src/eslint/ast.ts","../../src/eslint/rules.ts","../../src/eslint/mobile.ts","../../src/eslint/observability.ts","../../src/eslint/index.ts"],"sourcesContent":["// A deliberately narrow view of the AST, for rules that are deliberately\n// syntactic.\n//\n// ESLint's own `Rule.Node` is the ESTree union. It does not describe JSX at\n// all, and it forces a narrowing cascade for every property access — in rules\n// whose whole job is to read three or four fields off a node and report it.\n// So these rules declare exactly the fields they read and cast once, at the\n// visitor boundary, rather than per line.\n//\n// Anything that has to follow a value across functions or files is a Semgrep\n// rule instead; that pack ships in `semgrep/` alongside this plugin.\nexport interface AstNode {\n type: string\n /** `Identifier.name` and `MemberExpression.property.name`. Never a JSX name. */\n name?: string\n value?: unknown\n callee?: AstNode\n object?: AstNode\n property?: AstNode\n source?: AstNode\n arguments?: (AstNode | undefined)[]\n expressions?: (AstNode | undefined)[]\n /** `TemplateLiteral.quasis`: the fixed text between the `${}` holes. */\n quasis?: { value?: { cooked?: string | null; raw?: string } }[]\n /** `BinaryExpression.left`; the rule that reads it only follows the left edge. */\n left?: AstNode\n operator?: string\n /** `ImportDeclaration.specifiers`. */\n specifiers?: AstNode[]\n /** `ImportSpecifier.imported` / `.local`. */\n imported?: AstNode\n local?: AstNode\n /** `ObjectExpression.properties`; a `Property` has `key` and `computed`. */\n properties?: AstNode[]\n key?: AstNode\n computed?: boolean\n /** Set by ESLint on every node it visits. */\n parent?: AstNode\n}\n\n/** Calls whose result is a URL this app decided on, not one a caller supplied. */\nexport const VETTED_CALLS = [\"safeRedirect\", \"safeFetch\", \"vetTarget\", \"clone\"]\n\n/** POSIX form of the file being linted, so the checks read the same on Windows. */\nexport function pathOf(filename: string): string {\n return filename.replaceAll(\"\\\\\", \"/\")\n}\n\n/** Is the linted file at, or inside, one of these project paths? */\nexport function isUnder(filename: string, paths: readonly string[]): boolean {\n const file = pathOf(filename)\n return paths.some((path) => file.endsWith(`/${path}`) || file.includes(`/${path}/`))\n}\n\n/** The called name, whether the callee is `f()` or `x.f()`. */\nexport function calleeName(node: AstNode): string {\n const callee = node.callee\n if (!callee) return \"\"\n if (callee.type === \"Identifier\") return callee.name ?? \"\"\n if (callee.type === \"MemberExpression\" && callee.property?.type === \"Identifier\") {\n return callee.property.name ?? \"\"\n }\n return \"\"\n}\n\n/**\n * A target this app wrote down, rather than one that arrived with the request.\n *\n * `allowIdentifier` is the whole difference between the two advisory rules:\n * judging what a bare variable holds takes dataflow, which is what the Semgrep\n * taint rules do. `qdc/safe-redirect` lets a variable through because\n * `NextResponse.redirect(url)` after `req.nextUrl.clone()` is the canonical\n * Next redirect and appears in every generated app; `qdc/safe-fetch` does not.\n */\nexport function isFixedTarget(node: AstNode | undefined, allowIdentifier: boolean): boolean {\n if (!node) return false\n if (node.type === \"Literal\") return typeof node.value === \"string\"\n if (node.type === \"TemplateLiteral\") return (node.expressions?.length ?? 0) === 0\n if (node.type === \"Identifier\") return allowIdentifier\n if (node.type === \"NewExpression\") {\n // `new URL(\"/login\", req.url)` fixes the path; the base only ever\n // contributes this app's own origin.\n return node.callee?.name === \"URL\" && isFixedTarget(node.arguments?.[0], allowIdentifier)\n }\n if (node.type === \"CallExpression\") return VETTED_CALLS.includes(calleeName(node))\n return false\n}\n","import type { Rule } from \"eslint\"\n\nimport { isPlatformManagedHost } from \"../integrations-core/platform-hosts\"\nimport { type AstNode, calleeName, isFixedTarget, isUnder } from \"./ast\"\n\n/**\n * The fourteen QDC security lint rules.\n *\n * One rule per id, rather than fourteen entries in `no-restricted-syntax`, for\n * two reasons that only show up after the fact:\n *\n * - **Severity is per rule.** `no-restricted-syntax` carries one severity for\n * its whole array, and three of these are advisory on purpose — they fire on\n * shapes that are usually fine, and the Semgrep pack does the dataflow they\n * can only approximate.\n * - **Suppression is per rule.** `// eslint-disable-next-line\n * no-restricted-syntax` switches off every selector on that line, so\n * silencing \"no inline styles\" would silently also silence the\n * `dangerouslySetInnerHTML` ban sitting next to it.\n *\n * Suppress one by its own name, and say why:\n *\n * // eslint-disable-next-line qdc/no-dangerous-html -- sanitised in renderPost()\n */\n\n/** Modules that talk to the database directly, and where that is allowed. */\nconst DB_DRIVERS = [\"pg\", \"postgres\", \"mysql2\", \"mysql2/promise\"]\nconst DB_LAYER = [\"src/db\", \"src/lib/db.ts\"]\n\n/** Node's filesystem API, and where a generated app is expected to use it. */\nconst FS_MODULES = [\"fs\", \"node:fs\", \"fs/promises\", \"node:fs/promises\"]\n// `src/lib/migrate.ts` is the migration runner: it reads the migration files\n// off disk at boot, which is the sanctioned use, and it is not reachable from\n// a request. The backend recipes put it there rather than under src/db.\nconst FS_CALLERS = [\"src/scripts\", \"src/db\", \"src/lib/migrate.ts\"]\n\n/** Where a fetch goes out with the server's own network position. */\nconst SERVER_PATHS = [\"src/app/api\", \"src/lib/server\", \"src/proxy.ts\"]\n\n/** One cast, at the boundary, instead of one per `context.report` call. */\nexport function reporter(context: Rule.RuleContext, message: string): (node: AstNode) => void {\n return (node: AstNode) => {\n context.report({ node: node as unknown as Rule.Node, message })\n }\n}\n\nexport function listener(visitor: Record<string, (node: AstNode) => void>): Rule.RuleListener {\n return visitor as unknown as Rule.RuleListener\n}\n\nexport function meta(description: string, type: \"problem\" | \"suggestion\"): Rule.RuleModule[\"meta\"] {\n return { type, docs: { description }, schema: [] }\n}\n\n/** A rule that reports every node matching one of `selectors`. */\nfunction ban(id: string, message: string, selectors: string[]): Rule.RuleModule {\n const text = `${id} - ${message}`\n return {\n meta: meta(text, \"problem\"),\n create(context) {\n const report = reporter(context, text)\n return listener(Object.fromEntries(selectors.map((selector) => [selector, report])))\n },\n }\n}\n\n/** A rule that bans importing any of `modules`, except from `allowed` paths. */\nfunction banImports(\n id: string,\n message: string,\n modules: string[],\n allowed: string[],\n): Rule.RuleModule {\n const text = `${id} - ${message}`\n return {\n meta: meta(text, \"problem\"),\n create(context) {\n if (isUnder(context.filename, allowed)) return {}\n const report = reporter(context, text)\n const flag = (node: AstNode) => {\n const source = node.source\n if (source?.type === \"Literal\" && typeof source.value === \"string\") {\n if (modules.includes(source.value)) report(node)\n }\n }\n return listener({ ImportDeclaration: flag, ImportExpression: flag })\n },\n }\n}\n\nconst noStringEval: Rule.RuleModule = {\n meta: meta(\"QDC-XSS-005 - no code compiled from a string\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-XSS-005 - compiling a string into code runs whatever the string turned out to be. Pass a function.\",\n )\n const isStringy = (node: AstNode | undefined) =>\n node?.type === \"TemplateLiteral\" ||\n node?.type === \"BinaryExpression\" ||\n (node?.type === \"Literal\" && typeof node.value === \"string\")\n return listener({\n \"CallExpression[callee.name='eval']\": report,\n \"CallExpression[callee.name='Function']\": report,\n \"NewExpression[callee.name='Function']\": report,\n \"CallExpression[callee.name=/^set(Timeout|Interval)$/]\": (node) => {\n if (isStringy(node.arguments?.[0])) report(node)\n },\n })\n },\n}\n\nconst safeRedirect: Rule.RuleModule = {\n meta: meta(\"QDC-URL-001 - redirect to a target this app decided on\", \"suggestion\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-URL-001 - redirecting to a value that came with the request is an open redirect. Wrap it in safeRedirect from @quatronic/sdk/next/auth.\",\n )\n return listener({\n \"CallExpression[callee.object.name='NextResponse'][callee.property.name='redirect']\": (\n node,\n ) => {\n if (isFixedTarget(node.arguments?.[0], true)) return\n report(node)\n },\n })\n },\n}\n\nconst safeFetch: Rule.RuleModule = {\n meta: meta(\"QDC-NET-001 - server-side fetch of a caller-supplied URL\", \"suggestion\"),\n create(context) {\n if (!isUnder(context.filename, SERVER_PATHS)) return {}\n const report = reporter(\n context,\n \"QDC-NET-001 - a URL the server did not decide on reaches the private network too. Use safeFetch from @quatronic/sdk/node/net, or connection(alias).fetch for a wired module.\",\n )\n return listener({\n \"CallExpression[callee.name='fetch']\": (node) => {\n if (isFixedTarget(node.arguments?.[0], false)) return\n report(node)\n },\n })\n },\n}\n\n/** Outbound HTTP clients a generated app might reach for. */\nconst HTTP_CLIENTS = [\"fetch\", \"axios\", \"got\", \"ky\"]\nconst HTTP_LIBS = [\"axios\", \"got\", \"ky\"]\nconst HTTP_METHODS = /^(get|post|put|patch|delete|head|request)$/\n\n/** A host that is this cluster or this machine, so not an external API. */\nconst LOCAL_HOST_SUFFIXES = [\".local\", \".internal\", \".svc\", \".cluster.local\"]\nconst ENV_KEY = /^[A-Z][A-Z0-9_]*$/\n\nfunction isLocalHost(host: string): boolean {\n const h = host.toLowerCase()\n if (h === \"localhost\" || h === \"::1\" || h === \"0.0.0.0\" || h.startsWith(\"127.\")) return true\n return LOCAL_HOST_SUFFIXES.some((suffix) => h.endsWith(suffix))\n}\n\n/** The host of an `http(s)://` string, or null when it has none or a `${}` hole cuts it off. */\nfunction hostOf(text: string): string | null {\n const m = /^https?:\\/\\/(?:[^@/?#]*@)?(\\[[^\\]]*\\]|[^/?#:]+)/i.exec(text)\n if (!m?.[1]) return null\n return m[1].replace(/^\\[|\\]$/g, \"\")\n}\n\n/** `process.env.X`, `env.X`, `serverEnv().X` — the env key, when `X` looks like one. */\nfunction envKeyOf(node: AstNode | undefined): string | null {\n if (node?.type !== \"MemberExpression\" || node.property?.type !== \"Identifier\") return null\n const key = node.property.name ?? \"\"\n if (!ENV_KEY.test(key)) return null\n const object = node.object\n if (!object) return null\n if (object.type === \"Identifier\") return object.name === \"env\" ? key : null\n if (object.type === \"MemberExpression\") {\n const isProcessEnv =\n object.object?.type === \"Identifier\" &&\n object.object.name === \"process\" &&\n object.property?.name === \"env\"\n return isProcessEnv ? key : null\n }\n if (object.type === \"CallExpression\") {\n const name = calleeName(object)\n return name === \"env\" || name.endsWith(\"Env\") ? key : null\n }\n return null\n}\n\ntype ExternalTarget = { host: string } | { envKey: string } | null\n\n/**\n * Where a call is going, read off its first argument: a host when the code\n * spells the URL out, an env key when the base comes from the environment,\n * null when the shape says nothing (a bare variable, a relative path).\n */\nfunction externalTargetOf(node: AstNode | undefined): ExternalTarget {\n if (!node) return null\n if (node.type === \"Literal\" && typeof node.value === \"string\") {\n const host = hostOf(node.value)\n return host ? { host } : null\n }\n if (node.type === \"TemplateLiteral\") {\n const head = node.quasis?.[0]?.value?.cooked ?? node.quasis?.[0]?.value?.raw ?? \"\"\n const host = hostOf(head)\n if (host) return { host }\n // `${process.env.SAP_BASE_URL}/path` — the base is the first hole.\n if (head === \"\") {\n const key = envKeyOf(node.expressions?.[0])\n if (key) return { envKey: key }\n }\n return null\n }\n if (node.type === \"BinaryExpression\" && node.operator === \"+\") return externalTargetOf(node.left)\n if (node.type === \"MemberExpression\") {\n const key = envKeyOf(node)\n return key ? { envKey: key } : null\n }\n if (node.type === \"NewExpression\" && node.callee?.name === \"URL\") {\n // new URL(path, base): the base decides the host; new URL(absolute) has no base.\n const args = node.arguments ?? []\n return externalTargetOf(args[1]) ?? externalTargetOf(args[0])\n }\n return null\n}\n\nfunction isHttpClientCall(node: AstNode): boolean {\n const callee = node.callee\n if (!callee) return false\n if (callee.type === \"Identifier\") return HTTP_CLIENTS.includes(callee.name ?? \"\")\n if (callee.type === \"MemberExpression\") {\n return (\n callee.object?.type === \"Identifier\" &&\n HTTP_LIBS.includes(callee.object.name ?? \"\") &&\n callee.property?.type === \"Identifier\" &&\n HTTP_METHODS.test(callee.property.name ?? \"\")\n )\n }\n return false\n}\n\n/**\n * An outbound call to a host this app has not declared. Advisory: the rule\n * reads one argument, so it sees a spelled-out host or an env-backed base and\n * nothing more. The manifest extractor does the same classification at deploy\n * time and the portal shows the result; this is the editor-time echo of it.\n */\nconst noUndeclaredExternalCall: Rule.RuleModule = {\n meta: meta(\"QDC-NET-002 - outbound call to an external API this app has not declared\", \"suggestion\"),\n create(context) {\n return listener({\n CallExpression: (node) => {\n if (!isHttpClientCall(node)) return\n const target = externalTargetOf(node.arguments?.[0])\n if (!target) return\n let label: string\n if (\"host\" in target) {\n if (isLocalHost(target.host) || isPlatformManagedHost(target.host)) return\n label = target.host\n } else {\n // CONN_* is a wired module connection: the portal already knows the other end.\n if (target.envKey.startsWith(\"CONN_\")) return\n label = `$${target.envKey}`\n }\n context.report({\n node: node as unknown as Rule.Node,\n message: `QDC-NET-002 - ${label} is an external API this app has not declared. Declare it in src/config/integrations.ts and call integration(alias).get/post, so the portal can see and manage it.`,\n })\n },\n })\n },\n}\n\n/** The calls on an integration handle that send a request, and where their path sits. */\nconst INTEGRATION_PATH_ARG: Record<string, number> = { get: 0, post: 0, put: 0, patch: 0, delete: 0, request: 1 }\n/** Reads off a handle that send nothing, so taking them through a variable hides no endpoint. */\nconst INTEGRATION_READS = [\"config\", \"alias\", \"definition\"]\n\nconst isStringLiteral = (node: AstNode | undefined): boolean =>\n node?.type === \"Literal\" && typeof node.value === \"string\"\n\n/**\n * An integration call the portal cannot read. The manifest extractor reads\n * exactly `integration(\"alias\").get(\"/path\")`, alias and path written at the\n * call site, because it reads source, not values. A path passed in through a\n * helper, an alias held in a variable, or a handle stored and called later all\n * reach the API fine and leave the portal's Integrations tab short of that\n * endpoint, with nothing failing to say so. Advisory, like QDC-NET-002.\n */\nconst integrationStaticCall: Rule.RuleModule = {\n meta: meta(\"QDC-NET-003 - an integration call whose alias or path the portal cannot read\", \"suggestion\"),\n create(context) {\n const report = (node: AstNode, message: string) => {\n context.report({ node: node as unknown as Rule.Node, message: `QDC-NET-003 - ${message}` })\n }\n return listener({\n CallExpression: (node) => {\n if (node.callee?.type !== \"Identifier\" || node.callee.name !== \"integration\") return\n if (!isStringLiteral(node.arguments?.[0])) {\n report(\n node,\n 'the alias is not a string literal, so the portal cannot tell which integration this calls. Write integration(\"alias\") here.',\n )\n return\n }\n const member = node.parent\n const method =\n member?.type === \"MemberExpression\" && member.object === node && member.property?.type === \"Identifier\"\n ? (member.property.name ?? \"\")\n : \"\"\n if (INTEGRATION_READS.includes(method)) return\n const call = member?.parent\n const index = INTEGRATION_PATH_ARG[method]\n if (index === undefined || call?.type !== \"CallExpression\" || call.callee !== member) {\n report(\n node,\n 'the integration handle is stored or passed on instead of called here, so the portal cannot see the endpoints called through it. Write integration(\"alias\").get(\"/path\") at each call site.',\n )\n return\n }\n const path = call.arguments?.[index]\n if (path === undefined || isStringLiteral(path) || path.type === \"TemplateLiteral\") return\n report(\n path,\n \"the path is not written at the call site, so the portal cannot list this endpoint. Write it as a string or template literal here, e.g. `/orders/${id}`. A helper may share options, never the path.\",\n )\n },\n })\n },\n}\n\nexport const rules: Record<string, Rule.RuleModule> = {\n \"no-dangerous-html\": ban(\n \"QDC-XSS-001\",\n \"dangerouslySetInnerHTML renders unescaped markup. Render text, or sanitise it first.\",\n [\"JSXAttribute[name.name='dangerouslySetInnerHTML']\"],\n ),\n \"no-inner-html\": ban(\n \"QDC-XSS-002\",\n \"Assigning innerHTML parses the string as markup. Use textContent.\",\n [\n \"AssignmentExpression[left.type='MemberExpression'][left.property.name=/^(innerHTML|outerHTML)$/]\",\n ],\n ),\n \"no-insert-adjacent-html\": ban(\n \"QDC-XSS-003\",\n \"insertAdjacentHTML parses its argument as markup. Build the nodes instead.\",\n [\"CallExpression[callee.property.name='insertAdjacentHTML']\"],\n ),\n \"no-document-write\": ban(\n \"QDC-XSS-004\",\n \"document.write parses its argument as markup and blocks the parser. Render it in React.\",\n [\"CallExpression[callee.object.name='document'][callee.property.name=/^write(ln)?$/]\"],\n ),\n \"no-string-eval\": noStringEval,\n \"no-raw-script-tag\": ban(\n \"QDC-CSP-001\",\n \"A hand-written <script> gets no nonce, and this app's CSP uses 'strict-dynamic', so it will not run. Use next/script.\",\n [\"JSXElement[openingElement.name.name='script']\"],\n ),\n \"no-sql-interpolation\": ban(\n \"QDC-SQL-001\",\n \"An interpolated string reaching .execute() is the injection. Use the sql tag, which parameterises.\",\n [\n \"CallExpression[callee.property.name='execute'] > TemplateLiteral[expressions.length>0]\",\n \"CallExpression[callee.property.name='execute'] > BinaryExpression[operator='+']\",\n ],\n ),\n \"no-sql-raw\": ban(\n \"QDC-SQL-002\",\n \"sql.raw() puts its argument into the query verbatim and sanitises nothing. Interpolate through the sql tag.\",\n [\"MemberExpression[object.name='sql'][property.name='raw']\"],\n ),\n \"no-driver-import\": banImports(\n \"QDC-SQL-003\",\n \"The database driver belongs in the db layer. Everywhere else, go through Drizzle.\",\n DB_DRIVERS,\n DB_LAYER,\n ),\n \"no-fs-import\": banImports(\n \"QDC-FS-001\",\n \"Request handlers should not reach the filesystem. If one must, use safeJoin from @quatronic/sdk/node/fspath.\",\n FS_MODULES,\n FS_CALLERS,\n ),\n \"safe-redirect\": safeRedirect,\n \"safe-fetch\": safeFetch,\n \"no-undeclared-external-call\": noUndeclaredExternalCall,\n \"integration-static-call\": integrationStaticCall,\n}\n\n/**\n * Rule name to QDC id, for docs and for anything that wants to assert the set\n * without re-deriving it from the messages.\n */\nexport const RULE_IDS: Record<string, string> = {\n \"no-dangerous-html\": \"QDC-XSS-001\",\n \"no-inner-html\": \"QDC-XSS-002\",\n \"no-insert-adjacent-html\": \"QDC-XSS-003\",\n \"no-document-write\": \"QDC-XSS-004\",\n \"no-string-eval\": \"QDC-XSS-005\",\n \"no-raw-script-tag\": \"QDC-CSP-001\",\n \"no-sql-interpolation\": \"QDC-SQL-001\",\n \"no-sql-raw\": \"QDC-SQL-002\",\n \"no-driver-import\": \"QDC-SQL-003\",\n \"no-fs-import\": \"QDC-FS-001\",\n \"safe-redirect\": \"QDC-URL-001\",\n \"safe-fetch\": \"QDC-NET-001\",\n \"no-undeclared-external-call\": \"QDC-NET-002\",\n \"integration-static-call\": \"QDC-NET-003\",\n}\n","import type { Rule } from \"eslint\"\n\nimport type { AstNode } from \"./ast\"\nimport { listener, meta, reporter } from \"./rules\"\n\n/**\n * The web/mobile boundary, as lint rules.\n *\n * A Qore module with a phone app has two programs in one repository: the Next\n * server in `src/` and the Expo app in `mobile/`. They share a package and\n * nothing else — the phone can only reach its own server over HTTP, and the\n * server never runs React Native. Docs say so; these rules are what holds an\n * agent to it, because the wrong import compiles fine until Metro or Next\n * meets it at the app's build.\n */\n\n/** SDK entries and packages that only run on a server or in a browser. */\nconst WEB_ONLY = [\"@quatronic/sdk/next/\", \"@quatronic/sdk/node/\", \"react-dom\", \"next\", \"next/\"]\n/** Entries and packages that only run in React Native. */\nconst DEVICE_ONLY = [\"@quatronic/sdk/expo/\", \"react-native\", \"react-native/\", \"expo-\", \"@react-native/\", \"@react-native-community/\"]\n\nconst matches = (source: string, prefixes: readonly string[]) =>\n prefixes.some((p) => (p.endsWith(\"/\") || p.endsWith(\"-\") ? source.startsWith(p) : source === p || source.startsWith(`${p}/`)))\n\nfunction banPrefixes(id: string, message: string, prefixes: readonly string[]): Rule.RuleModule {\n const text = `${id} - ${message}`\n return {\n meta: meta(text, \"problem\"),\n create(context) {\n const report = reporter(context, text)\n const flag = (node: AstNode) => {\n const source = node.source\n if (source?.type === \"Literal\" && typeof source.value === \"string\" && matches(source.value, prefixes)) report(node)\n }\n return listener({ ImportDeclaration: flag, ImportExpression: flag, ExportAllDeclaration: flag, ExportNamedDeclaration: flag })\n },\n }\n}\n\n/** `process.env.NAME`, the only form Expo inlines at build time. */\nfunction envName(node: AstNode): string | null {\n const object = node.object\n if (object?.type !== \"MemberExpression\") return null\n if (object.object?.type !== \"Identifier\" || object.object.name !== \"process\") return null\n if (object.property?.type !== \"Identifier\" || object.property.name !== \"env\") return null\n if (node.property?.type === \"Identifier\" && !node.computed) return node.property.name ?? null\n if (node.property?.type === \"Literal\" && typeof node.property.value === \"string\") return node.property.value\n return null\n}\n\nconst SECRET_WORD = /SECRET|TOKEN|PASSWORD|PRIVATE|(^|_)KEY($|_)/\nconst PUBLIC_ALLOWED = new Set([\"EXPO_PUBLIC_SENTRY_DSN\"])\n\nconst noSecretPublicEnv: Rule.RuleModule = {\n meta: meta(\"QDC-MOB-002 - no secret in an EXPO_PUBLIC_* variable\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-MOB-002 - every EXPO_PUBLIC_* value is compiled into the app and readable by anyone who installs it. A secret belongs on the app's server; call it through apiFetch.\",\n )\n return listener({\n MemberExpression: (node) => {\n const name = envName(node)\n if (name?.startsWith(\"EXPO_PUBLIC_\") && !PUBLIC_ALLOWED.has(name) && SECRET_WORD.test(name.slice(12))) report(node)\n },\n })\n },\n}\n\nconst noPrivateEnv: Rule.RuleModule = {\n meta: meta(\"QDC-MOB-003 - the phone only has EXPO_PUBLIC_* variables\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-MOB-003 - only EXPO_PUBLIC_* variables reach the phone; anything else is undefined at runtime. Server configuration stays on the server.\",\n )\n return listener({\n MemberExpression: (node) => {\n const name = envName(node)\n if (name && !name.startsWith(\"EXPO_PUBLIC_\") && name !== \"NODE_ENV\") report(node)\n },\n })\n },\n}\n\nconst noRawFetch: Rule.RuleModule = {\n meta: meta(\"QDC-MOB-004 - the phone calls its server through apiFetch\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-MOB-004 - call the app's own server through apiFetch from @quatronic/sdk/expo/auth: it adds the session, the app version and the trace, and refuses any other host. A third-party API is called from the server.\",\n )\n return listener({\n \"CallExpression[callee.name='fetch']\": report,\n \"CallExpression[callee.type='MemberExpression'][callee.property.name='fetch'][callee.object.name=/^(globalThis|window|global)$/]\": report,\n })\n },\n}\n\nexport const mobileRules: Record<string, Rule.RuleModule> = {\n \"no-web-import\": banPrefixes(\n \"QDC-MOB-001\",\n \"This is the phone app. Server and web entries (@quatronic/sdk/next/*, node/*, react-dom, next) do not run in React Native; use @quatronic/sdk/expo/*.\",\n WEB_ONLY,\n ),\n \"no-secret-public-env\": noSecretPublicEnv,\n \"no-private-env\": noPrivateEnv,\n \"no-raw-fetch\": noRawFetch,\n \"no-mobile-import\": banPrefixes(\n \"QDC-MOB-005\",\n \"This is the Next app. @quatronic/sdk/expo/*, react-native and expo-* run on the phone only and belong in mobile/.\",\n DEVICE_ONLY,\n ),\n}\n\nexport const MOBILE_RULE_IDS: Record<string, string> = {\n \"no-web-import\": \"QDC-MOB-001\",\n \"no-secret-public-env\": \"QDC-MOB-002\",\n \"no-private-env\": \"QDC-MOB-003\",\n \"no-raw-fetch\": \"QDC-MOB-004\",\n \"no-mobile-import\": \"QDC-MOB-005\",\n}\n","import type { Rule } from \"eslint\"\n\nimport type { AstNode } from \"./ast\"\nimport { listener, meta, reporter } from \"./rules\"\n\nconst SENTRY_MODULE = /^@sentry\\//\nconst BANNED = new Set([\"init\", \"withSentryConfig\"])\nconst SPAN_STARTERS = new Set([\"startSpan\", \"startSpanManual\", \"startInactiveSpan\"])\nconst CAPTURES = new Set([\"captureException\", \"captureMessage\"])\nconst LOG_LEVELS = new Set([\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"])\nconst KEY_SETTERS = new Set([\"setAttribute\", \"setTag\"])\nconst OBJECT_SETTERS = new Set([\"setAttributes\", \"setTags\"])\nconst SPAN_RECEIVER = /^(span|\\w*Span)$/\nconst SCOPE_RECEIVER = /^(scope|\\w*Scope)$/\nconst SPAN_GETTERS = new Set([\"getActiveSpan\", \"getRootSpan\"])\nconst SCOPE_GETTERS = new Set([\"getCurrentScope\", \"getIsolationScope\"])\nconst PII =\n /(^|[._-])(e-?mail|phone|password|passwd|token|secret|iban|bsn|ssn|ip_?address|first_?name|last_?name|full_?name|username)($|[._-])/i\n\n/** Local names bound to `@sentry/*` (namespace, default, or a named export). */\nfunction trackSentry() {\n const namespaces = new Set<string>()\n const named = new Map<string, string>()\n return {\n namespaces,\n named,\n onImport(node: AstNode, onBanned?: (n: AstNode) => void) {\n const src = node.source?.value\n if (typeof src !== \"string\" || !SENTRY_MODULE.test(src)) return\n for (const s of node.specifiers ?? []) {\n const local = s.local?.name ?? \"\"\n if (s.type === \"ImportNamespaceSpecifier\" || s.type === \"ImportDefaultSpecifier\") namespaces.add(local)\n else if (s.type === \"ImportSpecifier\") {\n const imported = s.imported?.name ?? \"\"\n named.set(local, imported)\n if (BANNED.has(imported)) onBanned?.(s)\n }\n }\n },\n }\n}\n\nconst keyOf = (prop: AstNode): string | undefined => {\n if (prop.type !== \"Property\" || prop.computed) return undefined\n if (prop.key?.type === \"Identifier\") return prop.key.name\n return typeof prop.key?.value === \"string\" ? prop.key.value : undefined\n}\n\nconst objectKeys = (node: AstNode | undefined): [string, AstNode][] =>\n node?.type === \"ObjectExpression\"\n ? (node.properties ?? []).flatMap((p) => {\n const k = keyOf(p)\n return k === undefined ? [] : [[k, p] as [string, AstNode]]\n })\n : []\n\nconst propertyNamed = (node: AstNode | undefined, name: string): AstNode | undefined =>\n node?.type === \"ObjectExpression\"\n ? ((node.properties ?? []).find((p) => keyOf(p) === name)?.value as AstNode | undefined)\n : undefined\n\n/** Reports every attribute, tag or log-field key the app hands Sentry. */\nfunction attributeKeyRule(\n id: string,\n description: string,\n check: (key: string) => string | undefined,\n): Rule.RuleModule {\n return {\n meta: meta(`${id} - ${description}`, \"suggestion\"),\n create(context) {\n const sentry = trackSentry()\n const flag = (key: string, node: AstNode) => {\n const problem = check(key)\n if (problem) reporter(context, `${id} - ${problem}`)(node)\n }\n return listener({\n ImportDeclaration: (node) => sentry.onImport(node),\n CallExpression: (node) => {\n const callee = node.callee\n const args = node.arguments ?? []\n let name: string | undefined\n let viaSentry = false\n if (callee?.type === \"Identifier\") {\n name = sentry.named.get(callee.name ?? \"\")\n viaSentry = name !== undefined\n } else if (callee?.type === \"MemberExpression\") {\n name = callee.property?.name\n const obj = callee.object\n viaSentry =\n (obj?.type === \"Identifier\" && sentry.namespaces.has(obj.name ?? \"\")) ||\n (obj?.type === \"MemberExpression\" &&\n obj.property?.name === \"logger\" &&\n obj.object?.type === \"Identifier\" &&\n sentry.namespaces.has(obj.object.name ?? \"\")) ||\n (obj?.type === \"Identifier\" && sentry.named.get(obj.name ?? \"\") === \"logger\")\n }\n if (!name) return\n const obj = callee?.type === \"MemberExpression\" ? callee.object : undefined\n const sentryCall = (names: Set<string>) =>\n obj?.type === \"CallExpression\" &&\n ((obj.callee?.type === \"Identifier\" && names.has(sentry.named.get(obj.callee.name ?? \"\") ?? \"\")) ||\n (obj.callee?.type === \"MemberExpression\" &&\n obj.callee.object?.type === \"Identifier\" &&\n sentry.namespaces.has(obj.callee.object.name ?? \"\") &&\n names.has(obj.callee.property?.name ?? \"\")))\n const recv = obj?.type === \"Identifier\" ? (obj.name ?? \"\") : \"\"\n const spanRecv = SPAN_RECEIVER.test(recv) || sentryCall(SPAN_GETTERS)\n const tagRecv = viaSentry || SCOPE_RECEIVER.test(recv) || sentryCall(SCOPE_GETTERS)\n const keys: [string, AstNode][] = []\n if (\n KEY_SETTERS.has(name) &&\n (name === \"setAttribute\" ? spanRecv : tagRecv) &&\n args[0]?.type === \"Literal\" &&\n typeof args[0].value === \"string\"\n ) {\n keys.push([args[0].value, args[0]])\n } else if (OBJECT_SETTERS.has(name) && (name === \"setAttributes\" ? spanRecv : tagRecv)) {\n keys.push(...objectKeys(args[0]))\n } else if (viaSentry && SPAN_STARTERS.has(name)) {\n keys.push(...objectKeys(propertyNamed(args[0], \"attributes\")))\n } else if (viaSentry && CAPTURES.has(name)) {\n keys.push(...objectKeys(propertyNamed(args[1], \"tags\")))\n } else if (viaSentry && LOG_LEVELS.has(name) && callee?.type === \"MemberExpression\") {\n keys.push(...objectKeys(args[1]))\n }\n for (const [key, at] of keys) flag(key, at)\n },\n })\n },\n }\n}\n\nconst noSentryInit: Rule.RuleModule = {\n meta: meta(\"QDC-OBS-001 - the SDK owns Sentry.init and withSentryConfig\", \"problem\"),\n create(context) {\n const report = reporter(\n context,\n \"QDC-OBS-001 - @quatronic/sdk owns Sentry.init and withSentryConfig. Use Sentry.* directly; see the qore-observability skill.\",\n )\n const sentry = trackSentry()\n return listener({\n ImportDeclaration: (node) => sentry.onImport(node, report),\n CallExpression: (node) => {\n const c = node.callee\n if (\n c?.type === \"MemberExpression\" &&\n c.object?.type === \"Identifier\" &&\n sentry.namespaces.has(c.object.name ?? \"\") &&\n BANNED.has(c.property?.name ?? \"\")\n ) {\n report(node)\n }\n },\n })\n },\n}\n\nexport const observabilityRules: Record<string, Rule.RuleModule> = {\n \"no-sentry-init\": noSentryInit,\n \"sentry-attribute-namespace\": attributeKeyRule(\n \"QDC-OBS-002\",\n \"custom attribute, tag and log keys are qore.<area>.<name>\",\n (key) =>\n key.startsWith(\"qore.\") ? undefined : `'${key}' is not namespaced. Use qore.<area>.<name>, e.g. qore.invoice.id.`,\n ),\n \"no-pii-attributes\": attributeKeyRule(\"QDC-OBS-003\", \"no personal data in telemetry keys\", (key) =>\n PII.test(key)\n ? `'${key}' looks like personal data. Send an id instead; see the qore-observability skill.`\n : undefined,\n ),\n}\n\nexport const OBSERVABILITY_RULE_IDS: Record<string, string> = {\n \"no-sentry-init\": \"QDC-OBS-001\",\n \"sentry-attribute-namespace\": \"QDC-OBS-002\",\n \"no-pii-attributes\": \"QDC-OBS-003\",\n}\n","import type { Linter, Rule } from \"eslint\"\n\nimport { MOBILE_RULE_IDS, mobileRules } from \"./mobile\"\nimport { observabilityRules } from \"./observability\"\nimport { RULE_IDS, rules } from \"./rules\"\n\nexport { MOBILE_RULE_IDS, mobileRules } from \"./mobile\"\nexport { OBSERVABILITY_RULE_IDS, observabilityRules } from \"./observability\"\nexport { RULE_IDS, rules } from \"./rules\"\n\n/**\n * The QDC security ESLint plugin.\n *\n * It lives here rather than in each generated app because a lint rule is the\n * cheapest security control QDC has, and a rule copied into every app can only\n * be tightened by editing every app. Shipped from the SDK, a corrected rule\n * reaches an app on its next `@quatronic/sdk` bump — the same bump the app\n * pays for everything else in the package.\n *\n * Usage in a generated app's `eslint.config.mjs`:\n *\n * import qdcSecurity from \"@quatronic/sdk/eslint\"\n *\n * export default [\n * ...whatever,\n * ...qdcSecurity.configs.recommended,\n * ]\n *\n * A repository that predates the pack spreads `configs.warn` instead — the\n * same rules and scopes, reporting rather than blocking — and promotes itself\n * to `recommended` once its backlog is clear.\n *\n * The rules are syntactic by design. Anything that has to follow a value\n * across functions and files is a Semgrep rule instead, in this package's\n * `semgrep/` directory, run by the same CI job.\n */\nconst plugin = {\n meta: { name: \"@quatronic/sdk/eslint\" },\n rules: { ...rules, ...observabilityRules, ...mobileRules },\n}\n\n/** Where a generated app keeps the code these rules are about. */\nconst SRC_FILES = [\"src/**/*.{ts,tsx}\"]\nconst TEST_FILES = [\"**/*.test.{ts,tsx}\", \"**/*.spec.{ts,tsx}\"]\n\nexport interface QdcSecurityConfigs {\n recommended: Linter.Config[]\n /**\n * The same rules, in the same scopes, with every enabled one demoted to\n * \"warn\".\n *\n * For a codebase that predates the pack. Adopting fourteen rules at \"error\"\n * into an existing tree means either a red build on day one or a hand-copied\n * override block in that repo — and a hand-copied block stops covering the\n * pack the moment a fifteenth rule ships, while still reporting green. So\n * the demotion lives here, next to the list it demotes.\n *\n * It is a starting position, not a destination: a pack that warns forever is\n * not a control. Promote the repo to `recommended` once its backlog is clear.\n */\n warn: Linter.Config[]\n /**\n * Telemetry rules for apps whose runtime code logs through Sentry only.\n * Separate from `recommended` so a bump does not turn an older app's lint red.\n */\n observability: Linter.Config[]\n /**\n * For the Expo app in a module's `mobile/` directory, spread from\n * `mobile/eslint.config.js`. Its `src/` is the phone's code: no server\n * imports, no secrets or server variables, and every request through\n * `apiFetch`. The web counterpart is `qdc/no-mobile-import` in `recommended`.\n */\n expo: Linter.Config[]\n}\n\n/**\n * The plugin object, typed explicitly: an inferred type here reaches into\n * `@eslint/core` and TypeScript refuses to name it in a `.d.ts`.\n */\nexport interface QdcSecurityPlugin {\n meta: { name: string }\n rules: Record<string, Rule.RuleModule>\n configs: QdcSecurityConfigs\n RULE_IDS: Record<string, string>\n}\n\n/**\n * Two blocks, spread into a flat config in this order.\n *\n * The second one is not decoration: a test that proves escaping works has to\n * build the markup it escapes, so the XSS bans are off there. It is a separate\n * block because flat-config rule options **replace** rather than merge — a\n * later block naming a rule wins outright — so the exemption has to come after\n * the block that switches the rules on, and has to name only what it exempts.\n */\nconst recommended: Linter.Config[] = [\n {\n files: SRC_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-dangerous-html\": \"error\",\n \"qdc/no-inner-html\": \"error\",\n \"qdc/no-insert-adjacent-html\": \"error\",\n \"qdc/no-document-write\": \"error\",\n \"qdc/no-string-eval\": \"error\",\n \"qdc/no-raw-script-tag\": \"error\",\n \"qdc/no-sql-interpolation\": \"error\",\n \"qdc/no-sql-raw\": \"error\",\n \"qdc/no-driver-import\": \"error\",\n \"qdc/no-fs-import\": \"error\",\n // Advisory, and `eslint .` does not fail on warnings. All three fire on\n // shapes that are often fine, so they prompt a look rather than block a\n // merge; qdc.redirect.tainted and qdc.ssrf.tainted-fetch in the Semgrep\n // pack follow the value and are what actually decide, and the manifest\n // extractor classifies the same hosts at deploy time for the portal.\n \"qdc/safe-redirect\": \"warn\",\n \"qdc/safe-fetch\": \"warn\",\n \"qdc/no-undeclared-external-call\": \"warn\",\n // Advisory too: the call works either way, the portal just cannot list it.\n \"qdc/integration-static-call\": \"warn\",\n // The web half of the web/mobile boundary; `configs.expo` holds the other.\n \"qdc/no-mobile-import\": \"error\",\n },\n },\n {\n // Tests build markup on purpose, to prove the escaping works.\n files: TEST_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-dangerous-html\": \"off\",\n \"qdc/no-inner-html\": \"off\",\n \"qdc/no-insert-adjacent-html\": \"off\",\n \"qdc/no-document-write\": \"off\",\n \"qdc/no-raw-script-tag\": \"off\",\n // The two location bans are off here for a different reason than the\n // XSS ones above. They do not say \"this is dangerous\"; they say \"this\n // capability belongs in `src/db` or `src/scripts`, not scattered through\n // the app\", and that argument is about the shape of the *application*. A\n // test reads a fixture off disk and an integration test opens a real\n // connection; neither ships, and neither can be reached by a request, so\n // neither is the traversal or injection surface the ban exists for.\n //\n // Found by running the pack over five live tenant repositories before it\n // started blocking merges: `no-fs-import` fired six times in one repo and\n // every hit was a test reading its own fixture.\n \"qdc/no-fs-import\": \"off\",\n \"qdc/no-driver-import\": \"off\",\n // A test that stubs fetch names the host it stubs; nothing leaves the\n // process, and the portal is told about deploys, not test runs.\n \"qdc/no-undeclared-external-call\": \"off\",\n // A test calls a handle it built itself; no deploy reads it.\n \"qdc/integration-static-call\": \"off\",\n },\n },\n]\n\n/**\n * \"off\" is an exemption, not a severity. Demoting it to \"warn\" would switch a\n * rule back on in the scope that deliberately turned it off — the test-file\n * block below being the whole reason that distinction matters.\n */\nconst demote = (config: Linter.Config): Linter.Config => ({\n ...config,\n rules: Object.fromEntries(\n Object.entries(config.rules ?? {}).map(([id, level]) => [\n id,\n level === \"off\" ? \"off\" : \"warn\",\n ]),\n ),\n})\n\nconst warn: Linter.Config[] = recommended.map(demote)\n\nconst observability: Linter.Config[] = [\n {\n files: SRC_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-sentry-init\": \"error\",\n \"no-console\": \"error\",\n \"qdc/sentry-attribute-namespace\": \"warn\",\n \"qdc/no-pii-attributes\": \"warn\",\n },\n },\n {\n // CLI tools and tests print on purpose.\n files: [\"**/seed.ts\", \"src/scripts/**\", ...TEST_FILES],\n rules: { \"no-console\": \"off\" },\n },\n]\n\nconst expo: Linter.Config[] = [\n {\n files: SRC_FILES,\n plugins: { qdc: plugin },\n rules: {\n \"qdc/no-web-import\": \"error\",\n \"qdc/no-secret-public-env\": \"error\",\n \"qdc/no-private-env\": \"error\",\n \"qdc/no-raw-fetch\": \"error\",\n \"qdc/no-string-eval\": \"error\",\n // Phone logs go through `log` from @quatronic/sdk/expo/log, which reaches Sentry.\n \"no-console\": \"error\",\n },\n },\n {\n // Tests stub fetch and print on purpose; the jest setup reads its own env.\n files: [...TEST_FILES, \"**/__tests__/**\"],\n rules: { \"qdc/no-raw-fetch\": \"off\", \"qdc/no-private-env\": \"off\", \"no-console\": \"off\" },\n },\n]\n\nexport const configs: QdcSecurityConfigs = { recommended, warn, observability, expo }\n\nconst qdcSecurity: QdcSecurityPlugin = { ...plugin, configs, RULE_IDS: { ...RULE_IDS, ...MOBILE_RULE_IDS } }\n\nexport default qdcSecurity\n"],"mappings":";;;;;AAyCO,IAAM,eAAe,CAAC,gBAAgB,aAAa,aAAa,OAAO;AAGvE,SAAS,OAAO,UAA0B;AAC/C,SAAO,SAAS,WAAW,MAAM,GAAG;AACtC;AAGO,SAAS,QAAQ,UAAkB,OAAmC;AAC3E,QAAM,OAAO,OAAO,QAAQ;AAC5B,SAAO,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,EAAE,KAAK,KAAK,SAAS,IAAI,IAAI,GAAG,CAAC;AACrF;AAGO,SAAS,WAAW,MAAuB;AAChD,QAAM,SAAS,KAAK;AACpB,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO,SAAS,aAAc,QAAO,OAAO,QAAQ;AACxD,MAAI,OAAO,SAAS,sBAAsB,OAAO,UAAU,SAAS,cAAc;AAChF,WAAO,OAAO,SAAS,QAAQ;AAAA,EACjC;AACA,SAAO;AACT;AAWO,SAAS,cAAc,MAA2B,iBAAmC;AAC1F,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI,KAAK,SAAS,UAAW,QAAO,OAAO,KAAK,UAAU;AAC1D,MAAI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kBAAkB,GAAG,UAAU;AAAA,IACrD,OAAO,EAAE,cAAc,MAAM;AAAA,EAC/B;AACF;AAEA,IAAM,OAAwB;AAAA,EAC5B;AAAA,IACE,OAAO;AAAA,IACP,SAAS,EAAE,KAAK,OAAO;AAAA,IACvB,OAAO;AAAA,MACL,qBAAqB;AAAA,MACrB,4BAA4B;AAAA,MAC5B,sBAAsB;AAAA,MACtB,oBAAoB;AAAA,MACpB,sBAAsB;AAAA;AAAA,MAEtB,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EACA;AAAA;AAAA,IAEE,OAAO,CAAC,GAAG,YAAY,iBAAiB;AAAA,IACxC,OAAO,EAAE,oBAAoB,OAAO,sBAAsB,OAAO,cAAc,MAAM;AAAA,EACvF;AACF;AAEO,IAAM,UAA8B,EAAE,aAAa,MAAM,eAAe,KAAK;AAEpF,IAAM,cAAiC,EAAE,GAAG,QAAQ,SAAS,UAAU,EAAE,GAAG,UAAU,GAAG,gBAAgB,EAAE;AAE3G,IAAO,iBAAQ;","names":["obj"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { M as MobileAuthOptions, a as MobileAuth } from '../../context-B_u-vpkw.js';
|
|
2
|
+
export { A as ApiError, b as AuthContextValue, c as AuthStatus, C as Can, L as LoginFailure, d as LoginResult, e as Me, Q as QoreAuthProvider, f as QoreAuthProviderProps, S as SignedOutNotice, U as Unauthenticated, u as useAuth, g as useCan, h as useMe } from '../../context-B_u-vpkw.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
/** The device auth client for the app's own server. Create it once, at module scope. */
|
|
6
|
+
declare function createMobileAuth(opts: MobileAuthOptions): MobileAuth;
|
|
7
|
+
|
|
8
|
+
export { MobileAuth, MobileAuthOptions, createMobileAuth };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Can,
|
|
3
|
+
QoreAuthProvider,
|
|
4
|
+
useAuth,
|
|
5
|
+
useCan,
|
|
6
|
+
useMe
|
|
7
|
+
} from "../../chunk-7XIDABOQ.js";
|
|
8
|
+
import {
|
|
9
|
+
ApiError,
|
|
10
|
+
Unauthenticated
|
|
11
|
+
} from "../../chunk-YXIYI7R2.js";
|
|
12
|
+
|
|
13
|
+
// src/expo/core/pkce.ts
|
|
14
|
+
var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
15
|
+
function base64url(bytes) {
|
|
16
|
+
let out = "";
|
|
17
|
+
let i = 0;
|
|
18
|
+
for (; i + 2 < bytes.length; i += 3) {
|
|
19
|
+
const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
|
|
20
|
+
out += ALPHABET[n >> 18 & 63] + ALPHABET[n >> 12 & 63] + ALPHABET[n >> 6 & 63] + ALPHABET[n & 63];
|
|
21
|
+
}
|
|
22
|
+
const rest = bytes.length - i;
|
|
23
|
+
if (rest === 1) {
|
|
24
|
+
const n = bytes[i] << 16;
|
|
25
|
+
out += ALPHABET[n >> 18 & 63] + ALPHABET[n >> 12 & 63];
|
|
26
|
+
} else if (rest === 2) {
|
|
27
|
+
const n = bytes[i] << 16 | bytes[i + 1] << 8;
|
|
28
|
+
out += ALPHABET[n >> 18 & 63] + ALPHABET[n >> 12 & 63] + ALPHABET[n >> 6 & 63];
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function base64ToUrl(b64) {
|
|
33
|
+
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
34
|
+
}
|
|
35
|
+
async function createPkce(crypto) {
|
|
36
|
+
const verifier = base64url(crypto.randomBytes(32));
|
|
37
|
+
const challenge = base64ToUrl(await crypto.sha256Base64(verifier));
|
|
38
|
+
return { verifier, challenge };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/expo/core/url.ts
|
|
42
|
+
function queryParam(url, name) {
|
|
43
|
+
const query = url.split("#", 1)[0].split("?")[1];
|
|
44
|
+
if (!query) return null;
|
|
45
|
+
for (const pair of query.split("&")) {
|
|
46
|
+
const i = pair.indexOf("=");
|
|
47
|
+
const key = i < 0 ? pair : pair.slice(0, i);
|
|
48
|
+
if (safeDecode(key) !== name) continue;
|
|
49
|
+
return i < 0 ? "" : safeDecode(pair.slice(i + 1).replace(/\+/g, " "));
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function safeDecode(s) {
|
|
54
|
+
try {
|
|
55
|
+
return decodeURIComponent(s);
|
|
56
|
+
} catch {
|
|
57
|
+
return s;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function normalizeOrigin(serverUrl) {
|
|
61
|
+
return serverUrl.replace(/\/+$/, "");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/expo/auth/client.ts
|
|
65
|
+
var TOKEN_KEY = "qore.session";
|
|
66
|
+
var SERVER_REASONS = /* @__PURE__ */ new Set(["cancelled", "expired", "no_app_access", "identity_mismatch", "failed"]);
|
|
67
|
+
function createMobileAuthWith(platform, opts) {
|
|
68
|
+
const origin = normalizeOrigin(opts.serverUrl);
|
|
69
|
+
const versionHeader = opts.appVersion ? { "x-qore-app-version": opts.appVersion } : void 0;
|
|
70
|
+
function headers(init, token) {
|
|
71
|
+
const h = new Headers(init);
|
|
72
|
+
if (versionHeader) h.set("x-qore-app-version", versionHeader["x-qore-app-version"]);
|
|
73
|
+
if (token) h.set("authorization", `Bearer ${token}`);
|
|
74
|
+
return h;
|
|
75
|
+
}
|
|
76
|
+
async function apiFetch(path, init = {}) {
|
|
77
|
+
if (!path.startsWith("/") || path.startsWith("//")) throw new Error(`apiFetch takes a path on the app's own server, got "${path}"`);
|
|
78
|
+
const token = await platform.store.get(TOKEN_KEY);
|
|
79
|
+
if (!token) throw new Unauthenticated();
|
|
80
|
+
const res = await platform.fetch(`${origin}${path}`, { ...init, headers: headers(init.headers, token) });
|
|
81
|
+
if (res.status === 401) {
|
|
82
|
+
await platform.store.delete(TOKEN_KEY);
|
|
83
|
+
throw new Unauthenticated();
|
|
84
|
+
}
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const body = await res.json().catch(() => null);
|
|
87
|
+
throw new ApiError(res.status, typeof body?.error === "string" ? body.error : null);
|
|
88
|
+
}
|
|
89
|
+
if (res.status === 204) return void 0;
|
|
90
|
+
return await res.json();
|
|
91
|
+
}
|
|
92
|
+
async function login(locale) {
|
|
93
|
+
const { verifier, challenge } = await createPkce(platform);
|
|
94
|
+
const returnUrl = platform.returnUrl();
|
|
95
|
+
const url = `${origin}/api/auth/mobile/login?challenge=${encodeURIComponent(challenge)}&redirect=${encodeURIComponent(returnUrl)}&locale=${encodeURIComponent(locale)}`;
|
|
96
|
+
const back = await platform.openAuthSession(url, returnUrl);
|
|
97
|
+
if (back === null) return { ok: false, reason: "cancelled" };
|
|
98
|
+
const error = queryParam(back, "error");
|
|
99
|
+
if (error !== null) return { ok: false, reason: SERVER_REASONS.has(error) ? error : "failed", detail: error };
|
|
100
|
+
const code = queryParam(back, "code");
|
|
101
|
+
if (!code) return { ok: false, reason: "failed", detail: "no_code" };
|
|
102
|
+
let res;
|
|
103
|
+
try {
|
|
104
|
+
res = await platform.fetch(`${origin}/api/auth/mobile/redeem`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: headers({ "content-type": "application/json" }),
|
|
107
|
+
body: JSON.stringify({ code, verifier })
|
|
108
|
+
});
|
|
109
|
+
} catch {
|
|
110
|
+
return { ok: false, reason: "failed", detail: "network" };
|
|
111
|
+
}
|
|
112
|
+
const body = await res.json().catch(() => null);
|
|
113
|
+
if (!res.ok || typeof body?.token !== "string") {
|
|
114
|
+
const detail = typeof body?.error === "string" ? body.error : `http_${res.status}`;
|
|
115
|
+
return { ok: false, reason: detail === "invalid_grant" ? "expired" : "failed", detail };
|
|
116
|
+
}
|
|
117
|
+
await platform.store.set(TOKEN_KEY, body.token);
|
|
118
|
+
return { ok: true };
|
|
119
|
+
}
|
|
120
|
+
async function logout() {
|
|
121
|
+
const token = await platform.store.get(TOKEN_KEY);
|
|
122
|
+
await platform.store.delete(TOKEN_KEY);
|
|
123
|
+
if (!token) return;
|
|
124
|
+
await platform.fetch(`${origin}/api/auth/mobile/logout`, { method: "POST", headers: headers(void 0, token) }).catch(() => void 0);
|
|
125
|
+
}
|
|
126
|
+
async function openPasswordReset(locale) {
|
|
127
|
+
await platform.openBrowser(`${origin}/api/auth/mobile/reset-password?locale=${encodeURIComponent(locale)}`);
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
login,
|
|
131
|
+
logout,
|
|
132
|
+
apiFetch,
|
|
133
|
+
openPasswordReset,
|
|
134
|
+
hasSession: async () => await platform.store.get(TOKEN_KEY) !== null,
|
|
135
|
+
serverUrl: origin
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/expo/auth/native.ts
|
|
140
|
+
import * as Crypto from "expo-crypto";
|
|
141
|
+
import * as Linking from "expo-linking";
|
|
142
|
+
import * as SecureStore from "expo-secure-store";
|
|
143
|
+
import * as WebBrowser from "expo-web-browser";
|
|
144
|
+
var nativeAuthPlatform = {
|
|
145
|
+
randomBytes: (n) => Crypto.getRandomBytes(n),
|
|
146
|
+
sha256Base64: (input) => Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, input, { encoding: Crypto.CryptoEncoding.BASE64 }),
|
|
147
|
+
store: {
|
|
148
|
+
get: (key) => SecureStore.getItemAsync(key),
|
|
149
|
+
set: (key, value) => SecureStore.setItemAsync(key, value),
|
|
150
|
+
delete: (key) => SecureStore.deleteItemAsync(key)
|
|
151
|
+
},
|
|
152
|
+
returnUrl: () => Linking.createURL("auth/return"),
|
|
153
|
+
openAuthSession: async (url, returnUrl) => {
|
|
154
|
+
const result = await WebBrowser.openAuthSessionAsync(url, returnUrl);
|
|
155
|
+
return result.type === "success" ? result.url : null;
|
|
156
|
+
},
|
|
157
|
+
openBrowser: async (url) => {
|
|
158
|
+
await WebBrowser.openBrowserAsync(url);
|
|
159
|
+
},
|
|
160
|
+
fetch: (input, init) => fetch(input, init)
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/expo/auth/index.ts
|
|
164
|
+
function createMobileAuth(opts) {
|
|
165
|
+
return createMobileAuthWith(nativeAuthPlatform, opts);
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
ApiError,
|
|
169
|
+
Can,
|
|
170
|
+
QoreAuthProvider,
|
|
171
|
+
Unauthenticated,
|
|
172
|
+
createMobileAuth,
|
|
173
|
+
useAuth,
|
|
174
|
+
useCan,
|
|
175
|
+
useMe
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=index.js.map
|