@open-mercato/cli 0.10.1-develop.7600.1.57704c3ffb → 0.10.1-develop.7614.1.75d5ac1a6a
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/.turbo/turbo-build.log +1 -1
- package/dist/agentic/guides/module-facts.json +152 -152
- package/dist/agentic/guides/module-facts.v2.json +152 -152
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/agentic/shared/ai/skills/om-setup-ci/SKILL.md +42 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/scripts/setup-ci.mjs +525 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/scripts/verify-semgrep-rules.mjs +54 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/docs/README.md +463 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/actions/gitleaks/action.yml +25 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/actions/playwright/action.yml +31 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/actions/setup/action.yml +55 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/dependabot.yml +27 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/workflows/audit.yml +193 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/workflows/ci.yml +477 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/workflows/codeql.yml +63 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/github/workflows/security.yml +254 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/audit-ci-allowlist.json +4 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/audit-ci.mjs +283 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/semgrep/open-mercato.fixture.txt +89 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/semgrep/open-mercato.yml +146 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/time-bomb-scanner.mjs +286 -0
- package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/zap-rules.tsv +11 -0
- package/dist/agentic/shared/ai/skills/tiers.json +2 -1
- package/package.json +7 -7
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as cp from 'node:child_process'
|
|
2
|
+
import { exec, execFile, execSync, spawn } from 'node:child_process'
|
|
3
|
+
import { NextResponse, type NextRequest } from 'next/server'
|
|
4
|
+
import { redirect } from 'next/navigation'
|
|
5
|
+
import { sql } from 'kysely'
|
|
6
|
+
|
|
7
|
+
const ORDERS_TABLE = 'orders'
|
|
8
|
+
const THEME_SCRIPT = 'document.documentElement.dataset.theme = "dark"'
|
|
9
|
+
|
|
10
|
+
export async function GET(req: NextRequest, em: any, db: any, cookies: any) {
|
|
11
|
+
const input = req.nextUrl.searchParams.get('q') ?? ''
|
|
12
|
+
|
|
13
|
+
// ruleid: om-dynamic-code-execution
|
|
14
|
+
eval(input)
|
|
15
|
+
// ruleid: om-dynamic-code-execution
|
|
16
|
+
const compiled = new Function('a', input)
|
|
17
|
+
// ok: om-dynamic-code-execution
|
|
18
|
+
eval('1 + 1')
|
|
19
|
+
|
|
20
|
+
// ruleid: om-dynamic-shell-command
|
|
21
|
+
exec('ls ' + input)
|
|
22
|
+
// ruleid: om-dynamic-shell-command
|
|
23
|
+
execSync(`git log ${input}`)
|
|
24
|
+
// ruleid: om-dynamic-shell-command
|
|
25
|
+
spawn('sh', ['-c', input], { shell: true })
|
|
26
|
+
// ok: om-dynamic-shell-command
|
|
27
|
+
execFile('git', ['log', input])
|
|
28
|
+
// ok: om-dynamic-shell-command
|
|
29
|
+
exec('ls -la')
|
|
30
|
+
// ruleid: om-dynamic-shell-command
|
|
31
|
+
cp.exec(input)
|
|
32
|
+
// ok: om-dynamic-shell-command
|
|
33
|
+
new RegExp('a(b)').exec(input)
|
|
34
|
+
const matcher = /a(b)/
|
|
35
|
+
// ok: om-dynamic-shell-command
|
|
36
|
+
matcher.exec(input)
|
|
37
|
+
|
|
38
|
+
// ruleid: om-raw-sql-interpolation
|
|
39
|
+
await sql.raw(`select * from users where name = '${input}'`).execute(db)
|
|
40
|
+
// ruleid: om-raw-sql-interpolation
|
|
41
|
+
await em.execute(`delete from orders where id = ${input}`)
|
|
42
|
+
// ruleid: om-raw-sql-interpolation
|
|
43
|
+
await db.query('select * from t where a = ' + input)
|
|
44
|
+
// ok: om-raw-sql-interpolation
|
|
45
|
+
await sql`select * from users where name = ${input}`.execute(db)
|
|
46
|
+
// ok: om-raw-sql-interpolation
|
|
47
|
+
await em.execute('delete from orders where id = ?', [input])
|
|
48
|
+
const placeholders = [input].map(() => '?').join(', ')
|
|
49
|
+
// ok: om-raw-sql-interpolation
|
|
50
|
+
await em.execute(`select id from orders where id in (${placeholders})`, [input])
|
|
51
|
+
// ok: om-raw-sql-interpolation
|
|
52
|
+
await db.execute(`select 1 from ${ORDERS_TABLE} where id = ?`, [input])
|
|
53
|
+
const owned = { sql: 'owner_id = ?', params: [input] }
|
|
54
|
+
// ok: om-raw-sql-interpolation
|
|
55
|
+
await db.execute(`select * from reports where ${owned.sql}`, owned.params)
|
|
56
|
+
const orgClause = ' and organization_id = ?'
|
|
57
|
+
// ok: om-raw-sql-interpolation
|
|
58
|
+
await db.execute(`select * from reports where id = ?${orgClause}`, [input, input])
|
|
59
|
+
// ruleid: om-raw-sql-interpolation
|
|
60
|
+
await db.execute(`select * from reports order by ${input}`)
|
|
61
|
+
|
|
62
|
+
// ruleid: om-cookie-without-httponly
|
|
63
|
+
cookies.set('session', input, { httpOnly: false, secure: true })
|
|
64
|
+
// ok: om-cookie-without-httponly
|
|
65
|
+
cookies.set('session', input, { httpOnly: true, secure: true })
|
|
66
|
+
|
|
67
|
+
if (input === 'a') {
|
|
68
|
+
// ruleid: om-open-redirect
|
|
69
|
+
return NextResponse.redirect(new URL(req.nextUrl.searchParams.get('next') ?? '/', req.url))
|
|
70
|
+
}
|
|
71
|
+
// ruleid: om-open-redirect
|
|
72
|
+
redirect(req.nextUrl.searchParams.get('next') ?? '/')
|
|
73
|
+
// ok: om-open-redirect
|
|
74
|
+
redirect('/backend')
|
|
75
|
+
return compiled
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function Page({ html }: { html: string }) {
|
|
79
|
+
return (
|
|
80
|
+
<>
|
|
81
|
+
{/* ruleid: om-dangerously-set-inner-html */}
|
|
82
|
+
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
83
|
+
{/* ok: om-dangerously-set-inner-html */}
|
|
84
|
+
<div dangerouslySetInnerHTML={{ __html: '<b>static</b>' }} />
|
|
85
|
+
{/* ok: om-dangerously-set-inner-html */}
|
|
86
|
+
<script dangerouslySetInnerHTML={{ __html: THEME_SCRIPT }} />
|
|
87
|
+
</>
|
|
88
|
+
)
|
|
89
|
+
}
|
package/dist/agentic/shared/ai/skills/om-setup-ci/templates/scripts/ci/semgrep/open-mercato.yml
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Generated by the Open Mercato om-setup-ci skill. Documentation: docs/ci/README.md
|
|
2
|
+
#
|
|
3
|
+
# Open Mercato security rules for Semgrep Community Edition. The public
|
|
4
|
+
# registry rulesets barely cover Next.js route handlers and server actions,
|
|
5
|
+
# so these rules target the patterns that matter in an Open Mercato app.
|
|
6
|
+
# Silence a reviewed false positive with a trailing `// nosemgrep: <rule-id>`
|
|
7
|
+
# comment that explains why the line is safe.
|
|
8
|
+
rules:
|
|
9
|
+
- id: om-dynamic-code-execution
|
|
10
|
+
languages: [typescript, javascript]
|
|
11
|
+
severity: ERROR
|
|
12
|
+
message: >-
|
|
13
|
+
Code built at runtime is executed. Anything an attacker can influence
|
|
14
|
+
becomes remote code execution. Use a lookup table or a parser instead.
|
|
15
|
+
metadata:
|
|
16
|
+
cwe: 'CWE-95: Eval Injection'
|
|
17
|
+
category: security
|
|
18
|
+
patterns:
|
|
19
|
+
- pattern-either:
|
|
20
|
+
- pattern: eval($CODE)
|
|
21
|
+
- pattern: new Function(..., $CODE)
|
|
22
|
+
- pattern: Function(..., $CODE)
|
|
23
|
+
- pattern: vm.runInNewContext($CODE, ...)
|
|
24
|
+
- pattern: vm.runInThisContext($CODE, ...)
|
|
25
|
+
- pattern-not: eval("...")
|
|
26
|
+
- pattern-not: new Function(..., "...")
|
|
27
|
+
- pattern-not: Function(..., "...")
|
|
28
|
+
|
|
29
|
+
- id: om-dynamic-shell-command
|
|
30
|
+
languages: [typescript, javascript]
|
|
31
|
+
severity: ERROR
|
|
32
|
+
message: >-
|
|
33
|
+
A shell command is assembled from a variable. Use execFile/spawn with an
|
|
34
|
+
argument array (no shell) so input can never be parsed as shell syntax.
|
|
35
|
+
metadata:
|
|
36
|
+
cwe: "CWE-78: OS Command Injection"
|
|
37
|
+
category: security
|
|
38
|
+
pattern-either:
|
|
39
|
+
- patterns:
|
|
40
|
+
- pattern-either:
|
|
41
|
+
- pattern-inside: |
|
|
42
|
+
import { ..., exec, ... } from "$MODULE"
|
|
43
|
+
...
|
|
44
|
+
- pattern-inside: |
|
|
45
|
+
import { ..., execSync, ... } from "$MODULE"
|
|
46
|
+
...
|
|
47
|
+
- metavariable-regex:
|
|
48
|
+
metavariable: $MODULE
|
|
49
|
+
regex: '^(node:)?child_process$'
|
|
50
|
+
- pattern-either:
|
|
51
|
+
- pattern: exec($CMD, ...)
|
|
52
|
+
- pattern: execSync($CMD, ...)
|
|
53
|
+
- metavariable-regex:
|
|
54
|
+
metavariable: $CMD
|
|
55
|
+
regex: '^(?!([''"])[^''"]*\1$|`[^`$]*`$)'
|
|
56
|
+
- patterns:
|
|
57
|
+
- pattern-either:
|
|
58
|
+
- pattern: $CP.exec($CMD, ...)
|
|
59
|
+
- pattern: $CP.execSync($CMD, ...)
|
|
60
|
+
- metavariable-regex:
|
|
61
|
+
metavariable: $CP
|
|
62
|
+
regex: '^(cp|childProcess|child_process|childProcesses)$'
|
|
63
|
+
- metavariable-regex:
|
|
64
|
+
metavariable: $CMD
|
|
65
|
+
regex: '^(?!([''"])[^''"]*\1$|`[^`$]*`$)'
|
|
66
|
+
- pattern: '$CP.$FN(..., {..., shell: true, ...})'
|
|
67
|
+
- pattern: '$FN(..., {..., shell: true, ...})'
|
|
68
|
+
|
|
69
|
+
- id: om-raw-sql-interpolation
|
|
70
|
+
languages: [typescript, javascript]
|
|
71
|
+
severity: ERROR
|
|
72
|
+
message: >-
|
|
73
|
+
A raw SQL string is built with interpolation. Use the query builder or
|
|
74
|
+
bound parameters (Kysely `sql` tagged template, MikroORM `em.execute(sql,
|
|
75
|
+
params)`) so values are never spliced into SQL text.
|
|
76
|
+
metadata:
|
|
77
|
+
cwe: "CWE-89: SQL Injection"
|
|
78
|
+
category: security
|
|
79
|
+
patterns:
|
|
80
|
+
- pattern-either:
|
|
81
|
+
- pattern: sql.raw(`...${$X}...`)
|
|
82
|
+
- pattern: $DB.raw(`...${$X}...`, ...)
|
|
83
|
+
- pattern: $DB.execute(`...${$X}...`, ...)
|
|
84
|
+
- pattern: $DB.query(`...${$X}...`, ...)
|
|
85
|
+
- pattern: sql.raw("..." + $X)
|
|
86
|
+
- pattern: $DB.raw("..." + $X, ...)
|
|
87
|
+
- pattern: $DB.execute("..." + $X, ...)
|
|
88
|
+
- pattern: $DB.query("..." + $X, ...)
|
|
89
|
+
# Safe idioms for dynamic SQL are not flagged: a constant (a table name),
|
|
90
|
+
# a generated list of `?` placeholders, and a parameterized fragment from
|
|
91
|
+
# a clause builder that returns `{ sql, params }` (`${clause.sql}`).
|
|
92
|
+
- metavariable-regex:
|
|
93
|
+
metavariable: $X
|
|
94
|
+
regex: '^(?![A-Z][A-Z0-9_]*$)(?!.*[Pp]laceholders?$)(?!.*\.sql$)(?!.*(Clause|clause|Fragment|fragment)$)'
|
|
95
|
+
|
|
96
|
+
- id: om-dangerously-set-inner-html
|
|
97
|
+
languages: [typescript, javascript]
|
|
98
|
+
severity: WARNING
|
|
99
|
+
message: >-
|
|
100
|
+
HTML from a variable is injected into the page. Render it as text, or
|
|
101
|
+
sanitize it first (for example with DOMPurify) and mark the reviewed
|
|
102
|
+
line with `// nosemgrep: om-dangerously-set-inner-html`.
|
|
103
|
+
metadata:
|
|
104
|
+
cwe: "CWE-79: Cross-site Scripting"
|
|
105
|
+
category: security
|
|
106
|
+
patterns:
|
|
107
|
+
- pattern: '<$EL dangerouslySetInnerHTML={{__html: $HTML}} />'
|
|
108
|
+
- pattern-not: '<$EL dangerouslySetInnerHTML={{__html: "..."}} />'
|
|
109
|
+
- metavariable-regex:
|
|
110
|
+
metavariable: $HTML
|
|
111
|
+
regex: '^(?![A-Z][A-Z0-9_]*$)'
|
|
112
|
+
|
|
113
|
+
- id: om-open-redirect
|
|
114
|
+
languages: [typescript, javascript]
|
|
115
|
+
severity: WARNING
|
|
116
|
+
message: >-
|
|
117
|
+
The redirect target comes straight from the request. Redirect only to a
|
|
118
|
+
relative path you validated, or to an allowlisted host.
|
|
119
|
+
metadata:
|
|
120
|
+
cwe: "CWE-601: Open Redirect"
|
|
121
|
+
category: security
|
|
122
|
+
patterns:
|
|
123
|
+
- pattern-either:
|
|
124
|
+
- pattern: redirect($TARGET, ...)
|
|
125
|
+
- pattern: NextResponse.redirect($TARGET, ...)
|
|
126
|
+
- pattern: Response.redirect($TARGET, ...)
|
|
127
|
+
- metavariable-pattern:
|
|
128
|
+
metavariable: $TARGET
|
|
129
|
+
pattern-either:
|
|
130
|
+
- pattern: $SOURCE.searchParams.get(...)
|
|
131
|
+
- pattern: $SOURCE.nextUrl.searchParams.get(...)
|
|
132
|
+
- pattern: $HEADERS.get("referer")
|
|
133
|
+
- pattern: $SEARCH_PARAMS.get(...)
|
|
134
|
+
|
|
135
|
+
- id: om-cookie-without-httponly
|
|
136
|
+
languages: [typescript, javascript]
|
|
137
|
+
severity: WARNING
|
|
138
|
+
message: >-
|
|
139
|
+
A cookie is set with `httpOnly: false`, so page scripts (and any XSS) can
|
|
140
|
+
read it. Keep session and auth cookies httpOnly.
|
|
141
|
+
metadata:
|
|
142
|
+
cwe: "CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag"
|
|
143
|
+
category: security
|
|
144
|
+
pattern-either:
|
|
145
|
+
- pattern: '$COOKIES.set($NAME, $VALUE, {..., httpOnly: false, ...})'
|
|
146
|
+
- pattern: '$COOKIES.set({..., httpOnly: false, ...})'
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Time-bomb test scanner.
|
|
3
|
+
//
|
|
4
|
+
// A "time-bomb" test is one that hardcodes an absolute date/datetime literal
|
|
5
|
+
// whose pass/fail outcome depends on the wall clock at run time. The classic
|
|
6
|
+
// failure mode (see issue #2384) is a literal that was "just over the horizon"
|
|
7
|
+
// when authored and asserted as valid/future — it silently flips to failing
|
|
8
|
+
// once that timestamp elapses, turning CI red on unrelated PRs.
|
|
9
|
+
//
|
|
10
|
+
// This scanner walks test files, extracts absolute date literals, and uses the
|
|
11
|
+
// surrounding lines (±2) to judge whether the assertion is clock-dependent:
|
|
12
|
+
//
|
|
13
|
+
// HIGH — future literal asserted as future-valid (will flip when it elapses),
|
|
14
|
+
// or a future-validity assertion whose literal has already elapsed
|
|
15
|
+
// (likely failing right now).
|
|
16
|
+
// MEDIUM — near-future fixture literal (becomes past soon), or a far-future
|
|
17
|
+
// (> 5y) "slow" time-bomb, or an ambiguous past-in-validity-context.
|
|
18
|
+
// LOW — literal echoed in an equality/format assertion (both sides
|
|
19
|
+
// hardcoded → not clock-dependent), or a plain past fixture.
|
|
20
|
+
//
|
|
21
|
+
// Intentional "rejects past datetime" tests (a past literal asserted to throw)
|
|
22
|
+
// are recognised and NOT flagged. The safe, time-independent patterns
|
|
23
|
+
// (`Date.now()`, `new Date()`, `new Date(Date.now() + 60_000)`) contain no
|
|
24
|
+
// literal and are naturally ignored.
|
|
25
|
+
//
|
|
26
|
+
// Usage:
|
|
27
|
+
// node scripts/time-bomb-scanner.mjs [--json] [--all] [--fail]
|
|
28
|
+
// [--fail-on=high|medium] [--now=<ISO>] [path ...]
|
|
29
|
+
|
|
30
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
|
|
31
|
+
import path from 'node:path'
|
|
32
|
+
|
|
33
|
+
const root = process.cwd()
|
|
34
|
+
const rawArgs = process.argv.slice(2)
|
|
35
|
+
const flags = new Set(rawArgs.filter((a) => a.startsWith('--')))
|
|
36
|
+
const positional = rawArgs.filter((a) => !a.startsWith('--'))
|
|
37
|
+
|
|
38
|
+
const json = flags.has('--json')
|
|
39
|
+
const includeLow = flags.has('--all')
|
|
40
|
+
const shouldFail = flags.has('--fail')
|
|
41
|
+
|
|
42
|
+
function flagValue(name, fallback) {
|
|
43
|
+
const hit = rawArgs.find((a) => a.startsWith(`${name}=`))
|
|
44
|
+
return hit ? hit.split('=').slice(1).join('=') : fallback
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const failOn = flagValue('--fail-on', 'high').toLowerCase()
|
|
48
|
+
const nowArg = flagValue('--now', null)
|
|
49
|
+
const now = nowArg ? new Date(nowArg).getTime() : Date.now()
|
|
50
|
+
if (Number.isNaN(now)) {
|
|
51
|
+
console.error(`Invalid --now value: ${nowArg}`)
|
|
52
|
+
process.exit(2)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const allowlistPath = path.join(root, '.ai/time-bomb-allowlist.json')
|
|
56
|
+
|
|
57
|
+
const YEAR_MS = 365 * 24 * 60 * 60 * 1000
|
|
58
|
+
const FAR_FUTURE_YEARS = 5
|
|
59
|
+
const CONTEXT_RADIUS = 2 // lines of context examined on each side of a literal
|
|
60
|
+
const SEVERITY_ORDER = { high: 3, medium: 2, low: 1 }
|
|
61
|
+
const IGNORE_DIRS = new Set(['node_modules', '.next', '.mercato', 'dist', 'coverage', 'generated', '.git'])
|
|
62
|
+
const TEST_FILE_RE = /(?:\.(?:test|spec)\.[mc]?[jt]sx?$)|(?:[\\/]__tests__[\\/])/
|
|
63
|
+
const SENTINEL_YEAR = 9000 // years >= this are treated as never-expiring sentinels (e.g. 9999-12-31)
|
|
64
|
+
|
|
65
|
+
// Quoted ISO-8601 date or datetime literal, e.g. '2026-06-01T12:00:00.000Z' or "2025-01-01".
|
|
66
|
+
const ISO_LITERAL_RE =
|
|
67
|
+
/(['"`])(\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:?\d{2})?)?)\1/g
|
|
68
|
+
|
|
69
|
+
// Context markers.
|
|
70
|
+
const VALIDITY_RE = /\buntil\b|isFuture|\bfuture\b|must be a future|toBeGreaterThan|isAfter\b/i
|
|
71
|
+
const REJECT_RE = /\.toThrow|toThrow\(/
|
|
72
|
+
const ACCEPT_RE = /not\.toThrow/
|
|
73
|
+
const ECHO_RE = /\.(?:toBe|toEqual|toStrictEqual|toContain)\(|toHaveValue\(|toHaveBeenCalledWith\(/
|
|
74
|
+
|
|
75
|
+
function loadAllowlist() {
|
|
76
|
+
if (!existsSync(allowlistPath)) return { locations: new Set(), literals: new Set() }
|
|
77
|
+
try {
|
|
78
|
+
const parsed = JSON.parse(readFileSync(allowlistPath, 'utf8'))
|
|
79
|
+
const entries = Array.isArray(parsed) ? parsed : parsed.entries ?? []
|
|
80
|
+
const locations = new Set()
|
|
81
|
+
const literals = new Set()
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
const value = typeof entry === 'string' ? entry : entry?.match
|
|
84
|
+
if (!value) continue
|
|
85
|
+
if (/:\d+$/.test(value) || value.includes('/')) locations.add(value)
|
|
86
|
+
else literals.add(value)
|
|
87
|
+
}
|
|
88
|
+
return { locations, literals }
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error(`Failed to parse ${rel(allowlistPath)}: ${err.message}`)
|
|
91
|
+
return { locations: new Set(), literals: new Set() }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function normalize(file) {
|
|
96
|
+
return file.split(path.sep).join('/')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function rel(file) {
|
|
100
|
+
return normalize(path.relative(root, file))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function walk(dir, out = []) {
|
|
104
|
+
if (!existsSync(dir)) return out
|
|
105
|
+
let entries
|
|
106
|
+
try {
|
|
107
|
+
entries = readdirSync(dir)
|
|
108
|
+
} catch {
|
|
109
|
+
return out
|
|
110
|
+
}
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
if (IGNORE_DIRS.has(entry)) continue
|
|
113
|
+
const full = path.join(dir, entry)
|
|
114
|
+
let st
|
|
115
|
+
try {
|
|
116
|
+
st = statSync(full)
|
|
117
|
+
} catch {
|
|
118
|
+
continue
|
|
119
|
+
}
|
|
120
|
+
if (st.isDirectory()) walk(full, out)
|
|
121
|
+
else if (TEST_FILE_RE.test(normalize(full))) out.push(full)
|
|
122
|
+
}
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function classify(timestamp, line, context) {
|
|
127
|
+
const year = new Date(timestamp).getUTCFullYear()
|
|
128
|
+
if (year >= SENTINEL_YEAR) return null // never-expiring sentinel
|
|
129
|
+
|
|
130
|
+
const future = timestamp > now
|
|
131
|
+
const yearsOut = (timestamp - now) / YEAR_MS
|
|
132
|
+
const isValidity = VALIDITY_RE.test(context)
|
|
133
|
+
const expectsReject = REJECT_RE.test(context)
|
|
134
|
+
const expectsAccept = ACCEPT_RE.test(context)
|
|
135
|
+
const isEcho = ECHO_RE.test(line)
|
|
136
|
+
|
|
137
|
+
if (isValidity) {
|
|
138
|
+
if (future) {
|
|
139
|
+
if (yearsOut > FAR_FUTURE_YEARS) {
|
|
140
|
+
return { severity: 'medium', reason: 'far-future validity literal — slow time-bomb' }
|
|
141
|
+
}
|
|
142
|
+
return { severity: 'high', reason: 'future literal in a future-validity assertion — flips when it elapses' }
|
|
143
|
+
}
|
|
144
|
+
// past literal in a future-validity context
|
|
145
|
+
if (expectsReject && !expectsAccept) {
|
|
146
|
+
return null // intentional "rejects past datetime" test — correct by design
|
|
147
|
+
}
|
|
148
|
+
if (expectsAccept) {
|
|
149
|
+
return {
|
|
150
|
+
severity: 'high',
|
|
151
|
+
reason: 'future-validity assertion whose literal has already elapsed — likely failing now',
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { severity: 'medium', reason: 'past literal in a future-validity context — review for clock dependence' }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (isEcho) {
|
|
158
|
+
return { severity: 'low', reason: 'literal echoed in an equality/format assertion — not clock-dependent' }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (future) {
|
|
162
|
+
if (yearsOut > FAR_FUTURE_YEARS) {
|
|
163
|
+
return { severity: 'medium', reason: 'far-future fixture literal — slow time-bomb' }
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
severity: 'medium',
|
|
167
|
+
reason: 'near-future fixture literal — becomes past soon; verify no future-dependent assertion relies on it',
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { severity: 'low', reason: 'past date fixture — usually stable' }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function scanFile(file) {
|
|
174
|
+
const text = readFileSync(file, 'utf8')
|
|
175
|
+
const lines = text.split(/\r?\n/)
|
|
176
|
+
const findings = []
|
|
177
|
+
for (let i = 0; i < lines.length; i++) {
|
|
178
|
+
const line = lines[i]
|
|
179
|
+
const context = lines.slice(Math.max(0, i - CONTEXT_RADIUS), i + CONTEXT_RADIUS + 1).join('\n')
|
|
180
|
+
ISO_LITERAL_RE.lastIndex = 0
|
|
181
|
+
let match
|
|
182
|
+
while ((match = ISO_LITERAL_RE.exec(line)) !== null) {
|
|
183
|
+
const literal = match[2]
|
|
184
|
+
const timestamp = new Date(literal).getTime()
|
|
185
|
+
if (Number.isNaN(timestamp)) continue
|
|
186
|
+
const verdict = classify(timestamp, line, context)
|
|
187
|
+
if (!verdict) continue
|
|
188
|
+
findings.push({
|
|
189
|
+
file: rel(file),
|
|
190
|
+
line: i + 1,
|
|
191
|
+
literal,
|
|
192
|
+
iso: new Date(timestamp).toISOString(),
|
|
193
|
+
severity: verdict.severity,
|
|
194
|
+
reason: verdict.reason,
|
|
195
|
+
snippet: line.trim().slice(0, 160),
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return findings
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const allowlist = loadAllowlist()
|
|
203
|
+
|
|
204
|
+
function isAllowlisted(finding) {
|
|
205
|
+
if (allowlist.literals.has(finding.literal)) return true
|
|
206
|
+
if (allowlist.locations.has(`${finding.file}:${finding.line}`)) return true
|
|
207
|
+
if (allowlist.locations.has(finding.file)) return true
|
|
208
|
+
return false
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const searchRoots = positional.length
|
|
212
|
+
? positional.map((p) => path.resolve(root, p))
|
|
213
|
+
: [path.join(root, 'packages'), path.join(root, 'apps'), path.join(root, 'external')]
|
|
214
|
+
|
|
215
|
+
const files = searchRoots.flatMap((target) => {
|
|
216
|
+
if (!existsSync(target)) return []
|
|
217
|
+
return statSync(target).isDirectory() ? walk(target) : [target]
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
let findings = files
|
|
221
|
+
.flatMap(scanFile)
|
|
222
|
+
.filter((f) => !isAllowlisted(f))
|
|
223
|
+
.filter((f) => includeLow || f.severity !== 'low')
|
|
224
|
+
|
|
225
|
+
findings.sort(
|
|
226
|
+
(a, b) =>
|
|
227
|
+
SEVERITY_ORDER[b.severity] - SEVERITY_ORDER[a.severity] ||
|
|
228
|
+
a.file.localeCompare(b.file) ||
|
|
229
|
+
a.line - b.line
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
const counts = findings.reduce(
|
|
233
|
+
(acc, f) => ((acc[f.severity] = (acc[f.severity] ?? 0) + 1), acc),
|
|
234
|
+
{ high: 0, medium: 0, low: 0 }
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
if (json) {
|
|
238
|
+
console.log(
|
|
239
|
+
JSON.stringify(
|
|
240
|
+
{ now: new Date(now).toISOString(), scannedFiles: files.length, counts, findings },
|
|
241
|
+
null,
|
|
242
|
+
2
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
} else {
|
|
246
|
+
printReport()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function severityLabel(severity) {
|
|
250
|
+
return { high: 'HIGH ', medium: 'MEDIUM', low: 'LOW ' }[severity]
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function printReport() {
|
|
254
|
+
console.log(`Time-bomb test scan`)
|
|
255
|
+
console.log(` reference now : ${new Date(now).toISOString()}`)
|
|
256
|
+
console.log(` test files : ${files.length}`)
|
|
257
|
+
console.log(
|
|
258
|
+
` findings : ${findings.length} (high: ${counts.high}, medium: ${counts.medium}, low: ${counts.low}${
|
|
259
|
+
includeLow ? '' : ' — low hidden, pass --all to show'
|
|
260
|
+
})`
|
|
261
|
+
)
|
|
262
|
+
console.log('')
|
|
263
|
+
|
|
264
|
+
if (findings.length === 0) {
|
|
265
|
+
console.log(' No actionable time-bomb literals detected. ✅')
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
for (const f of findings) {
|
|
270
|
+
console.log(` [${severityLabel(f.severity)}] ${f.file}:${f.line}`)
|
|
271
|
+
console.log(` literal "${f.literal}" → ${f.iso}`)
|
|
272
|
+
console.log(` ${f.reason}`)
|
|
273
|
+
console.log(` ${f.snippet}`)
|
|
274
|
+
console.log('')
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
console.log(' Fix: replace the literal with a clock-relative value computed at run time, e.g.')
|
|
278
|
+
console.log(" const future = new Date(Date.now() + 60_000).toISOString()")
|
|
279
|
+
console.log(` Intentional literals can be allowlisted in ${rel(allowlistPath)}.`)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (shouldFail) {
|
|
283
|
+
const threshold = SEVERITY_ORDER[failOn] ?? SEVERITY_ORDER.high
|
|
284
|
+
const breaching = findings.filter((f) => SEVERITY_ORDER[f.severity] >= threshold)
|
|
285
|
+
if (breaching.length > 0) process.exit(1)
|
|
286
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
10010 WARN (Cookie No HttpOnly Flag — promote to FAIL once every cookie the app sets is reviewed)
|
|
2
|
+
10011 WARN (Cookie Without Secure Flag — the scan runs over plain http on localhost)
|
|
3
|
+
10020 FAIL (Missing Anti-clickjacking Header)
|
|
4
|
+
10021 FAIL (X-Content-Type-Options Header Missing)
|
|
5
|
+
10027 IGNORE (Information Disclosure - Suspicious Comments — Next.js bundles are full of them)
|
|
6
|
+
10036 WARN (Server Leaks Version Information via "Server" HTTP Response Header)
|
|
7
|
+
10037 WARN (X-Powered-By header — set poweredByHeader: false in next.config.ts, then promote to FAIL)
|
|
8
|
+
10038 WARN (Content Security Policy Header Not Set)
|
|
9
|
+
10054 WARN (Cookie without SameSite Attribute — promote to FAIL once every cookie is reviewed)
|
|
10
|
+
10096 IGNORE (Timestamp Disclosure — build hashes and timestamps in bundles)
|
|
11
|
+
90022 FAIL (Application Error Disclosure)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/cli",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@mikro-orm/decorators": "^7.1.14",
|
|
61
61
|
"@mikro-orm/migrations": "^7.1.14",
|
|
62
62
|
"@mikro-orm/postgresql": "^7.1.14",
|
|
63
|
-
"@open-mercato/events": "0.10.1-develop.
|
|
64
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
65
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
66
|
-
"@open-mercato/telemetry": "0.10.1-develop.
|
|
63
|
+
"@open-mercato/events": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
64
|
+
"@open-mercato/queue": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
65
|
+
"@open-mercato/shared": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
66
|
+
"@open-mercato/telemetry": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
67
67
|
"cross-spawn": "^7.0.6",
|
|
68
68
|
"pg": "8.23.0",
|
|
69
69
|
"semver": "^7.8.5",
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
"typescript-js": "npm:typescript@6.0.3"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
77
|
+
"@open-mercato/shared": "0.10.1-develop.7614.1.75d5ac1a6a"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
80
|
+
"@open-mercato/shared": "0.10.1-develop.7614.1.75d5ac1a6a",
|
|
81
81
|
"@types/jest": "^30.0.0",
|
|
82
82
|
"jest": "^30.4.2",
|
|
83
83
|
"ts-jest": "^29.4.12"
|