angular

Seeded Angular defects — a disabled sanitiser, dead subscriptions, an open redirect, work in a template binding.

23 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 9 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 23 defects

SeedSeverityRule it violatesDefect
1BLOCKERcore/hardcoded-secretsapi key committed in source
2BLOCKERcore/escape-hatch-typesany-typed input
3BLOCKERangular/bypass-security-trustsanitiser switched off on user-supplied html
4BLOCKERangular/open-redirect-navigationnavigation target taken straight from a query param
5BLOCKERangular/unsubscribed-subscriptionsubscription with no teardown
6BLOCKERangular/uncancelled-request-racea request per keystroke, merged not switched
8BLOCKERangular/timer-not-clearedinterval never cleared in ngOnDestroy
9BLOCKERcore/customer-data-in-logsmsisdn written to the console
16BLOCKERangular/open-redirect-navigationrouterLink bound to a query-param url -->
1HIGHangular/banana-out-of-boxinverted two-way binding never syncs
1HIGHangular/impure-pipere-runs on every change-detection cycle
2HIGHangular/computed-reads-no-signalreads plain fields, never updates
3HIGHangular/output-native-event-namefires the parent handler twice
4HIGHangular/async-lifecycle-hookAngular never awaits the hook
5HIGHangular/uncalled-signalthe signal function is always truthy
6HIGHangular/injection-context-api-outside-contextNG0203 outside an injection context
7HIGHangular/manual-lifecycle-callre-runs every subscription the hook set up
7HIGHangular/interceptor-swallows-errorfailure returned as an empty success
10HIGHangular/unvalidated-route-paramroute param coerced with no validation
12HIGHangular/input-object-mutationchild writing to an object the parent owns
14HIGHangular/function-call-in-templatemethod called from a binding, so it runs every cycle -->
15HIGHangular/missing-trackbyngFor over a re-fetched list with no trackBy -->
13SUGGESTIONangular/prefer-async-pipemanual subscribe where the async pipe would do

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 23 defects here, 9 BLOCKER, 13 HIGH and 1 SUGGESTION — 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/angular/anti-slop.component.ts · 32 lines · 1.4 KB
// DO NOT MERGE — Redline validation seed (anti-slop rules).
import { Component, EventEmitter, OnInit, Output, computed, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

@Component({
  selector: 'app-anti-slop',
  // SEED 1 [HIGH] (angular/banana-out-of-box) inverted two-way binding never syncs
  template: '<input ([ngModel])="query"><input type="number" (input)="onInput($event)">',
})
export class AntiSlopComponent implements OnInit {
  readonly isAdmin = signal(false);
  first = 'Ada';
  last = 'Lovelace';
  // SEED 2 [HIGH] (angular/computed-reads-no-signal) reads plain fields, never updates
  fullName = computed(() => `${this.first} ${this.last}`);
  // SEED 3 [HIGH] (angular/output-native-event-name) fires the parent handler twice
  @Output() change = new EventEmitter<number>();

  // SEED 4 [HIGH] (angular/async-lifecycle-hook) Angular never awaits the hook
  async ngOnInit() {
    // SEED 5 [HIGH] (angular/uncalled-signal) the signal function is always truthy
    if (this.isAdmin) this.actions.push('delete');
    // SEED 6 [HIGH] (angular/injection-context-api-outside-context) NG0203 outside an injection context
    this.route.params.pipe(takeUntilDestroyed()).subscribe((p) => this.load(p['id']));
  }

  refresh() {
    // SEED 7 [HIGH] (angular/manual-lifecycle-call) re-runs every subscription the hook set up
    this.ngOnInit();
  }
}
seeded/angular/filter-by.pipe.ts · 9 lines · 0.4 KB
// DO NOT MERGE — Redline validation seed (anti-slop rules).
import { Pipe, PipeTransform } from '@angular/core';

// SEED 1 [HIGH] (angular/impure-pipe) re-runs on every change-detection cycle
@Pipe({ name: 'filterBy', standalone: true, pure: false })
export class FilterByPipe implements PipeTransform {
  transform(items: { name: string }[], q: string) { return items.filter((i) => i.name.includes(q)); }
}
seeded/angular/seeded-violations.component.ts · 91 lines · 3.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.
import { Component, Input, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router';
import { catchError, mergeMap, of } from 'rxjs';

// SEED 1 [BLOCKER] (core/hardcoded-secrets) api key committed in source
const PARTNER_API_KEY = 'ptnr-live-51H8xQ2Kd9Wm4Tz6Hb';

@Component({
  selector: 'app-seeded-violations',
  template: `
    <div [innerHTML]="trustedBio"></div>
    <!-- SEED 14 [HIGH] (angular/function-call-in-template) method called from a binding, so it runs every cycle -->
    <p>{{ formatTotal() }}</p>
    <!-- SEED 15 [HIGH] (angular/missing-trackby) ngFor over a re-fetched list with no trackBy -->
    <li *ngFor="let order of orders">{{ order.reference }}</li>
    <!-- SEED 16 [BLOCKER] (angular/open-redirect-navigation) routerLink bound to a query-param url -->
    <a [routerLink]="returnUrl">back</a>
  `,
})
export class SeededViolationsComponent implements OnInit {
  // SEED 2 [BLOCKER] (core/escape-hatch-types) any-typed input
  @Input() profile: any;

  orders: { reference: string }[] = [];
  trustedBio: unknown;
  returnUrl = '/';

  constructor(
    private readonly sanitizer: DomSanitizer,
    private readonly http: HttpClient,
    private readonly route: ActivatedRoute,
    private readonly router: Router
  ) {}

  ngOnInit(): void {
    // SEED 3 [BLOCKER] (angular/bypass-security-trust) sanitiser switched off on user-supplied html
    this.trustedBio = this.sanitizer.bypassSecurityTrustHtml(this.profile.bio);

    // SEED 4 [BLOCKER] (angular/open-redirect-navigation) navigation target taken straight from a query param
    this.returnUrl = this.route.snapshot.queryParams['next'];
    this.router.navigateByUrl(this.returnUrl);

    // SEED 5 [BLOCKER] (angular/unsubscribed-subscription) subscription with no teardown
    this.http.get<{ reference: string }[]>('/api/orders').subscribe((orders) => {
      this.orders = orders;
    });

    // SEED 6 [BLOCKER] (angular/uncancelled-request-race) a request per keystroke, merged not switched
    this.route.queryParams
      .pipe(
        mergeMap((params) => this.http.get<{ reference: string }[]>(`/api/search?q=${params['q']}`)),
        // SEED 7 [HIGH] (angular/interceptor-swallows-error) failure returned as an empty success
        catchError(() => of([]))
      )
      .subscribe((orders) => (this.orders = orders));

    // SEED 8 [BLOCKER] (angular/timer-not-cleared) interval never cleared in ngOnDestroy
    setInterval(() => this.http.get('/api/heartbeat').subscribe(), 5000);

    // SEED 9 [BLOCKER] (core/customer-data-in-logs) msisdn written to the console
    console.log('loaded profile for', this.profile.msisdn);

    // SEED 10 [HIGH] (angular/unvalidated-route-param) route param coerced with no validation
    const accountId = +this.route.snapshot.params['accountId'];
    this.http.get(`/api/accounts/${accountId}`).subscribe();
  }

  formatTotal(): string {
    return this.orders.reduce((sum, o) => sum + o.reference.length, 0).toFixed(2);
  }

  // SEED 12 [HIGH] (angular/input-object-mutation) child writing to an object the parent owns
  markSeen(): void {
    this.profile.seen = true;
  }

  // SEED 13 [SUGGESTION] (angular/prefer-async-pipe) manual subscribe where the async pipe would do
  refresh(): void {
    this.http.get<{ reference: string }[]>('/api/orders').subscribe((o) => (this.orders = o));
  }

  authHeader(): string {
    return `Bearer ${PARTNER_API_KEY}`;
  }
}