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.

terminal
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>

Flags and output are on redline metrics.

The 33 defects

SeedSeverityRule it violatesDefect
1BLOCKERcore/hardcoded-secretsdatabase password committed in source
1BLOCKERsvelte/async-store-startthe Promise is called as the stop function
1BLOCKERsvelte/module-context-shared-statemodule-scope state shared by every instance and every SSR request
2BLOCKERsvelte/secret-in-universal-loadinternal-only credential used in code that also runs in the browser
2BLOCKERsvelte/browser-global-at-top-levellocalStorage on the server is a 500
2BLOCKERsvelte/private-env-in-shared-codeprivate env imported from a component, so it ships to the browser
3BLOCKERcore/query-string-concatenationroute param concatenated into a sql string
3BLOCKERcore/hardcoded-secretsfallback token committed in source
4BLOCKERcore/customer-data-in-logsmsisdn written to the log on teardown
5BLOCKERsvelte/html-tag-sinkunsanitised markdown output injected into the page -->
7BLOCKERcore/customer-data-in-logsmsisdn written to the log
7BLOCKERcore/customer-data-in-logsmsisdn written to the console
9BLOCKERsvelte/html-tag-sinkunsanitised user html injected into the page -->
1HIGHsvelte/load-in-page-componentSvelteKit never calls load from a .svelte file
1HIGHsvelte/reactive-statement-side-effecta reactive block performing a fetch
2HIGHsvelte/effect-for-derived-statea reactive block assigning what a derived value already gives
3HIGHsvelte/non-reactive-builtin-in-stateSet mutations never update the view
3HIGHsvelte/store-not-unsubscribedsubscribed without keeping the unsubscriber
4HIGHsvelte/global-fetch-in-loadglobal fetch in load — no cookie forwarding, no SSR reuse
4HIGHsvelte/store-or-signal-as-valuethe store object is always truthy -->
4HIGHsvelte/effect-for-derived-statederived value computed in an effect instead of $derived
5HIGHsvelte/load-waterfallindependent requests awaited in sequence
5HIGHsvelte/double-brace-mustacherenders [object Object] -->
5HIGHsvelte/effect-missing-cleanupinterval registered with no teardown returned
6HIGHsvelte/error-swallowed-in-loadfailure rendered as "no data" instead of an error
6HIGHsvelte/handler-not-functiondeletes every item on render -->
6HIGHsvelte/store-not-unsubscribedmanual subscribe whose unsubscriber is dropped
6HIGHsvelte/each-missing-keyunkeyed each over a list that is refetched per query -->
7HIGHsvelte/bound-node-dom-mutationremoves a node Svelte still owns -->
8HIGHsvelte/state-mutation-across-boundarychild writing to an object the parent owns
10HIGHsvelte/each-missing-keyunkeyed each over a list that reorders -->
11HIGHjavascript/var-in-new-codefunction-scoped var in new code inside a single-file component
12HIGHjavascript/unsafe-numeric-coercionparseInt 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.

The full file

seeded/svelte/+layout.svelte · 6 lines · 0.3 KB
<!-- 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>
seeded/svelte/+page.js · 43 lines · 1.8 KB
// 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,
  };
}
seeded/svelte/AntiSlop.svelte · 35 lines · 1.4 KB
<!-- 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>
seeded/svelte/SeededViolations.svelte · 75 lines · 2.7 KB
<!--
  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>
seeded/svelte/SeededViolationsLegacy.svelte · 53 lines · 1.6 KB
<!--
  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>