prodlint 0.5.0 → 0.6.0

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.
package/dist/cli.js CHANGED
@@ -314,7 +314,8 @@ var SCAN_EXTENSIONS = [
314
314
  "jsx",
315
315
  "mjs",
316
316
  "cjs",
317
- "json"
317
+ "json",
318
+ "sql"
318
319
  ];
319
320
  var AST_EXTENSIONS = /* @__PURE__ */ new Set(["ts", "tsx", "js", "jsx", "mjs", "cjs"]);
320
321
  var MAX_FILE_SIZE = 1024 * 1024;
@@ -2538,6 +2539,1058 @@ var missingTransactionRule = {
2538
2539
  }
2539
2540
  };
2540
2541
 
2542
+ // src/rules/redirect-in-try-catch.ts
2543
+ var redirectInTryCatchRule = {
2544
+ id: "redirect-in-try-catch",
2545
+ name: "Redirect Inside Try/Catch",
2546
+ description: "Detects Next.js redirect() inside try/catch blocks \u2014 redirect throws internally and the catch swallows it",
2547
+ category: "reliability",
2548
+ severity: "critical",
2549
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
2550
+ check(file, _project) {
2551
+ if (isTestFile(file.relativePath)) return [];
2552
+ if (!/redirect\s*\(/.test(file.content)) return [];
2553
+ const findings = [];
2554
+ let tryDepth = 0;
2555
+ for (let i = 0; i < file.lines.length; i++) {
2556
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
2557
+ const line = file.lines[i];
2558
+ const trimmed = line.trim();
2559
+ if (/\btry\s*\{/.test(trimmed) || trimmed === "try {") {
2560
+ tryDepth++;
2561
+ }
2562
+ if (/\}\s*catch\s*[\s(]/.test(trimmed)) {
2563
+ }
2564
+ if (tryDepth > 0) {
2565
+ const match = /\bredirect\s*\(/.exec(line);
2566
+ if (match && !/\/\//.test(line.slice(0, match.index))) {
2567
+ findings.push({
2568
+ ruleId: "redirect-in-try-catch",
2569
+ file: file.relativePath,
2570
+ line: i + 1,
2571
+ column: match.index + 1,
2572
+ message: "redirect() inside try/catch \u2014 Next.js redirect throws internally, the catch block will intercept it",
2573
+ severity: "critical",
2574
+ category: "reliability",
2575
+ fix: 'Move redirect() outside the try/catch block, or re-throw redirect errors in the catch: if (e instanceof Error && e.message === "NEXT_REDIRECT") throw e'
2576
+ });
2577
+ }
2578
+ }
2579
+ for (const ch of trimmed) {
2580
+ if (ch === "{" && tryDepth > 0) {
2581
+ }
2582
+ }
2583
+ if (tryDepth > 0 && /^\}\s*$/.test(trimmed)) {
2584
+ let nextLine = "";
2585
+ for (let j = i + 1; j < file.lines.length; j++) {
2586
+ nextLine = file.lines[j].trim();
2587
+ if (nextLine) break;
2588
+ }
2589
+ if (!/^catch\b/.test(nextLine) && !/^finally\b/.test(nextLine)) {
2590
+ tryDepth--;
2591
+ }
2592
+ }
2593
+ }
2594
+ return findings;
2595
+ }
2596
+ };
2597
+
2598
+ // src/rules/missing-revalidation.ts
2599
+ var USE_SERVER2 = /['"]use server['"]/;
2600
+ var DB_MUTATIONS = [
2601
+ /\.insert\s*\(/,
2602
+ /\.update\s*\(/,
2603
+ /\.delete\s*\(/,
2604
+ /\.upsert\s*\(/,
2605
+ /\.create\s*\(/,
2606
+ /\.createMany\s*\(/,
2607
+ /\.updateMany\s*\(/,
2608
+ /\.deleteMany\s*\(/,
2609
+ /\.remove\s*\(/,
2610
+ /\.save\s*\(/,
2611
+ /\.destroy\s*\(/
2612
+ ];
2613
+ var REVALIDATION = [
2614
+ /revalidatePath\s*\(/,
2615
+ /revalidateTag\s*\(/,
2616
+ /redirect\s*\(/
2617
+ ];
2618
+ var missingRevalidationRule = {
2619
+ id: "missing-revalidation",
2620
+ name: "Missing Revalidation After Mutation",
2621
+ description: "Detects server actions that mutate data without calling revalidatePath or revalidateTag \u2014 UI shows stale data",
2622
+ category: "reliability",
2623
+ severity: "warning",
2624
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
2625
+ check(file, _project) {
2626
+ if (isTestFile(file.relativePath)) return [];
2627
+ if (!USE_SERVER2.test(file.content)) return [];
2628
+ const hasMutation = DB_MUTATIONS.some((p) => p.test(file.content));
2629
+ if (!hasMutation) return [];
2630
+ const hasRevalidation = REVALIDATION.some((p) => p.test(file.content));
2631
+ if (hasRevalidation) return [];
2632
+ let reportLine = 1;
2633
+ for (let i = 0; i < file.lines.length; i++) {
2634
+ if (DB_MUTATIONS.some((p) => p.test(file.lines[i]))) {
2635
+ reportLine = i + 1;
2636
+ break;
2637
+ }
2638
+ }
2639
+ return [{
2640
+ ruleId: "missing-revalidation",
2641
+ file: file.relativePath,
2642
+ line: reportLine,
2643
+ column: 1,
2644
+ message: "Server action mutates data without revalidatePath() or revalidateTag() \u2014 UI will show stale data",
2645
+ severity: "warning",
2646
+ category: "reliability",
2647
+ fix: 'Add revalidatePath("/affected-route") after the mutation'
2648
+ }];
2649
+ }
2650
+ };
2651
+
2652
+ // src/rules/use-client-overuse.ts
2653
+ var CLIENT_APIS = [
2654
+ /\buseState\b/,
2655
+ /\buseEffect\b/,
2656
+ /\buseRef\b/,
2657
+ /\buseReducer\b/,
2658
+ /\buseCallback\b/,
2659
+ /\buseMemo\b/,
2660
+ /\buseContext\b/,
2661
+ /\buseLayoutEffect\b/,
2662
+ /\buseInsertionEffect\b/,
2663
+ /\buseTransition\b/,
2664
+ /\buseDeferredValue\b/,
2665
+ /\buseSyncExternalStore\b/,
2666
+ /\buseFormStatus\b/,
2667
+ /\buseFormState\b/,
2668
+ /\buseOptimistic\b/,
2669
+ /\bonClick\b\s*[=:]/,
2670
+ /\bonChange\b\s*[=:]/,
2671
+ /\bonSubmit\b\s*[=:]/,
2672
+ /\bonBlur\b\s*[=:]/,
2673
+ /\bonFocus\b\s*[=:]/,
2674
+ /\bonKeyDown\b\s*[=:]/,
2675
+ /\bonKeyUp\b\s*[=:]/,
2676
+ /\bonMouseDown\b\s*[=:]/,
2677
+ /\bonMouseUp\b\s*[=:]/,
2678
+ /\bonScroll\b\s*[=:]/,
2679
+ /\bonInput\b\s*[=:]/,
2680
+ /\bonDrag\b/,
2681
+ /\bonDrop\b/,
2682
+ /\bonTouchStart\b/,
2683
+ /\bcreateContext\b/,
2684
+ /\bwindow\./,
2685
+ /\bdocument\./,
2686
+ /\blocalStorage\b/,
2687
+ /\bsessionStorage\b/,
2688
+ /\bnavigator\b/,
2689
+ /\bIntersectionObserver\b/,
2690
+ /\bResizeObserver\b/,
2691
+ /\bMutationObserver\b/
2692
+ ];
2693
+ var useClientOveruseRule = {
2694
+ id: "use-client-overuse",
2695
+ name: '"use client" Overuse',
2696
+ description: `Detects files with "use client" that don't use any client-side APIs \u2014 unnecessary client rendering`,
2697
+ category: "ai-quality",
2698
+ severity: "info",
2699
+ fileExtensions: ["tsx", "jsx"],
2700
+ check(file, _project) {
2701
+ if (isTestFile(file.relativePath)) return [];
2702
+ if (isConfigFile(file.relativePath)) return [];
2703
+ if (!isClientComponent(file.content)) return [];
2704
+ const usesClientApi = CLIENT_APIS.some((p) => p.test(file.content));
2705
+ if (usesClientApi) return [];
2706
+ return [{
2707
+ ruleId: "use-client-overuse",
2708
+ file: file.relativePath,
2709
+ line: 1,
2710
+ column: 1,
2711
+ message: '"use client" directive but no client-side APIs (hooks, event handlers, browser APIs) \u2014 this component could be a server component',
2712
+ severity: "info",
2713
+ category: "ai-quality",
2714
+ fix: 'Remove "use client" to let Next.js render this as a server component for better performance'
2715
+ }];
2716
+ }
2717
+ };
2718
+
2719
+ // src/rules/env-fallback-secret.ts
2720
+ var SENSITIVE_ENV = /process\.env\.(JWT_SECRET|SECRET_KEY|AUTH_SECRET|SESSION_SECRET|ENCRYPTION_KEY|API_SECRET|PRIVATE_KEY|SIGNING_KEY|NEXTAUTH_SECRET|TOKEN_SECRET|APP_SECRET|COOKIE_SECRET|HASH_SECRET)\s*(?:\|\||&&|\?\?)\s*['"`]/i;
2721
+ var ENV_FALLBACK = /process\.env\.\w*(SECRET|KEY|PASSWORD|TOKEN)\w*\s*(?:\|\||\?\?)\s*['"`]/i;
2722
+ var envFallbackSecretRule = {
2723
+ id: "env-fallback-secret",
2724
+ name: "Secret with Fallback Value",
2725
+ description: "Detects security-sensitive env vars with hardcoded fallback values \u2014 if the env var is missing, the fallback becomes the production secret",
2726
+ category: "security",
2727
+ severity: "critical",
2728
+ fileExtensions: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
2729
+ check(file, _project) {
2730
+ if (isTestFile(file.relativePath)) return [];
2731
+ const findings = [];
2732
+ for (let i = 0; i < file.lines.length; i++) {
2733
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
2734
+ const line = file.lines[i];
2735
+ const directMatch = SENSITIVE_ENV.exec(line);
2736
+ if (directMatch) {
2737
+ findings.push({
2738
+ ruleId: "env-fallback-secret",
2739
+ file: file.relativePath,
2740
+ line: i + 1,
2741
+ column: directMatch.index + 1,
2742
+ message: `Secret env var has a hardcoded fallback \u2014 if ${directMatch[1] || "the var"} is unset, this literal becomes the production secret`,
2743
+ severity: "critical",
2744
+ category: "security",
2745
+ fix: 'Throw an error if the env var is missing: const secret = process.env.SECRET ?? (() => { throw new Error("SECRET is required") })()'
2746
+ });
2747
+ continue;
2748
+ }
2749
+ const genericMatch = ENV_FALLBACK.exec(line);
2750
+ if (genericMatch && !isConfigFile(file.relativePath)) {
2751
+ findings.push({
2752
+ ruleId: "env-fallback-secret",
2753
+ file: file.relativePath,
2754
+ line: i + 1,
2755
+ column: genericMatch.index + 1,
2756
+ message: "Security-sensitive env var has a hardcoded fallback \u2014 defaults to a literal string when missing",
2757
+ severity: "warning",
2758
+ category: "security",
2759
+ fix: "Fail fast when required env vars are missing instead of falling back to a default value"
2760
+ });
2761
+ }
2762
+ }
2763
+ return findings;
2764
+ }
2765
+ };
2766
+
2767
+ // src/rules/verbose-error-response.ts
2768
+ var ERROR_LEAK_PATTERNS = [
2769
+ { pattern: /error\.stack/, msg: "error.stack exposed \u2014 leaks internal file paths and code structure" },
2770
+ { pattern: /error\.message/, msg: "error.message may leak internal details to clients" }
2771
+ ];
2772
+ var verboseErrorResponseRule = {
2773
+ id: "verbose-error-response",
2774
+ name: "Verbose Error Response",
2775
+ description: "Detects error details (stack traces, error messages) sent directly in API responses",
2776
+ category: "security",
2777
+ severity: "warning",
2778
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
2779
+ check(file, _project) {
2780
+ if (isTestFile(file.relativePath)) return [];
2781
+ if (!isApiRoute(file.relativePath) && !/['"]use server['"]/.test(file.content)) return [];
2782
+ const findings = [];
2783
+ for (let i = 0; i < file.lines.length; i++) {
2784
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
2785
+ const line = file.lines[i];
2786
+ for (const { pattern, msg } of ERROR_LEAK_PATTERNS) {
2787
+ const match = pattern.exec(line);
2788
+ if (match) {
2789
+ const severity = pattern.source.includes("stack") ? "warning" : "info";
2790
+ findings.push({
2791
+ ruleId: "verbose-error-response",
2792
+ file: file.relativePath,
2793
+ line: i + 1,
2794
+ column: match.index + 1,
2795
+ message: msg,
2796
+ severity,
2797
+ category: "security",
2798
+ fix: 'Return a generic error message: { error: "Internal server error" }. Log the real error server-side.'
2799
+ });
2800
+ break;
2801
+ }
2802
+ }
2803
+ }
2804
+ return findings;
2805
+ }
2806
+ };
2807
+
2808
+ // src/rules/missing-webhook-verification.ts
2809
+ var WEBHOOK_PATH = /webhook/i;
2810
+ var VERIFICATION_PATTERNS = [
2811
+ /constructEvent\s*\(/,
2812
+ // Stripe
2813
+ /webhooks\.verify\s*\(/,
2814
+ // Clerk, GitHub
2815
+ /verify\s*\(/,
2816
+ // Generic
2817
+ /verifySignature\s*\(/,
2818
+ // Generic
2819
+ /validateWebhook\s*\(/,
2820
+ // Generic
2821
+ /svix.*verify/i,
2822
+ // Svix (used by Clerk, Resend)
2823
+ /crypto\.timingSafeEqual\s*\(/,
2824
+ // Manual HMAC comparison
2825
+ /hmac/i,
2826
+ // HMAC verification
2827
+ /x-hub-signature/i,
2828
+ // GitHub webhooks
2829
+ /stripe-signature/i,
2830
+ // Stripe signature header
2831
+ /svix-signature/i,
2832
+ // Svix signature header
2833
+ /webhook-secret/i
2834
+ ];
2835
+ var missingWebhookVerificationRule = {
2836
+ id: "missing-webhook-verification",
2837
+ name: "Missing Webhook Verification",
2838
+ description: "Detects webhook endpoints without signature verification \u2014 anyone can send fake events",
2839
+ category: "security",
2840
+ severity: "critical",
2841
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
2842
+ check(file, _project) {
2843
+ if (isTestFile(file.relativePath)) return [];
2844
+ if (!isApiRoute(file.relativePath)) return [];
2845
+ if (!WEBHOOK_PATH.test(file.relativePath)) return [];
2846
+ const hasVerification = VERIFICATION_PATTERNS.some((p) => p.test(file.content));
2847
+ if (hasVerification) return [];
2848
+ let handlerLine = 1;
2849
+ for (let i = 0; i < file.lines.length; i++) {
2850
+ if (/export\s+(async\s+)?function\s+POST\b/.test(file.lines[i])) {
2851
+ handlerLine = i + 1;
2852
+ break;
2853
+ }
2854
+ }
2855
+ return [{
2856
+ ruleId: "missing-webhook-verification",
2857
+ file: file.relativePath,
2858
+ line: handlerLine,
2859
+ column: 1,
2860
+ message: "Webhook endpoint has no signature verification \u2014 anyone can forge events to this route",
2861
+ severity: "critical",
2862
+ category: "security",
2863
+ fix: "Verify the webhook signature before processing. For Stripe: stripe.webhooks.constructEvent(body, sig, secret)"
2864
+ }];
2865
+ }
2866
+ };
2867
+
2868
+ // src/rules/server-action-auth.ts
2869
+ var USE_SERVER3 = /['"]use server['"]/;
2870
+ var AUTH_PATTERNS2 = [
2871
+ /getServerSession\s*\(/,
2872
+ /getSession\s*\(/,
2873
+ /\.auth\.getUser\s*\(/,
2874
+ /auth\(\)/,
2875
+ /authenticate\s*\(/,
2876
+ /isAuthenticated/,
2877
+ /requireAuth/,
2878
+ /withAuth/,
2879
+ /getToken\s*\(/,
2880
+ /verifyToken\s*\(/,
2881
+ /jwt\.verify\s*\(/,
2882
+ /createServerComponentClient/,
2883
+ /currentUser\s*\(/,
2884
+ /getAuth\s*\(/,
2885
+ /cookies\(\).*auth/s,
2886
+ /session/i
2887
+ ];
2888
+ var PUBLIC_ACTION_NAMES = [
2889
+ /contact/i,
2890
+ /subscribe/i,
2891
+ /newsletter/i,
2892
+ /feedback/i,
2893
+ /signup/i,
2894
+ /login/i,
2895
+ /register/i
2896
+ ];
2897
+ var serverActionAuthRule = {
2898
+ id: "server-action-auth",
2899
+ name: "Server Action Without Auth",
2900
+ description: "Detects server actions that perform mutations without any authentication check",
2901
+ category: "security",
2902
+ severity: "warning",
2903
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
2904
+ check(file, project) {
2905
+ if (isTestFile(file.relativePath)) return [];
2906
+ if (!USE_SERVER3.test(file.content)) return [];
2907
+ if (project.hasAuthMiddleware) return [];
2908
+ for (const p of PUBLIC_ACTION_NAMES) {
2909
+ if (p.test(file.relativePath)) return [];
2910
+ }
2911
+ const hasAuth = AUTH_PATTERNS2.some((p) => p.test(file.content));
2912
+ if (hasAuth) return [];
2913
+ const hasMutation = /\.(insert|update|delete|create|upsert|remove|destroy|save|push|set)\s*\(/i.test(file.content) || /\b(INSERT|UPDATE|DELETE)\b/.test(file.content);
2914
+ if (!hasMutation) return [];
2915
+ let reportLine = 1;
2916
+ for (let i = 0; i < file.lines.length; i++) {
2917
+ if (USE_SERVER3.test(file.lines[i])) {
2918
+ reportLine = i + 1;
2919
+ break;
2920
+ }
2921
+ }
2922
+ return [{
2923
+ ruleId: "server-action-auth",
2924
+ file: file.relativePath,
2925
+ line: reportLine,
2926
+ column: 1,
2927
+ message: "Server action performs mutations without any authentication check \u2014 anyone can call this action",
2928
+ severity: "warning",
2929
+ category: "security",
2930
+ fix: 'Add auth check: const session = await auth(); if (!session) throw new Error("Unauthorized")'
2931
+ }];
2932
+ }
2933
+ };
2934
+
2935
+ // src/rules/eval-injection.ts
2936
+ var EVAL_PATTERNS = [
2937
+ { pattern: /\beval\s*\(/, msg: "eval() executes arbitrary code \u2014 never use with dynamic input" },
2938
+ { pattern: /\bnew\s+Function\s*\(/, msg: "new Function() is equivalent to eval \u2014 avoid dynamic code execution" },
2939
+ { pattern: /\bsetTimeout\s*\(\s*['"`]/, msg: "setTimeout with a string argument is eval \u2014 pass a function instead" },
2940
+ { pattern: /\bsetInterval\s*\(\s*['"`]/, msg: "setInterval with a string argument is eval \u2014 pass a function instead" }
2941
+ ];
2942
+ var evalInjectionRule = {
2943
+ id: "eval-injection",
2944
+ name: "Eval / Code Injection",
2945
+ description: "Detects eval(), new Function(), and string arguments to setTimeout/setInterval",
2946
+ category: "security",
2947
+ severity: "critical",
2948
+ fileExtensions: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
2949
+ check(file, _project) {
2950
+ if (isTestFile(file.relativePath)) return [];
2951
+ const findings = [];
2952
+ for (let i = 0; i < file.lines.length; i++) {
2953
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
2954
+ const line = file.lines[i];
2955
+ for (const { pattern, msg } of EVAL_PATTERNS) {
2956
+ const match = pattern.exec(line);
2957
+ if (match) {
2958
+ findings.push({
2959
+ ruleId: "eval-injection",
2960
+ file: file.relativePath,
2961
+ line: i + 1,
2962
+ column: match.index + 1,
2963
+ message: msg,
2964
+ severity: "critical",
2965
+ category: "security"
2966
+ });
2967
+ break;
2968
+ }
2969
+ }
2970
+ }
2971
+ return findings;
2972
+ }
2973
+ };
2974
+
2975
+ // src/rules/missing-useeffect-cleanup.ts
2976
+ var NEEDS_CLEANUP = [
2977
+ /\bsetInterval\s*\(/,
2978
+ /\baddEventListener\s*\(/,
2979
+ /\.subscribe\s*\(/,
2980
+ /\.on\s*\(\s*['"`]/,
2981
+ /new\s+WebSocket\s*\(/,
2982
+ /new\s+EventSource\s*\(/,
2983
+ /new\s+IntersectionObserver\s*\(/,
2984
+ /new\s+ResizeObserver\s*\(/,
2985
+ /new\s+MutationObserver\s*\(/
2986
+ ];
2987
+ var missingUseEffectCleanupRule = {
2988
+ id: "missing-useeffect-cleanup",
2989
+ name: "Missing useEffect Cleanup",
2990
+ description: "Detects useEffect hooks with subscriptions or timers but no cleanup return function \u2014 causes memory leaks",
2991
+ category: "reliability",
2992
+ severity: "warning",
2993
+ fileExtensions: ["tsx", "jsx", "ts", "js"],
2994
+ check(file, _project) {
2995
+ if (isTestFile(file.relativePath)) return [];
2996
+ if (!isClientComponent(file.content)) return [];
2997
+ if (!/useEffect/.test(file.content)) return [];
2998
+ const findings = [];
2999
+ const lines = file.lines;
3000
+ for (let i = 0; i < lines.length; i++) {
3001
+ const line = lines[i];
3002
+ if (!/\buseEffect\s*\(/.test(line)) continue;
3003
+ let braceDepth = 0;
3004
+ let effectStart = -1;
3005
+ let effectEnd = -1;
3006
+ let started = false;
3007
+ for (let j = i; j < lines.length && j < i + 100; j++) {
3008
+ for (const ch of lines[j]) {
3009
+ if (ch === "(") {
3010
+ if (!started) {
3011
+ started = true;
3012
+ }
3013
+ braceDepth++;
3014
+ } else if (ch === ")") {
3015
+ braceDepth--;
3016
+ if (started && braceDepth === 0) {
3017
+ effectEnd = j;
3018
+ break;
3019
+ }
3020
+ } else if (ch === "{" && effectStart === -1 && started) {
3021
+ effectStart = j;
3022
+ }
3023
+ }
3024
+ if (effectEnd !== -1) break;
3025
+ }
3026
+ if (effectStart === -1 || effectEnd === -1) continue;
3027
+ const effectBody = lines.slice(effectStart, effectEnd + 1).join("\n");
3028
+ const needsCleanup = NEEDS_CLEANUP.some((p) => p.test(effectBody));
3029
+ if (!needsCleanup) continue;
3030
+ const hasReturn = /return\s*(?:\(\s*\)\s*=>|function|\(\))/.test(effectBody) || /return\s*\(\s*\)\s*\{/.test(effectBody) || /return\s+\w+\s*;?\s*$/.test(effectBody);
3031
+ if (!hasReturn) {
3032
+ const hasCleanupReturn = /return\s+(?:\(\)|(?:\(\s*\)\s*=>)|(?:function))/.test(effectBody);
3033
+ if (!hasCleanupReturn) {
3034
+ findings.push({
3035
+ ruleId: "missing-useeffect-cleanup",
3036
+ file: file.relativePath,
3037
+ line: i + 1,
3038
+ column: 1,
3039
+ message: "useEffect with subscription/timer but no cleanup return \u2014 will leak memory on unmount",
3040
+ severity: "warning",
3041
+ category: "reliability",
3042
+ fix: "Return a cleanup function: useEffect(() => { const id = setInterval(...); return () => clearInterval(id); }, [])"
3043
+ });
3044
+ }
3045
+ }
3046
+ }
3047
+ return findings;
3048
+ }
3049
+ };
3050
+
3051
+ // src/rules/next-public-sensitive.ts
3052
+ var SENSITIVE_PATTERN = /NEXT_PUBLIC_\w*(SECRET|PRIVATE|PASSWORD|DATABASE_URL|SERVICE_ROLE|SERVICE_KEY|ADMIN_KEY|sk_live|sk_test|SIGNING|ENCRYPTION)/i;
3053
+ var nextPublicSensitiveRule = {
3054
+ id: "next-public-sensitive",
3055
+ name: "Sensitive Env Var with NEXT_PUBLIC_ Prefix",
3056
+ description: "Detects NEXT_PUBLIC_ prefix on environment variables that should be server-only \u2014 exposes secrets to the browser",
3057
+ category: "security",
3058
+ severity: "critical",
3059
+ fileExtensions: ["ts", "tsx", "js", "jsx", "mjs", "env", "env.local", "env.production"],
3060
+ check(file, _project) {
3061
+ if (isTestFile(file.relativePath)) return [];
3062
+ const findings = [];
3063
+ for (let i = 0; i < file.lines.length; i++) {
3064
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3065
+ const line = file.lines[i];
3066
+ const match = SENSITIVE_PATTERN.exec(line);
3067
+ if (match) {
3068
+ findings.push({
3069
+ ruleId: "next-public-sensitive",
3070
+ file: file.relativePath,
3071
+ line: i + 1,
3072
+ column: match.index + 1,
3073
+ message: `NEXT_PUBLIC_ prefix on a sensitive env var \u2014 this value will be embedded in the client-side JavaScript bundle`,
3074
+ severity: "critical",
3075
+ category: "security",
3076
+ fix: "Remove the NEXT_PUBLIC_ prefix. Access this value only in server components, API routes, or server actions."
3077
+ });
3078
+ }
3079
+ }
3080
+ return findings;
3081
+ }
3082
+ };
3083
+
3084
+ // src/rules/ssrf-risk.ts
3085
+ var USER_INPUT_IN_FETCH = [
3086
+ /fetch\s*\(\s*(?:req|request)\.(?:body|query|params|nextUrl)/,
3087
+ /fetch\s*\(\s*(?:url|href|endpoint|target|link|src)\s*[,)]/,
3088
+ /fetch\s*\(\s*searchParams\.get\s*\(/,
3089
+ /fetch\s*\(\s*formData\.get\s*\(/,
3090
+ /new\s+URL\s*\(\s*(?:req|request)\.(?:body|query)/,
3091
+ /axios\s*[.(]\s*(?:req|request)\.(?:body|query)/,
3092
+ /axios\.get\s*\(\s*(?:url|href|endpoint|target|link)\s*[,)]/
3093
+ ];
3094
+ var VALIDATION_PATTERNS3 = [
3095
+ /allowlist/i,
3096
+ /allowedUrls/i,
3097
+ /allowedHosts/i,
3098
+ /allowedDomains/i,
3099
+ /whitelist/i,
3100
+ /validUrl/i,
3101
+ /validateUrl/i,
3102
+ /URL\.canParse/,
3103
+ /new\s+URL\s*\(.*\)\.host/,
3104
+ /\.startsWith\s*\(\s*['"]https?:\/\//,
3105
+ /\.hostname\s*[!=]==?\s*['"`]/
3106
+ ];
3107
+ var ssrfRiskRule = {
3108
+ id: "ssrf-risk",
3109
+ name: "SSRF Risk",
3110
+ description: "Detects fetch/HTTP calls with user-controlled URLs without validation \u2014 allows attackers to probe internal services",
3111
+ category: "security",
3112
+ severity: "warning",
3113
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
3114
+ check(file, _project) {
3115
+ if (isTestFile(file.relativePath)) return [];
3116
+ if (!isApiRoute(file.relativePath) && !/['"]use server['"]/.test(file.content)) return [];
3117
+ const hasValidation = VALIDATION_PATTERNS3.some((p) => p.test(file.content));
3118
+ if (hasValidation) return [];
3119
+ const findings = [];
3120
+ for (let i = 0; i < file.lines.length; i++) {
3121
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3122
+ const line = file.lines[i];
3123
+ for (const pattern of USER_INPUT_IN_FETCH) {
3124
+ const match = pattern.exec(line);
3125
+ if (match) {
3126
+ findings.push({
3127
+ ruleId: "ssrf-risk",
3128
+ file: file.relativePath,
3129
+ line: i + 1,
3130
+ column: match.index + 1,
3131
+ message: "User-controlled URL passed to fetch \u2014 validate against an allowlist to prevent SSRF",
3132
+ severity: "warning",
3133
+ category: "security",
3134
+ fix: "Validate the URL against an allowlist of permitted domains before making the request"
3135
+ });
3136
+ break;
3137
+ }
3138
+ }
3139
+ }
3140
+ return findings;
3141
+ }
3142
+ };
3143
+
3144
+ // src/rules/path-traversal.ts
3145
+ var FS_WITH_USER_INPUT = [
3146
+ { pattern: /(?:readFile|readFileSync|createReadStream)\s*\(\s*(?:req|request)\.(?:query|body|params)/, msg: "File read with user-controlled path \u2014 allows reading arbitrary files" },
3147
+ { pattern: /(?:readFile|readFileSync|createReadStream)\s*\(\s*(?:filePath|fileName|path|file|name)\s*[,)]/, msg: "File read with potentially user-controlled path \u2014 validate before use" },
3148
+ { pattern: /(?:writeFile|writeFileSync|createWriteStream)\s*\(\s*(?:req|request)\.(?:query|body|params)/, msg: "File write with user-controlled path \u2014 allows writing arbitrary files" },
3149
+ { pattern: /(?:unlink|unlinkSync|rm|rmSync)\s*\(\s*(?:req|request)\.(?:query|body|params)/, msg: "File delete with user-controlled path \u2014 allows deleting arbitrary files" },
3150
+ { pattern: /path\.join\s*\([^)]*(?:req|request)\.(?:query|body|params)/, msg: "path.join with user input \u2014 still vulnerable to traversal with ../" },
3151
+ { pattern: /\.sendFile\s*\(\s*(?:req|request)\.(?:query|body|params)/, msg: "express.sendFile with user-controlled path \u2014 validate against a base directory" }
3152
+ ];
3153
+ var SANITIZATION_PATTERNS = [
3154
+ /path\.resolve\s*\(.*\)\.startsWith/,
3155
+ /\.replace\s*\(\s*['"]\.\.['"],?\s*['"].*['"]\s*\)/,
3156
+ /\.includes\s*\(\s*['"]\.\.['"].*\)/,
3157
+ /normalize/,
3158
+ /sanitize/i,
3159
+ /realpath/
3160
+ ];
3161
+ var pathTraversalRule = {
3162
+ id: "path-traversal",
3163
+ name: "Path Traversal",
3164
+ description: "Detects filesystem operations with user-controlled paths \u2014 allows reading/writing arbitrary files via ../ sequences",
3165
+ category: "security",
3166
+ severity: "critical",
3167
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
3168
+ check(file, _project) {
3169
+ if (isTestFile(file.relativePath)) return [];
3170
+ const hasSanitization = SANITIZATION_PATTERNS.some((p) => p.test(file.content));
3171
+ if (hasSanitization) return [];
3172
+ const findings = [];
3173
+ for (let i = 0; i < file.lines.length; i++) {
3174
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3175
+ const line = file.lines[i];
3176
+ for (const { pattern, msg } of FS_WITH_USER_INPUT) {
3177
+ const match = pattern.exec(line);
3178
+ if (match) {
3179
+ const severity = /req|request/.test(match[0]) ? "critical" : "warning";
3180
+ findings.push({
3181
+ ruleId: "path-traversal",
3182
+ file: file.relativePath,
3183
+ line: i + 1,
3184
+ column: match.index + 1,
3185
+ message: msg,
3186
+ severity,
3187
+ category: "security",
3188
+ fix: "Validate the resolved path starts with an expected base directory: path.resolve(base, input).startsWith(path.resolve(base))"
3189
+ });
3190
+ break;
3191
+ }
3192
+ }
3193
+ }
3194
+ return findings;
3195
+ }
3196
+ };
3197
+
3198
+ // src/rules/hydration-mismatch.ts
3199
+ var BROWSER_ONLY_PATTERNS = [
3200
+ { pattern: /\bwindow\./, msg: "window access in server-rendered code \u2014 will differ between server and client" },
3201
+ { pattern: /\bdocument\./, msg: "document access in server-rendered code \u2014 undefined on the server" },
3202
+ { pattern: /\blocalStorage\b/, msg: "localStorage in render path \u2014 undefined on server, causes hydration mismatch" },
3203
+ { pattern: /\bsessionStorage\b/, msg: "sessionStorage in render path \u2014 undefined on server, causes hydration mismatch" },
3204
+ { pattern: /\bnavigator\./, msg: "navigator access in render path \u2014 undefined on server" }
3205
+ ];
3206
+ var NONDETERMINISTIC_PATTERNS = [
3207
+ { pattern: /\bnew\s+Date\s*\(\s*\)/, msg: "new Date() in render path \u2014 server and client will have different timestamps, causing hydration mismatch" },
3208
+ { pattern: /\bDate\.now\s*\(\s*\)/, msg: "Date.now() in render path \u2014 different on server vs client" },
3209
+ { pattern: /\bMath\.random\s*\(\s*\)/, msg: "Math.random() in render path \u2014 produces different values on server vs client" }
3210
+ ];
3211
+ var hydrationMismatchRule = {
3212
+ id: "hydration-mismatch",
3213
+ name: "Hydration Mismatch Risk",
3214
+ description: "Detects browser-only APIs and non-deterministic calls in server component render paths",
3215
+ category: "reliability",
3216
+ severity: "warning",
3217
+ fileExtensions: ["tsx", "jsx", "ts", "js"],
3218
+ check(file, _project) {
3219
+ if (isTestFile(file.relativePath)) return [];
3220
+ if (isClientComponent(file.content)) return [];
3221
+ if (!/(?:^|\/)(?:src\/)?app\//.test(file.relativePath)) return [];
3222
+ if (/route\.[jt]sx?$/.test(file.relativePath)) return [];
3223
+ const findings = [];
3224
+ let insideUseEffect = false;
3225
+ for (let i = 0; i < file.lines.length; i++) {
3226
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3227
+ const line = file.lines[i];
3228
+ if (/\buseEffect\s*\(/.test(line)) {
3229
+ insideUseEffect = true;
3230
+ }
3231
+ if (insideUseEffect) {
3232
+ if (/^\s*\}\s*,\s*\[/.test(line) || /^\s*\}\s*\)\s*;?\s*$/.test(line)) {
3233
+ insideUseEffect = false;
3234
+ }
3235
+ continue;
3236
+ }
3237
+ for (const { pattern, msg } of [...BROWSER_ONLY_PATTERNS, ...NONDETERMINISTIC_PATTERNS]) {
3238
+ const match = pattern.exec(line);
3239
+ if (match) {
3240
+ findings.push({
3241
+ ruleId: "hydration-mismatch",
3242
+ file: file.relativePath,
3243
+ line: i + 1,
3244
+ column: match.index + 1,
3245
+ message: msg,
3246
+ severity: "warning",
3247
+ category: "reliability",
3248
+ fix: 'Move this to a useEffect hook, or add "use client" if this component needs browser APIs'
3249
+ });
3250
+ break;
3251
+ }
3252
+ }
3253
+ }
3254
+ return findings;
3255
+ }
3256
+ };
3257
+
3258
+ // src/rules/server-component-fetch-self.ts
3259
+ var SELF_FETCH_PATTERNS = [
3260
+ /fetch\s*\(\s*['"`]\/api\//,
3261
+ /fetch\s*\(\s*['"`]http:\/\/localhost/,
3262
+ /fetch\s*\(\s*['"`]https?:\/\/localhost/,
3263
+ /fetch\s*\(\s*`\$\{.*\}\/api\//,
3264
+ /fetch\s*\(\s*(?:process\.env\.\w+\s*\+\s*)?['"`]\/api\//
3265
+ ];
3266
+ var serverComponentFetchSelfRule = {
3267
+ id: "server-component-fetch-self",
3268
+ name: "Server Component Fetching Own API",
3269
+ description: "Detects server components that fetch their own API routes instead of calling data logic directly \u2014 unnecessary network roundtrip",
3270
+ category: "performance",
3271
+ severity: "info",
3272
+ fileExtensions: ["tsx", "jsx", "ts", "js"],
3273
+ check(file, _project) {
3274
+ if (isTestFile(file.relativePath)) return [];
3275
+ if (isClientComponent(file.content)) return [];
3276
+ if (!/(?:^|\/)(?:src\/)?app\//.test(file.relativePath)) return [];
3277
+ if (/route\.[jt]sx?$/.test(file.relativePath)) return [];
3278
+ const findings = [];
3279
+ for (let i = 0; i < file.lines.length; i++) {
3280
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3281
+ const line = file.lines[i];
3282
+ for (const pattern of SELF_FETCH_PATTERNS) {
3283
+ const match = pattern.exec(line);
3284
+ if (match) {
3285
+ findings.push({
3286
+ ruleId: "server-component-fetch-self",
3287
+ file: file.relativePath,
3288
+ line: i + 1,
3289
+ column: match.index + 1,
3290
+ message: "Server component fetches its own API route \u2014 call the data logic directly instead of making a network request to yourself",
3291
+ severity: "info",
3292
+ category: "performance",
3293
+ fix: 'Import and call the data function directly instead of fetch("/api/...")'
3294
+ });
3295
+ break;
3296
+ }
3297
+ }
3298
+ }
3299
+ return findings;
3300
+ }
3301
+ };
3302
+
3303
+ // src/rules/unsafe-file-upload.ts
3304
+ var UPLOAD_PATTERNS = [
3305
+ /\.get\s*\(\s*['"`]file['"`]\s*\)/,
3306
+ /\.get\s*\(\s*['"`]image['"`]\s*\)/,
3307
+ /\.get\s*\(\s*['"`]upload['"`]\s*\)/,
3308
+ /\.get\s*\(\s*['"`]attachment['"`]\s*\)/,
3309
+ /\.get\s*\(\s*['"`]document['"`]\s*\)/,
3310
+ /\.get\s*\(\s*['"`]avatar['"`]\s*\)/,
3311
+ /\.get\s*\(\s*['"`]photo['"`]\s*\)/,
3312
+ /\.type\s*===?\s*['"`]file['"`]/,
3313
+ /req\.file\b/,
3314
+ /multer/i,
3315
+ /busboy/i,
3316
+ /formidable/i
3317
+ ];
3318
+ var VALIDATION_PATTERNS4 = [
3319
+ /\.type\b.*(?:image|video|audio|pdf|text)\//,
3320
+ /content-type/i,
3321
+ /mime/i,
3322
+ /\.size\s*[><!]/,
3323
+ /maxFileSize/i,
3324
+ /maxSize/i,
3325
+ /fileSizeLimit/i,
3326
+ /allowedTypes/i,
3327
+ /acceptedTypes/i,
3328
+ /fileFilter/i,
3329
+ /\.endsWith\s*\(\s*['"`]\./,
3330
+ /\.extension/i
3331
+ ];
3332
+ var unsafeFileUploadRule = {
3333
+ id: "unsafe-file-upload",
3334
+ name: "Unsafe File Upload",
3335
+ description: "Detects file upload handlers without type or size validation",
3336
+ category: "security",
3337
+ severity: "warning",
3338
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
3339
+ check(file, _project) {
3340
+ if (isTestFile(file.relativePath)) return [];
3341
+ if (!isApiRoute(file.relativePath) && !/['"]use server['"]/.test(file.content)) return [];
3342
+ const hasUpload = UPLOAD_PATTERNS.some((p) => p.test(file.content));
3343
+ if (!hasUpload) return [];
3344
+ const hasValidation = VALIDATION_PATTERNS4.some((p) => p.test(file.content));
3345
+ if (hasValidation) return [];
3346
+ let reportLine = 1;
3347
+ for (let i = 0; i < file.lines.length; i++) {
3348
+ if (UPLOAD_PATTERNS.some((p) => p.test(file.lines[i]))) {
3349
+ reportLine = i + 1;
3350
+ break;
3351
+ }
3352
+ }
3353
+ return [{
3354
+ ruleId: "unsafe-file-upload",
3355
+ file: file.relativePath,
3356
+ line: reportLine,
3357
+ column: 1,
3358
+ message: "File upload without type or size validation \u2014 accepts any file type and size",
3359
+ severity: "warning",
3360
+ category: "security",
3361
+ fix: "Validate file type (check MIME type, not just extension) and enforce a size limit before processing"
3362
+ }];
3363
+ }
3364
+ };
3365
+
3366
+ // src/rules/supabase-missing-rls.ts
3367
+ var CREATE_TABLE = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:public\.)?(\w+)/gi;
3368
+ var ENABLE_RLS = /ALTER\s+TABLE\s+(?:(?:public|"public")\.)?(\w+)\s+ENABLE\s+ROW\s+LEVEL\s+SECURITY/gi;
3369
+ var supabaseMissingRlsRule = {
3370
+ id: "supabase-missing-rls",
3371
+ name: "Missing Row-Level Security",
3372
+ description: "Detects SQL migrations that create tables without enabling Row-Level Security \u2014 all data is publicly accessible",
3373
+ category: "security",
3374
+ severity: "critical",
3375
+ fileExtensions: ["sql"],
3376
+ check(file, project) {
3377
+ if (isTestFile(file.relativePath)) return [];
3378
+ if (!/migration|supabase|schema/i.test(file.relativePath)) return [];
3379
+ const content = file.content;
3380
+ const findings = [];
3381
+ const tables = [];
3382
+ CREATE_TABLE.lastIndex = 0;
3383
+ let match;
3384
+ while ((match = CREATE_TABLE.exec(content)) !== null) {
3385
+ const name = match[1];
3386
+ if (name.startsWith("_") || name === "schema_migrations") continue;
3387
+ const beforeMatch = content.slice(0, match.index);
3388
+ const line = beforeMatch.split("\n").length;
3389
+ tables.push({ name, line });
3390
+ }
3391
+ if (tables.length === 0) return [];
3392
+ const rlsTables = /* @__PURE__ */ new Set();
3393
+ ENABLE_RLS.lastIndex = 0;
3394
+ while ((match = ENABLE_RLS.exec(content)) !== null) {
3395
+ rlsTables.add(match[1].toLowerCase());
3396
+ }
3397
+ for (const filePath of project.allFiles) {
3398
+ if (!filePath.endsWith(".sql")) continue;
3399
+ if (filePath === file.relativePath) continue;
3400
+ }
3401
+ for (const table of tables) {
3402
+ if (!rlsTables.has(table.name.toLowerCase())) {
3403
+ findings.push({
3404
+ ruleId: "supabase-missing-rls",
3405
+ file: file.relativePath,
3406
+ line: table.line,
3407
+ column: 1,
3408
+ message: `Table "${table.name}" created without ENABLE ROW LEVEL SECURITY \u2014 all rows are publicly accessible via the Supabase API`,
3409
+ severity: "critical",
3410
+ category: "security",
3411
+ fix: `Add: ALTER TABLE ${table.name} ENABLE ROW LEVEL SECURITY; and create appropriate policies`
3412
+ });
3413
+ }
3414
+ }
3415
+ return findings;
3416
+ }
3417
+ };
3418
+
3419
+ // src/rules/deprecated-oauth-flow.ts
3420
+ var IMPLICIT_GRANT = /response_type\s*[=:]\s*['"`]?token['"`]?/;
3421
+ var deprecatedOauthFlowRule = {
3422
+ id: "deprecated-oauth-flow",
3423
+ name: "Deprecated OAuth Flow",
3424
+ description: "Detects OAuth Implicit Grant flow (response_type=token) \u2014 deprecated in OAuth 2.1, vulnerable to token interception",
3425
+ category: "security",
3426
+ severity: "warning",
3427
+ fileExtensions: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
3428
+ check(file, _project) {
3429
+ if (isTestFile(file.relativePath)) return [];
3430
+ const findings = [];
3431
+ for (let i = 0; i < file.lines.length; i++) {
3432
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3433
+ const line = file.lines[i];
3434
+ const match = IMPLICIT_GRANT.exec(line);
3435
+ if (match) {
3436
+ findings.push({
3437
+ ruleId: "deprecated-oauth-flow",
3438
+ file: file.relativePath,
3439
+ line: i + 1,
3440
+ column: match.index + 1,
3441
+ message: "OAuth Implicit Grant flow (response_type=token) is deprecated \u2014 tokens are exposed in the URL fragment",
3442
+ severity: "warning",
3443
+ category: "security",
3444
+ fix: "Use Authorization Code flow with PKCE: response_type=code with code_challenge and code_verifier"
3445
+ });
3446
+ }
3447
+ }
3448
+ return findings;
3449
+ }
3450
+ };
3451
+
3452
+ // src/rules/jwt-no-expiry.ts
3453
+ var JWT_SIGN = /jwt\.sign\s*\(/;
3454
+ var HAS_EXPIRY = [
3455
+ /expiresIn/,
3456
+ /exp\s*:/,
3457
+ /expirationTime/,
3458
+ /maxAge/
3459
+ ];
3460
+ var jwtNoExpiryRule = {
3461
+ id: "jwt-no-expiry",
3462
+ name: "JWT Without Expiration",
3463
+ description: "Detects jwt.sign() calls without an expiresIn option \u2014 tokens never expire, compromised tokens are valid forever",
3464
+ category: "security",
3465
+ severity: "warning",
3466
+ fileExtensions: ["ts", "tsx", "js", "jsx", "mjs", "cjs"],
3467
+ check(file, _project) {
3468
+ if (isTestFile(file.relativePath)) return [];
3469
+ if (!JWT_SIGN.test(file.content)) return [];
3470
+ const findings = [];
3471
+ for (let i = 0; i < file.lines.length; i++) {
3472
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3473
+ const line = file.lines[i];
3474
+ const match = JWT_SIGN.exec(line);
3475
+ if (!match) continue;
3476
+ const context = file.lines.slice(i, i + 6).join("\n");
3477
+ const hasExpiry = HAS_EXPIRY.some((p) => p.test(context));
3478
+ if (!hasExpiry) {
3479
+ findings.push({
3480
+ ruleId: "jwt-no-expiry",
3481
+ file: file.relativePath,
3482
+ line: i + 1,
3483
+ column: match.index + 1,
3484
+ message: "jwt.sign() without expiresIn \u2014 tokens never expire, a compromised token is valid forever",
3485
+ severity: "warning",
3486
+ category: "security",
3487
+ fix: 'Add expiration: jwt.sign(payload, secret, { expiresIn: "1h" })'
3488
+ });
3489
+ }
3490
+ }
3491
+ return findings;
3492
+ }
3493
+ };
3494
+
3495
+ // src/rules/client-side-auth-only.ts
3496
+ var CLIENT_AUTH_PATTERNS = [
3497
+ /localStorage\.(?:get|set)Item\s*\(\s*['"`](?:token|auth|session|jwt|access_token|user)['"`]/,
3498
+ /sessionStorage\.(?:get|set)Item\s*\(\s*['"`](?:token|auth|session|jwt|access_token|user)['"`]/
3499
+ ];
3500
+ var PASSWORD_CHECK = /(?:password|passwd)\s*[!=]==?\s*['"`]/;
3501
+ var clientSideAuthOnlyRule = {
3502
+ id: "client-side-auth-only",
3503
+ name: "Client-Side Auth Only",
3504
+ description: "Detects authentication logic implemented only in client-side code \u2014 easily bypassed via browser DevTools",
3505
+ category: "security",
3506
+ severity: "critical",
3507
+ fileExtensions: ["tsx", "jsx", "ts", "js"],
3508
+ check(file, _project) {
3509
+ if (isTestFile(file.relativePath)) return [];
3510
+ if (!isClientComponent(file.content)) return [];
3511
+ const findings = [];
3512
+ for (let i = 0; i < file.lines.length; i++) {
3513
+ const line = file.lines[i];
3514
+ const match = PASSWORD_CHECK.exec(line);
3515
+ if (match) {
3516
+ findings.push({
3517
+ ruleId: "client-side-auth-only",
3518
+ file: file.relativePath,
3519
+ line: i + 1,
3520
+ column: match.index + 1,
3521
+ message: "Password comparison in client-side code \u2014 the password is visible in the JavaScript bundle",
3522
+ severity: "critical",
3523
+ category: "security",
3524
+ fix: "Move authentication logic to a server action or API route"
3525
+ });
3526
+ }
3527
+ }
3528
+ for (let i = 0; i < file.lines.length; i++) {
3529
+ const line = file.lines[i];
3530
+ for (const pattern of CLIENT_AUTH_PATTERNS) {
3531
+ const match = pattern.exec(line);
3532
+ if (match) {
3533
+ findings.push({
3534
+ ruleId: "client-side-auth-only",
3535
+ file: file.relativePath,
3536
+ line: i + 1,
3537
+ column: match.index + 1,
3538
+ message: "Auth token in localStorage \u2014 accessible to any script on the page (XSS risk). Use httpOnly cookies instead.",
3539
+ severity: "warning",
3540
+ category: "security",
3541
+ fix: "Store auth tokens in httpOnly cookies set by the server, not in localStorage"
3542
+ });
3543
+ break;
3544
+ }
3545
+ }
3546
+ }
3547
+ return findings;
3548
+ }
3549
+ };
3550
+
3551
+ // src/rules/missing-abort-controller.ts
3552
+ var FETCH_CALL = /\bfetch\s*\(/;
3553
+ var HAS_TIMEOUT = [
3554
+ /AbortController/,
3555
+ /abort/i,
3556
+ /signal\s*:/,
3557
+ /timeout/i,
3558
+ /setTimeout.*abort/s
3559
+ ];
3560
+ var missingAbortControllerRule = {
3561
+ id: "missing-abort-controller",
3562
+ name: "Missing Abort Controller",
3563
+ description: "Detects fetch calls in API routes without timeout or AbortController \u2014 requests can hang indefinitely",
3564
+ category: "performance",
3565
+ severity: "info",
3566
+ fileExtensions: ["ts", "tsx", "js", "jsx"],
3567
+ check(file, _project) {
3568
+ if (isTestFile(file.relativePath)) return [];
3569
+ if (!isApiRoute(file.relativePath) && !/['"]use server['"]/.test(file.content)) return [];
3570
+ if (!FETCH_CALL.test(file.content)) return [];
3571
+ const hasTimeout = HAS_TIMEOUT.some((p) => p.test(file.content));
3572
+ if (hasTimeout) return [];
3573
+ let reportLine = 1;
3574
+ for (let i = 0; i < file.lines.length; i++) {
3575
+ if (isCommentLine(file.lines, i, file.commentMap)) continue;
3576
+ if (FETCH_CALL.test(file.lines[i])) {
3577
+ reportLine = i + 1;
3578
+ break;
3579
+ }
3580
+ }
3581
+ return [{
3582
+ ruleId: "missing-abort-controller",
3583
+ file: file.relativePath,
3584
+ line: reportLine,
3585
+ column: 1,
3586
+ message: "fetch() without timeout or AbortController \u2014 request will hang indefinitely if the upstream server doesn't respond",
3587
+ severity: "info",
3588
+ category: "performance",
3589
+ fix: "Add a timeout: const controller = new AbortController(); setTimeout(() => controller.abort(), 10000); fetch(url, { signal: controller.signal })"
3590
+ }];
3591
+ }
3592
+ };
3593
+
2541
3594
  // src/rules/index.ts
2542
3595
  var rules = [
2543
3596
  // Security
@@ -2555,6 +3608,19 @@ var rules = [
2555
3608
  leakedEnvInLogsRule,
2556
3609
  insecureRandomRule,
2557
3610
  nextServerActionValidationRule,
3611
+ envFallbackSecretRule,
3612
+ verboseErrorResponseRule,
3613
+ missingWebhookVerificationRule,
3614
+ serverActionAuthRule,
3615
+ evalInjectionRule,
3616
+ nextPublicSensitiveRule,
3617
+ ssrfRiskRule,
3618
+ pathTraversalRule,
3619
+ unsafeFileUploadRule,
3620
+ supabaseMissingRlsRule,
3621
+ deprecatedOauthFlowRule,
3622
+ jwtNoExpiryRule,
3623
+ clientSideAuthOnlyRule,
2558
3624
  // Reliability
2559
3625
  hallucinatedImportsRule,
2560
3626
  errorHandlingRule,
@@ -2563,11 +3629,17 @@ var rules = [
2563
3629
  missingLoadingStateRule,
2564
3630
  missingErrorBoundaryRule,
2565
3631
  missingTransactionRule,
3632
+ redirectInTryCatchRule,
3633
+ missingRevalidationRule,
3634
+ missingUseEffectCleanupRule,
3635
+ hydrationMismatchRule,
2566
3636
  // Performance
2567
3637
  noSyncFsRule,
2568
3638
  noNPlusOneRule,
2569
3639
  noUnboundedQueryRule,
2570
3640
  noDynamicImportLoopRule,
3641
+ serverComponentFetchSelfRule,
3642
+ missingAbortControllerRule,
2571
3643
  // AI Quality
2572
3644
  aiSmellsRule,
2573
3645
  placeholderContentRule,
@@ -2575,7 +3647,8 @@ var rules = [
2575
3647
  staleFallbackRule,
2576
3648
  comprehensionDebtRule,
2577
3649
  codebaseConsistencyRule,
2578
- deadExportsRule
3650
+ deadExportsRule,
3651
+ useClientOveruseRule
2579
3652
  ];
2580
3653
 
2581
3654
  // src/scanner.ts
@@ -2758,7 +3831,7 @@ async function main() {
2758
3831
  }
2759
3832
  function printHelp() {
2760
3833
  console.log(`
2761
- prodlint - Scan AI-generated projects for production readiness issues
3834
+ prodlint - The linter for vibe-coded apps
2762
3835
 
2763
3836
  Usage:
2764
3837
  npx prodlint [path] [options]