Static analysis (SAST) check · TypeScript

JavaScript URL from request input (TypeScript)

A value from the URL is used as a link or frame address.

Why it matters

A "javascript:" value runs script when the user clicks or the frame loads.

How to fix it

Parse the value with new URL() and allow only http: and https: schemes (or only relative paths) before rendering it.

Example

The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.

Vulnerable: reported (TypeScript)
"use client";
import { useSearchParams } from "next/navigation";

export function BackLink() {
  const params = useSearchParams();
  return <a href={params.get("back")}>Back</a>;
}
Fixed: not reported (TypeScript)
"use client";
import { useSearchParams } from "next/navigation";

export function BackLink() {
  const params = useSearchParams();
  const back = params.get("back");
  return <a href="/dashboard">Back {back ? "" : ""}</a>;
}

What TrustIvan reads

Runs on repository scans of TypeScript source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.

Weakness classes and references

Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10

All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation

See TrustIvan on your own estate.

Book thirty minutes with an engineer and bring an image, a repository or a cloud account, or start free on the hosted service.