lintsure 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ /** Well-known analytics and advertising hosts. Self-hosted or proxied trackers won't match. */
2
+ export declare const TRACKERS: [RegExp, string][];
3
+ export declare const trackerFor: (url: string) => string | null;
4
+ export interface BrowserFinding {
5
+ severity: "high" | "medium" | "low";
6
+ title: string;
7
+ detail: string;
8
+ relates: string;
9
+ }
10
+ export interface BrowserReport {
11
+ url: string;
12
+ checkedAt: string;
13
+ beforeConsent: {
14
+ trackers: string[];
15
+ cookies: string[];
16
+ };
17
+ rejectButton: string | null;
18
+ afterReject: {
19
+ trackers: string[];
20
+ cookies: string[];
21
+ } | null;
22
+ headers: Record<string, string | null>;
23
+ findings: BrowserFinding[];
24
+ screenshot: string;
25
+ }
26
+ export declare function browserCheck(url: string, opts: {
27
+ screenshot: string;
28
+ wait?: number;
29
+ }): Promise<BrowserReport>;
30
+ export declare function toBrowserMarkdown(r: BrowserReport): string;
@@ -0,0 +1,132 @@
1
+ // Browser check: opens your app in a real browser on your machine and watches what it does before and
2
+ // after someone clicks "Reject" on the cookie banner, and which security headers it sends.
3
+ // It only visits the URL you give it. It reads no code and sends nothing to Lintsure.
4
+ // Needs Playwright (an optional add-on): npm i -D playwright && npx playwright install chromium
5
+ import { createRequire } from "node:module";
6
+ import { join } from "node:path";
7
+ import { pathToFileURL } from "node:url";
8
+ /** Well-known analytics and advertising hosts. Self-hosted or proxied trackers won't match. */
9
+ export const TRACKERS = [
10
+ [/(^|\.)google-analytics\.com$|(^|\.)analytics\.google\.com$/, "Google Analytics"],
11
+ [/(^|\.)googletagmanager\.com$/, "Google Tag Manager"],
12
+ [/(^|\.)doubleclick\.net$|(^|\.)googleadservices\.com$|(^|\.)googlesyndication\.com$/, "Google Ads"],
13
+ [/(^|\.)connect\.facebook\.net$|^www\.facebook\.com$/, "Meta Pixel"],
14
+ [/(^|\.)i\.posthog\.com$|(^|\.)posthog\.com$/, "PostHog"],
15
+ [/(^|\.)segment\.(io|com)$/, "Segment"],
16
+ [/(^|\.)mixpanel\.com$|(^|\.)mxpnl\.com$/, "Mixpanel"],
17
+ [/(^|\.)amplitude\.com$/, "Amplitude"],
18
+ [/(^|\.)hotjar\.(com|io)$/, "Hotjar"],
19
+ [/(^|\.)clarity\.ms$/, "Microsoft Clarity"],
20
+ [/(^|\.)bat\.bing\.com$/, "Microsoft Ads"],
21
+ [/(^|\.)snap\.licdn\.com$|(^|\.)px\.ads\.linkedin\.com$/, "LinkedIn Insight"],
22
+ [/(^|\.)analytics\.tiktok\.com$/, "TikTok Pixel"],
23
+ [/(^|\.)ads-twitter\.com$|(^|\.)analytics\.twitter\.com$/, "X Pixel"],
24
+ [/(^|\.)fullstory\.com$/, "FullStory"],
25
+ [/(^|\.)heapanalytics\.com$|(^|\.)heap\.io$/, "Heap"],
26
+ ];
27
+ /** Cookie names analytics and ad tools set. */
28
+ const TRACKING_COOKIE = /^(_ga|_gid|_gat|_gcl|_fbp|_fbc|ph_|_hj|mp_|amp_|ajs_|_clck|_clsk|_uet|li_|_ttp|_tt_)/;
29
+ const REJECT = /^\s*(reject( all)?|decline( all)?|deny( all)?|refuse( all)?|only (necessary|essential)( cookies)?|necessary (cookies )?only|use necessary cookies only|continue without accepting)\s*$/i;
30
+ export const trackerFor = (url) => {
31
+ try {
32
+ const h = new URL(url).hostname;
33
+ return TRACKERS.find(([re]) => re.test(h))?.[1] ?? null;
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ };
39
+ const HEADERS = ["content-security-policy", "strict-transport-security", "x-content-type-options", "referrer-policy", "x-frame-options"];
40
+ export async function browserCheck(url, opts) {
41
+ let pw;
42
+ // npx runs Lintsure from its own cache, so look for Playwright in the user's project first.
43
+ const fromProject = async () => import(pathToFileURL(createRequire(join(process.cwd(), "package.json")).resolve("playwright")).href);
44
+ try {
45
+ const m = await fromProject().catch(() => import("playwright"));
46
+ pw = m.chromium ? m : m.default;
47
+ if (!pw?.chromium)
48
+ throw new Error();
49
+ }
50
+ catch {
51
+ throw new Error("The browser check needs Playwright, an optional add-on. Install it in your project with:\n npm i -D playwright\n npx playwright install chromium");
52
+ }
53
+ const browser = await pw.chromium.launch();
54
+ try {
55
+ const context = await browser.newContext(); // fresh visitor: no cookies, no stored consent
56
+ const page = await context.newPage();
57
+ const seen = new Set();
58
+ page.on("request", (r) => { const t = trackerFor(r.url()); if (t)
59
+ seen.add(t); });
60
+ const res = await page.goto(url, { waitUntil: "load", timeout: 30000 });
61
+ await page.waitForTimeout(opts.wait ?? 4000);
62
+ const headers = Object.fromEntries(HEADERS.map((h) => [h, res?.headers()[h] ?? null]));
63
+ const cookieNames = async () => (await context.cookies()).map((c) => c.name).filter((n) => TRACKING_COOKIE.test(n));
64
+ const beforeConsent = { trackers: [...seen], cookies: await cookieNames() };
65
+ await page.screenshot({ path: opts.screenshot });
66
+ // Look for a reject button, the way a visitor would.
67
+ const buttons = page.getByRole("button").or(page.getByRole("link"));
68
+ let rejectButton = null;
69
+ for (const b of await buttons.all()) {
70
+ const name = ((await b.textContent()) ?? "").trim();
71
+ if (REJECT.test(name) && await b.isVisible().catch(() => false)) {
72
+ rejectButton = name;
73
+ await b.click();
74
+ break;
75
+ }
76
+ }
77
+ let afterReject = null;
78
+ if (rejectButton) {
79
+ seen.clear();
80
+ await page.waitForTimeout(1500);
81
+ await page.reload({ waitUntil: "load" }); // the choice should hold on the next page view
82
+ await page.waitForTimeout(opts.wait ?? 4000);
83
+ afterReject = { trackers: [...seen], cookies: await cookieNames() };
84
+ }
85
+ const findings = [];
86
+ if (beforeConsent.trackers.length)
87
+ findings.push({ severity: "high", title: "Trackers load before anyone agrees",
88
+ detail: `${beforeConsent.trackers.join(", ")} loaded as soon as the page opened, before a choice was made on the cookie banner.`,
89
+ relates: "GDPR Art. 6 and 7 (lawful basis and consent), ePrivacy Directive Art. 5(3)" });
90
+ if (beforeConsent.cookies.length)
91
+ findings.push({ severity: "high", title: "Tracking cookies set before anyone agrees",
92
+ detail: `Cookies ${beforeConsent.cookies.join(", ")} were stored before a choice was made.`, relates: "ePrivacy Directive Art. 5(3), GDPR Art. 7" });
93
+ if (afterReject?.trackers.length)
94
+ findings.push({ severity: "high", title: "Trackers still load after \"Reject\"",
95
+ detail: `After clicking "${rejectButton}" and reloading, ${afterReject.trackers.join(", ")} still loaded.`, relates: "GDPR Art. 7(3) (withdrawing consent), ePrivacy Directive Art. 5(3)" });
96
+ if (!rejectButton && (beforeConsent.trackers.length || beforeConsent.cookies.length))
97
+ findings.push({ severity: "medium", title: "No clear reject button found",
98
+ detail: "Trackers or tracking cookies are present, but no button labelled Reject, Decline or Only necessary was found on the first screen. Refusing should be as easy as accepting.",
99
+ relates: "GDPR Art. 7(3), EDPB guidelines on consent" });
100
+ if (!headers["content-security-policy"])
101
+ findings.push({ severity: "medium", title: "No Content-Security-Policy header", detail: "A CSP limits which scripts can run and reduces the damage of cross-site scripting.", relates: "OWASP A02:2025 Security Misconfiguration" });
102
+ if (url.startsWith("https:") && !headers["strict-transport-security"])
103
+ findings.push({ severity: "medium", title: "No Strict-Transport-Security header", detail: "HSTS tells browsers to always use HTTPS for your site.", relates: "OWASP A02:2025, A04:2025" });
104
+ if (!headers["x-content-type-options"])
105
+ findings.push({ severity: "low", title: "No X-Content-Type-Options header", detail: "Set it to nosniff so browsers don't guess file types.", relates: "OWASP A02:2025" });
106
+ if (!headers["x-frame-options"] && !/frame-ancestors/.test(headers["content-security-policy"] ?? ""))
107
+ findings.push({ severity: "low", title: "Page can be shown inside other sites", detail: "Without X-Frame-Options or a CSP frame-ancestors rule, other sites can embed your pages, which enables clickjacking.", relates: "OWASP A02:2025" });
108
+ if (!headers["referrer-policy"])
109
+ findings.push({ severity: "low", title: "No Referrer-Policy header", detail: "Without it, full page addresses (which can contain personal data) may be sent to other sites.", relates: "OWASP A02:2025, GDPR Art. 32" });
110
+ return { url, checkedAt: new Date().toISOString(), beforeConsent, rejectButton, afterReject, headers, findings, screenshot: opts.screenshot };
111
+ }
112
+ finally {
113
+ await browser.close();
114
+ }
115
+ }
116
+ export function toBrowserMarkdown(r) {
117
+ const list = (a) => (a.length ? a.join(", ") : "none");
118
+ return [
119
+ "# Lintsure browser check", "",
120
+ `${r.url} · checked ${r.checkedAt.replace("T", " ").slice(0, 16)} UTC`, "",
121
+ "> This check opened your page as a new visitor in a browser on your machine. It recognises well-known trackers by their web address, so self-hosted or proxied tools may not show up, and consent may be handled in ways it can't see. Check each finding. It is a readiness check, not legal advice.", "",
122
+ "## What happened", "",
123
+ `- **Before any choice:** trackers ${list(r.beforeConsent.trackers)}; tracking cookies ${list(r.beforeConsent.cookies)}`,
124
+ `- **Reject button:** ${r.rejectButton ? `found ("${r.rejectButton}") and clicked` : "not found on the first screen"}`,
125
+ ...(r.afterReject ? [`- **After rejecting and reloading:** trackers ${list(r.afterReject.trackers)}; tracking cookies ${list(r.afterReject.cookies)}`] : []),
126
+ `- **Screenshot:** ${r.screenshot}`, "",
127
+ `## Findings (${r.findings.length})`, "",
128
+ ...(r.findings.length ? r.findings.flatMap((f) => [`### ${f.title} (${f.severity})`, "", f.detail, "", `Relates to: ${f.relates}`, ""]) : ["Nothing found by the current checks.", ""]),
129
+ "## Security headers", "",
130
+ ...HEADERS.map((h) => `- \`${h}\`: ${r.headers[h] ? "set" : "missing"}`), "",
131
+ ].join("\n");
132
+ }
package/dist/src/index.js CHANGED
@@ -4,33 +4,33 @@
4
4
  import { mkdir, writeFile } from "node:fs/promises";
5
5
  import { basename, dirname, join, resolve } from "node:path";
6
6
  import { ALL_FRAMEWORKS, BASELINE_FILE, DISCLAIMER, RULES_VERSION, isOpen, nextSteps, readConfig, scan, toAssessmentHtml, toBaseline, toMarkdown, toSarif } from "@lintsure/core";
7
- const HELP = `lintsure scan [path] [options]
8
- lintsure baseline [path]
9
-
10
- scan options:
11
- --framework <ids> Comma list: ${ALL_FRAMEWORKS.join(", ")}
12
- (default: lintsure.config.yaml if present, else all)
13
- --json Also write lintsure-report.json
14
- --sarif Also write lintsure.sarif (for GitHub code scanning and editors)
15
- --report Also write lintsure-assessment.html, a multi-page report
16
- to review, print or save as PDF
17
- --project <name> Project name on the assessment cover (default: folder name)
18
- --fail-on <status> Exit 1 if any open finding is "gap" or "partial" (for CI)
19
- --new-only With --fail-on: count only findings that are new since
20
- .lintsure/baseline.json
21
- --github Print GitHub Actions annotations, so findings show on the lines
22
- --save-record Also save this run's readiness check record to
23
- .lintsure/records/<id>.json, building a dated history (no code inside)
24
-
25
- baseline:
26
- Saves the current open findings to .lintsure/baseline.json in the scanned folder.
27
- Later scans show what is new, fixed or unchanged. The file holds rule ids, file
28
- paths and one-way fingerprints, never code. You decide whether to commit it.
29
-
30
- Accept a finding after review by adding it to .lintsure/accepted.yaml, with the
31
- fingerprint from lintsure-report.json, your reason, your name and the date.
32
-
33
- ${DISCLAIMER}
7
+ const HELP = `lintsure scan [path] [options]
8
+ lintsure baseline [path]
9
+
10
+ scan options:
11
+ --framework <ids> Comma list: ${ALL_FRAMEWORKS.join(", ")}
12
+ (default: lintsure.config.yaml if present, else all)
13
+ --json Also write lintsure-report.json
14
+ --sarif Also write lintsure.sarif (for GitHub code scanning and editors)
15
+ --report Also write lintsure-assessment.html, a multi-page report
16
+ to review, print or save as PDF
17
+ --project <name> Project name on the assessment cover (default: folder name)
18
+ --fail-on <status> Exit 1 if any open finding is "gap" or "partial" (for CI)
19
+ --new-only With --fail-on: count only findings that are new since
20
+ .lintsure/baseline.json
21
+ --github Print GitHub Actions annotations, so findings show on the lines
22
+ --save-record Also save this run's readiness check record to
23
+ .lintsure/records/<id>.json, building a dated history (no code inside)
24
+
25
+ baseline:
26
+ Saves the current open findings to .lintsure/baseline.json in the scanned folder.
27
+ Later scans show what is new, fixed or unchanged. The file holds rule ids, file
28
+ paths and one-way fingerprints, never code. You decide whether to commit it.
29
+
30
+ Accept a finding after review by adding it to .lintsure/accepted.yaml, with the
31
+ fingerprint from lintsure-report.json, your reason, your name and the date.
32
+
33
+ ${DISCLAIMER}
34
34
  Lintsure never sends your code anywhere.`;
35
35
  const VALUE_FLAGS = ["--framework", "--fail-on", "--project"];
36
36
  async function main(argv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lintsure",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Readiness checks for the code your AI writes: EU AI Act, GDPR, SOC 2, ISO 27001. Runs locally. Not an audit or legal advice.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -13,7 +13,7 @@
13
13
  "LICENSE"
14
14
  ],
15
15
  "dependencies": {
16
- "@lintsure/core": "0.2.0"
16
+ "@lintsure/core": "0.3.1"
17
17
  },
18
18
  "author": "Lintsure <hello@lintsure.com>",
19
19
  "homepage": "https://lintsure.com/docs",