svelte
Seeded Svelte and SvelteKit defects — {@html}, private env in shared code, secrets in a universal load.
33 deliberate defects, each with a marker naming the rule in standards/ it breaks. It measures recall: how many of the defects the reviewer flags at their severity or higher. The pass condition is that all 13 BLOCKER defects are flagged.
Because each marker names a rule, the scorer also grades attribution. A reviewer that finds the bug but cites the wrong rule counts as caught, and separately as misattributed.
Running it
Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.
seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>
Flags and output are on redline metrics.
The 33 defects
| Seed | Severity | Rule it violates | Defect |
|---|---|---|---|
| 1 | BLOCKER | core/hardcoded-secrets | database password committed in source |
| 1 | BLOCKER | svelte/async-store-start | the Promise is called as the stop function |
| 1 | BLOCKER | svelte/module-context-shared-state | module-scope state shared by every instance and every SSR request |
| 2 | BLOCKER | svelte/secret-in-universal-load | internal-only credential used in code that also runs in the browser |
| 2 | BLOCKER | svelte/browser-global-at-top-level | localStorage on the server is a 500 |
| 2 | BLOCKER | svelte/private-env-in-shared-code | private env imported from a component, so it ships to the browser |
| 3 | BLOCKER | core/query-string-concatenation | route param concatenated into a sql string |
| 3 | BLOCKER | core/hardcoded-secrets | fallback token committed in source |
| 4 | BLOCKER | core/customer-data-in-logs | msisdn written to the log on teardown |
| 5 | BLOCKER | svelte/html-tag-sink | unsanitised markdown output injected into the page --> |
| 7 | BLOCKER | core/customer-data-in-logs | msisdn written to the log |
| 7 | BLOCKER | core/customer-data-in-logs | msisdn written to the console |
| 9 | BLOCKER | svelte/html-tag-sink | unsanitised user html injected into the page --> |
| 1 | HIGH | svelte/load-in-page-component | SvelteKit never calls load from a .svelte file |
| 1 | HIGH | svelte/reactive-statement-side-effect | a reactive block performing a fetch |
| 2 | HIGH | svelte/effect-for-derived-state | a reactive block assigning what a derived value already gives |
| 3 | HIGH | svelte/non-reactive-builtin-in-state | Set mutations never update the view |
| 3 | HIGH | svelte/store-not-unsubscribed | subscribed without keeping the unsubscriber |
| 4 | HIGH | svelte/global-fetch-in-load | global fetch in load — no cookie forwarding, no SSR reuse |
| 4 | HIGH | svelte/store-or-signal-as-value | the store object is always truthy --> |
| 4 | HIGH | svelte/effect-for-derived-state | derived value computed in an effect instead of $derived |
| 5 | HIGH | svelte/load-waterfall | independent requests awaited in sequence |
| 5 | HIGH | svelte/double-brace-mustache | renders [object Object] --> |
| 5 | HIGH | svelte/effect-missing-cleanup | interval registered with no teardown returned |
| 6 | HIGH | svelte/error-swallowed-in-load | failure rendered as "no data" instead of an error |
| 6 | HIGH | svelte/handler-not-function | deletes every item on render --> |
| 6 | HIGH | svelte/store-not-unsubscribed | manual subscribe whose unsubscriber is dropped |
| 6 | HIGH | svelte/each-missing-key | unkeyed each over a list that is refetched per query --> |
| 7 | HIGH | svelte/bound-node-dom-mutation | removes a node Svelte still owns --> |
| 8 | HIGH | svelte/state-mutation-across-boundary | child writing to an object the parent owns |
| 10 | HIGH | svelte/each-missing-key | unkeyed each over a list that reorders --> |
| 11 | HIGH | javascript/var-in-new-code | function-scoped var in new code inside a single-file component |
| 12 | HIGH | javascript/unsafe-numeric-coercion | parseInt with no radix on a value from the URL |
Scoring
The score reports BLOCKER recall, false positives, and rule attribution. The canary appends it to data/seed-scores.jsonl and fails the run if BLOCKER recall drops below 1.0 or the clean corpus attracts a false positive. Of the 33 defects here, 13 BLOCKER and 20 HIGH — only the BLOCKER count is a pass condition.
Adding a defect
Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.
Related
- The svelte standard — every rule these defects test.
- seed-canary.yml — runs this corpus every week.
- Telemetry & validation — where the scores end up.
The full file
<!-- DO NOT MERGE — Redline validation seed (anti-slop rules). -->
<script context="module">
// SEED 1 [HIGH] (svelte/load-in-page-component) SvelteKit never calls load from a .svelte file
export async function load({ fetch }) { return { orders: await (await fetch('/api/orders')).json() }; }
</script>
// DO NOT MERGE — Redline validation seed. // Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher, // citing that rule id. Score with scripts/score-seeds.mjs. // // This is a UNIVERSAL load function: it runs on the server and again in the browser. // SEED 1 [BLOCKER] (core/hardcoded-secrets) database password committed in source const DB_URL = 'postgres://redline:[email protected]:5432/billing'; export async function load({ params, url, fetch: eventFetch }) { // SEED 2 [BLOCKER] (svelte/secret-in-universal-load) internal-only credential used in code that also runs in the browser const db = await connect(DB_URL); // SEED 3 [BLOCKER] (core/query-string-concatenation) route param concatenated into a sql string const account = await db.query(`select * from accounts where id = '${params.id}'`); // SEED 4 [HIGH] (svelte/global-fetch-in-load) global fetch in load — no cookie forwarding, no SSR reuse const orders = await fetch(`/api/accounts/${params.id}/orders`); // SEED 5 [HIGH] (svelte/load-waterfall) independent requests awaited in sequence const invoices = await eventFetch(`/api/accounts/${params.id}/invoices`); const offers = await eventFetch(`/api/accounts/${params.id}/offers`); // SEED 6 [HIGH] (svelte/error-swallowed-in-load) failure rendered as "no data" instead of an error let usage = []; try { usage = await (await eventFetch(`/api/usage?page=${url.searchParams.get('page')}`)).json(); } catch { usage = []; } // SEED 7 [BLOCKER] (core/customer-data-in-logs) msisdn written to the log console.log('loaded account', account.msisdn); return { account, orders: await orders.json(), invoices: await invoices.json(), offers: await offers.json(), usage, }; }
<!-- DO NOT MERGE — Redline validation seed (anti-slop rules). -->
<script>
import { readable } from 'svelte/store';
import { isLoggedIn } from '$lib/stores';
let { user, items } = $props();
// SEED 1 [BLOCKER] (svelte/async-store-start) the Promise is called as the stop function
export const me = readable(null, async (set) => { set(await (await fetch('/api/me')).json()); });
// SEED 2 [BLOCKER] (svelte/browser-global-at-top-level) localStorage on the server is a 500
const theme = localStorage.getItem('theme') ?? 'light';
// SEED 3 [HIGH] (svelte/non-reactive-builtin-in-state) Set mutations never update the view
let selected = $state(new Set());
const toggle = (id) => (selected.has(id) ? selected.delete(id) : selected.add(id));
let panel;
</script>
<!-- SEED 4 [HIGH] (svelte/store-or-signal-as-value) the store object is always truthy -->
{#if isLoggedIn}<p>Admin</p>{/if}
<!-- SEED 5 [HIGH] (svelte/double-brace-mustache) renders [object Object] -->
<h1>Welcome back, {{ user.name }}</h1>
{#each items as item (item.id)}
<!-- SEED 6 [HIGH] (svelte/handler-not-function) deletes every item on render -->
<button onclick={remove(item.id)}>Delete</button>
{/each}
<div bind:this={panel}>Details</div>
<!-- SEED 7 [HIGH] (svelte/bound-node-dom-mutation) removes a node Svelte still owns -->
<button onclick={() => panel.remove()}>Close</button>
<p>{selected.size} selected, theme {theme}</p>
<!--
DO NOT MERGE — Redline validation seed.
Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
citing that rule id. Score with scripts/score-seeds.mjs.
Svelte 5, runes mode. A rune anywhere in a component puts the whole file in runes mode,
where `$:` is a compile error — so the reactive-statement rule is seeded in
SeededViolationsLegacy.svelte instead, which is a Svelte 4 component.
-->
<script module>
// SEED 1 [BLOCKER] (svelte/module-context-shared-state) module-scope state shared by every instance and every SSR request
let lastViewedAccount = { msisdn: '', reference: '' };
</script>
<script>
import { onMount } from 'svelte';
import { page } from '$app/stores';
// SEED 2 [BLOCKER] (svelte/private-env-in-shared-code) private env imported from a component, so it ships to the browser
import { BILLING_API_SECRET } from '$env/static/private';
// SEED 3 [BLOCKER] (core/hardcoded-secrets) fallback token committed in source
const FALLBACK_TOKEN = 'fbk-live-Rn2Kd9Wm4Tz6Hb3Vy7Q';
let { profile } = $props();
let orders = $state([]);
let total = $state(0);
// SEED 4 [HIGH] (svelte/effect-for-derived-state) derived value computed in an effect instead of $derived
$effect(() => {
total = orders.length;
});
onMount(() => {
// SEED 5 [HIGH] (svelte/effect-missing-cleanup) interval registered with no teardown returned
setInterval(
() =>
fetch('/api/heartbeat', {
headers: { authorization: `Bearer ${BILLING_API_SECRET ?? FALLBACK_TOKEN}` },
}),
5000
);
// SEED 6 [HIGH] (svelte/store-not-unsubscribed) manual subscribe whose unsubscriber is dropped
page.subscribe((p) => {
lastViewedAccount = { msisdn: profile.msisdn, reference: p.url.pathname };
});
});
// SEED 7 [BLOCKER] (core/customer-data-in-logs) msisdn written to the console
console.log('viewing', profile.msisdn);
// SEED 8 [HIGH] (svelte/state-mutation-across-boundary) child writing to an object the parent owns
function markSeen() {
profile.seen = true;
}
// SEED 11 [HIGH] (javascript/var-in-new-code) function-scoped var in new code inside a single-file component
var retries = 0;
// SEED 12 [HIGH] (javascript/unsafe-numeric-coercion) parseInt with no radix on a value from the URL
const perPage = parseInt($page.url.searchParams.get('perPage'));
</script>
<!-- SEED 9 [BLOCKER] (svelte/html-tag-sink) unsanitised user html injected into the page -->
{@html profile.bio}
<ul>
<!-- SEED 10 [HIGH] (svelte/each-missing-key) unkeyed each over a list that reorders -->
{#each orders as order}
<li>{order.reference}</li>
{/each}
</ul>
<button onclick={markSeen}>seen ({total})</button>
<!--
DO NOT MERGE — Redline validation seed.
Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
citing that rule id. Score with scripts/score-seeds.mjs.
Svelte 4 syntax deliberately: `$:` and `export let` cannot appear in a component that
uses runes, and both are still what most onboarded Svelte code looks like.
-->
<script>
import { onDestroy } from 'svelte';
import { cartStore } from '$lib/stores/cart';
export let profile;
export let query = '';
let results = [];
let total = 0;
// SEED 1 [HIGH] (svelte/reactive-statement-side-effect) a reactive block performing a fetch
$: if (query) {
fetch(`/api/search?q=${query}`)
.then((r) => r.json())
.then((r) => (results = r));
}
// SEED 2 [HIGH] (svelte/effect-for-derived-state) a reactive block assigning what a derived value already gives
$: {
total = results.length;
}
// SEED 3 [HIGH] (svelte/store-not-unsubscribed) subscribed without keeping the unsubscriber
cartStore.subscribe((c) => {
profile.cartSize = c.items.length;
});
onDestroy(() => {
// SEED 4 [BLOCKER] (core/customer-data-in-logs) msisdn written to the log on teardown
console.log('closing panel for', profile.msisdn);
});
</script>
<!-- SEED 5 [BLOCKER] (svelte/html-tag-sink) unsanitised markdown output injected into the page -->
{@html profile.bioHtml}
<ul>
<!-- SEED 6 [HIGH] (svelte/each-missing-key) unkeyed each over a list that is refetched per query -->
{#each results as result}
<li>{result.reference}</li>
{/each}
</ul>
<p>{total} results</p>