lonkero 3.7.0

Web scanner built for actual pentests. Fast, modular, Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
// Copyright (c) 2026 Bountyy Oy. All rights reserved.
// This software is proprietary and confidential.

/**
 * Bountyy Oy - Security Scanner Engine
 * Main scan orchestration and coordination
 *
 * @copyright 2026 Bountyy Oy
 * @license Proprietary
 */
use crate::analysis::{IntelligenceBus, ResponseAnalyzer};
use crate::config::ScannerConfig;
use crate::crawler::{CrawlResults, WebCrawler};
use crate::framework_detector::FrameworkDetector;
use crate::http_client::HttpClient;
use crate::queue::RedisQueue;
use crate::rate_limiter::{AdaptiveRateLimiter, RateLimiterConfig};
use crate::subdomain_enum::SubdomainEnumerator;
use crate::types::{Confidence, ScanJob, ScanMode, ScanResults, Severity, Vulnerability};
use anyhow::{Context, Result};
use std::collections::HashSet;
use std::sync::Arc;
use std::time::Instant;
use tracing::{debug, error, info, warn};

pub mod account_takeover;
pub mod advanced_auth;
pub mod api_fuzzer;
pub mod api_gateway_scanner;
pub mod api_security;
pub mod api_versioning;
pub mod arcgis_rest;
pub mod aspnet_scanner;
pub mod attack_surface;
pub mod auth_bypass;
pub mod auth_flow_tester;
pub mod auth_manager;
pub mod azure_apim;
pub mod baseline_detector;
pub mod bola;
pub mod broken_function_auth;
pub mod business_logic;
pub mod cache_poisoning;
pub mod hybrid_xss; // Browser-less XSS detection
pub mod clickjacking;
pub mod client_route_auth_bypass;
pub mod cloud_security_scanner;
pub mod cloud_storage;
pub mod code_injection;
pub mod cognito_enum;
pub mod command_injection;
pub mod compliance_scanner;
pub mod container_scanner;
pub mod cors;
pub mod cors_misconfiguration;
pub mod crlf_injection;
pub mod csp_bypass;
pub mod csrf;
pub mod cve_2025_55182;
pub mod cve_2025_55183;
pub mod cve_2025_55184;
pub mod deserialization;
pub mod django_security;
pub mod dom_clobbering;
pub mod dora_scanner;
pub mod drupal_security;
pub mod email_header_injection;
pub mod express_security;
pub mod fastapi_scanner;
pub mod favicon_hash_scanner;
pub mod file_upload;
pub mod file_upload_vulnerabilities;
pub mod firebase;
pub mod framework_vulnerabilities;
pub mod go_frameworks_scanner;
pub mod google_dorking;
pub mod graphql;
pub mod graphql_batching;
pub mod graphql_security;
pub mod grpc;
pub mod host_header_injection;
pub mod html_injection;
pub mod http3_scanner;
pub mod http_parameter_pollution;
pub mod http_smuggling;
pub mod idor;
pub mod idor_analyzer;
pub mod information_disclosure;
pub mod intelligent_orchestrator;
pub mod joomla_scanner;
pub mod js_miner;
pub mod js_sensitive_info;
pub mod jwt;
pub mod jwt_analyzer;
pub mod jwt_vulnerabilities;
pub mod laravel_security;
pub mod ldap_injection;
pub mod liferay_security;
pub mod log4j_scanner;
pub mod mass_assignment;
pub mod mass_assignment_advanced;
pub mod merlin;
pub mod mfa;
pub mod nextjs_security;
pub mod nis2_scanner;
pub mod nosql;
pub mod nosql_injection;
pub mod oauth;
pub mod oidc_scanner;
pub mod open_redirect;
pub mod openapi_analyzer;
pub mod parameter_filter;
pub mod parameter_prioritizer;
pub mod password_reset_poisoning;
pub mod path_traversal;
pub mod postmessage_vulns;
pub mod proof_xss_scanner; // Proof-based XSS detection (no Chrome, 2-3 requests)
pub mod prototype_pollution;
pub mod race_condition;
pub mod rails_scanner;
pub mod readme_prompt_injection;
pub mod rate_limiting;
pub mod react_security;
pub mod redos;
pub mod reflection_xss_scanner;
pub mod registry;
pub mod saml;
pub mod second_order_injection;
pub mod security_headers;
pub mod sensitive_data;
pub mod session_analyzer;
pub mod session_management;
pub mod source_map_scanner;
pub mod spring_scanner;
pub mod sqli_enhanced;
pub mod ssi_injection;
pub mod ssrf;
pub mod ssrf_blind;
pub mod ssti_advanced_scanner;
pub mod stealth_recon;
pub mod subdomain_takeover;
pub mod sveltekit_security;
pub mod template_injection;
pub mod timing_attacks;
pub mod tomcat_misconfig;
pub mod twofa_bypass;
pub mod varnish_misconfig;
pub mod waf_bypass;
pub mod web_cache_deception;
pub mod webauthn_scanner;
pub mod websocket;
pub mod wordpress_security;
pub mod xml_injection;
pub mod xpath_injection;
pub mod xxe;

// External security scanners
pub mod external;

// Re-export scanner types for easy access
pub use account_takeover::AccountTakeoverScanner;
pub use advanced_auth::AdvancedAuthScanner;
pub use api_fuzzer::ApiFuzzerScanner;
pub use api_gateway_scanner::ApiGatewayScanner;
pub use api_security::APISecurityScanner;
pub use api_versioning::ApiVersioningScanner;
pub use arcgis_rest::ArcGISRestScanner;
pub use aspnet_scanner::AspNetScanner;
pub use attack_surface::{
    AttackSurface, ContentType, DeduplicatedTargets, EndpointSignature, FormData, FormSignature,
    ParameterContext, ParameterSource, PathNormalizer, TestEndpoint, TestForm, TestParameter,
    ValueType,
};
pub use auth_bypass::AuthBypassScanner;
pub use auth_manager::AuthManagerScanner;
pub use azure_apim::AzureApimScanner;
pub use baseline_detector::BaselineDetector;
pub use bola::BolaScanner;
pub use broken_function_auth::BrokenFunctionAuthScanner;
pub use business_logic::BusinessLogicScanner;
pub use cache_poisoning::CachePoisoningScanner;
pub use hybrid_xss::HybridXssDetector;
pub use proof_xss_scanner::ProofXssScanner;
pub use reflection_xss_scanner::ReflectionXssScanner;
pub use clickjacking::ClickjackingScanner;
pub use client_route_auth_bypass::ClientRouteAuthBypassScanner;
pub use cloud_security_scanner::CloudSecurityScanner;
pub use cloud_storage::CloudStorageScanner;
pub use code_injection::CodeInjectionScanner;
pub use cognito_enum::CognitoEnumScanner;
pub use command_injection::CommandInjectionScanner;
pub use compliance_scanner::ComplianceScanner;
pub use container_scanner::ContainerScanner;
pub use cors::CorsScanner;
pub use cors_misconfiguration::CorsMisconfigurationScanner;
pub use crlf_injection::CrlfInjectionScanner;
pub use csrf::CsrfScanner;
pub use cve_2025_55182::Cve202555182Scanner;
pub use cve_2025_55183::Cve202555183Scanner;
pub use cve_2025_55184::Cve202555184Scanner;
pub use deserialization::DeserializationScanner;
pub use django_security::DjangoSecurityScanner;
pub use dom_clobbering::DomClobberingScanner;
pub use dora_scanner::DoraScanner;
pub use drupal_security::DrupalSecurityScanner;
pub use email_header_injection::EmailHeaderInjectionScanner;
pub use express_security::ExpressSecurityScanner;
pub use fastapi_scanner::FastApiScanner;
pub use favicon_hash_scanner::FaviconHashScanner;
pub use file_upload::FileUploadScanner;
pub use file_upload_vulnerabilities::FileUploadVulnerabilitiesScanner;
pub use firebase::FirebaseScanner;
pub use framework_vulnerabilities::FrameworkVulnerabilitiesScanner;
pub use go_frameworks_scanner::GoFrameworksScanner;
pub use google_dorking::{GoogleDork, GoogleDorkingResults, GoogleDorkingScanner};
pub use graphql::GraphQlScanner;
pub use graphql_batching::GraphQlBatchingScanner;
pub use graphql_security::GraphqlSecurityScanner;
pub use grpc::GrpcScanner;
pub use host_header_injection::HostHeaderInjectionScanner;
pub use html_injection::HtmlInjectionScanner;
pub use http3_scanner::Http3Scanner;
pub use http_parameter_pollution::HttpParameterPollutionScanner;
pub use http_smuggling::HTTPSmugglingScanner;
pub use idor::IdorScanner;
pub use information_disclosure::InformationDisclosureScanner;
pub use intelligent_orchestrator::{
    IntelligentScanOrchestrator, IntelligentScanPlan, OrchestrationStats, PrioritizedParameter,
};
pub use joomla_scanner::JoomlaScanner;
pub use js_miner::{JsMinerResults, JsMinerScanner};
pub use js_sensitive_info::JsSensitiveInfoScanner;
pub use jwt::JwtScanner;
pub use jwt_vulnerabilities::JwtVulnerabilitiesScanner;
pub use laravel_security::LaravelSecurityScanner;
pub use ldap_injection::LdapInjectionScanner;
pub use liferay_security::LiferaySecurityScanner;
pub use log4j_scanner::Log4jScanner;
pub use mass_assignment::MassAssignmentScanner;
pub use merlin::MerlinScanner;
pub use mfa::MfaScanner;
pub use nextjs_security::NextJsSecurityScanner;
pub use nis2_scanner::Nis2Scanner;
pub use nosql::NoSqlScanner;
pub use nosql_injection::NosqlInjectionScanner;
pub use oauth::OAuthScanner;
pub use oidc_scanner::OidcScanner;
pub use open_redirect::OpenRedirectScanner;
pub use openapi_analyzer::OpenApiAnalyzer;
pub use parameter_prioritizer::{
    FormContext, ParameterInfo, ParameterPrioritizer, ParameterRisk,
    ParameterSource as PrioritizerParameterSource, RiskFactor,
    ScannerType as PrioritizerScannerType,
};
pub use password_reset_poisoning::PasswordResetPoisoningScanner;
pub use path_traversal::PathTraversalScanner;
pub use postmessage_vulns::PostMessageVulnsScanner;
pub use prototype_pollution::PrototypePollutionScanner;
pub use race_condition::RaceConditionScanner;
pub use rails_scanner::RailsScanner;
pub use readme_prompt_injection::ReadmePromptInjectionScanner;
pub use rate_limiting::RateLimitingScanner;
pub use react_security::ReactSecurityScanner;
pub use redos::RedosScanner;
pub use registry::{
    CloudProvider, DotNetFramework, GoFramework, JavaFramework, JsFramework, PayloadIntensity,
    PhpFramework, PythonFramework, RubyFramework, RustFramework,
    ScannerRegistry as TechScannerRegistry, ScannerTechMapping, ScannerType as TechScannerType,
    StaticPlatform, TechCategory,
};
pub use saml::SamlScanner;
pub use security_headers::SecurityHeadersScanner;
pub use sensitive_data::SensitiveDataScanner;
pub use session_management::SessionManagementScanner;
pub use source_map_scanner::SourceMapScanner;
pub use spring_scanner::SpringScanner;
pub use sqli_enhanced::EnhancedSqliScanner as SqliScanner;
pub use ssi_injection::SSIInjectionScanner;
pub use ssrf::SsrfScanner;
pub use ssrf_blind::SsrfBlindScanner;
pub use ssti_advanced_scanner::SstiAdvancedScanner;
pub use stealth_recon::{ProtectionLevel, Provider, RecommendedMode, StealthReconScanner, StealthReport};
pub use subdomain_takeover::{scan_subdomain_takeover, SubdomainTakeoverScanner};
pub use sveltekit_security::SvelteKitSecurityScanner;
pub use template_injection::TemplateInjectionScanner;
pub use tomcat_misconfig::TomcatMisconfigScanner;
pub use twofa_bypass::TwoFaBypassScanner;
pub use varnish_misconfig::VarnishMisconfigScanner;
pub use waf_bypass::WafBypassScanner;
pub use webauthn_scanner::WebAuthnScanner;
pub use websocket::WebSocketScanner;
pub use wordpress_security::WordPressSecurityScanner;
pub use xml_injection::XMLInjectionScanner;
pub use xpath_injection::XPathInjectionScanner;
pub use xxe::XxeScanner;
pub use second_order_injection::SecondOrderInjectionScanner;

pub struct ScanEngine {
    pub config: ScannerConfig,
    pub http_client: Arc<HttpClient>,
    pub request_batcher: Option<Arc<crate::request_batcher::RequestBatcher>>,
    pub adaptive_concurrency: Option<Arc<crate::adaptive_concurrency::AdaptiveConcurrencyTracker>>,
    pub dns_cache: Option<Arc<crate::dns_cache::DnsCache>>,
    pub hybrid_xss_detector: HybridXssDetector,
    pub proof_xss_scanner: ProofXssScanner,
    pub reflection_xss_scanner: ReflectionXssScanner,
    pub sqli_scanner: SqliScanner,
    pub cmdi_scanner: CommandInjectionScanner,
    pub path_scanner: PathTraversalScanner,
    pub ssrf_scanner: SsrfScanner,
    pub ssrf_blind_scanner: SsrfBlindScanner,
    pub jwt_scanner: JwtScanner,
    pub nosql_scanner: NoSqlScanner,
    pub security_headers_scanner: SecurityHeadersScanner,
    pub cors_scanner: CorsScanner,
    pub firebase_scanner: FirebaseScanner,
    pub csrf_scanner: CsrfScanner,
    pub xxe_scanner: XxeScanner,
    pub graphql_scanner: GraphQlScanner,
    pub oauth_scanner: OAuthScanner,
    pub oidc_scanner: OidcScanner,
    pub saml_scanner: SamlScanner,
    pub websocket_scanner: WebSocketScanner,
    pub grpc_scanner: GrpcScanner,
    pub auth_bypass_scanner: AuthBypassScanner,
    pub session_management_scanner: SessionManagementScanner,
    pub mfa_scanner: MfaScanner,
    pub idor_scanner: IdorScanner,
    pub bola_scanner: BolaScanner,
    pub auth_manager_scanner: AuthManagerScanner,
    pub advanced_auth_scanner: AdvancedAuthScanner,
    pub ldap_injection_scanner: LdapInjectionScanner,
    pub file_upload_scanner: FileUploadScanner,
    pub open_redirect_scanner: Arc<OpenRedirectScanner>,
    pub clickjacking_scanner: ClickjackingScanner,
    pub crlf_injection_scanner: CrlfInjectionScanner,
    pub email_header_injection_scanner: EmailHeaderInjectionScanner,
    pub template_injection_scanner: TemplateInjectionScanner,
    pub deserialization_scanner: DeserializationScanner,
    pub source_map_scanner: SourceMapScanner,
    pub favicon_hash_scanner: FaviconHashScanner,
    pub api_security_scanner: APISecurityScanner,
    pub http_smuggling_scanner: HTTPSmugglingScanner,
    pub xml_injection_scanner: XMLInjectionScanner,
    pub xpath_injection_scanner: XPathInjectionScanner,
    pub code_injection_scanner: CodeInjectionScanner,
    pub ssi_injection_scanner: SSIInjectionScanner,
    pub race_condition_scanner: RaceConditionScanner,
    pub readme_prompt_injection_scanner: ReadmePromptInjectionScanner,
    pub mass_assignment_scanner: MassAssignmentScanner,
    pub information_disclosure_scanner: InformationDisclosureScanner,
    pub cache_poisoning_scanner: CachePoisoningScanner,
    pub business_logic_scanner: BusinessLogicScanner,
    pub jwt_vulnerabilities_scanner: JwtVulnerabilitiesScanner,
    pub graphql_security_scanner: GraphqlSecurityScanner,
    pub nosql_injection_scanner: NosqlInjectionScanner,
    pub file_upload_vulnerabilities_scanner: FileUploadVulnerabilitiesScanner,
    pub cors_misconfiguration_scanner: CorsMisconfigurationScanner,
    pub cloud_storage_scanner: CloudStorageScanner,
    pub framework_vulnerabilities_scanner: FrameworkVulnerabilitiesScanner,
    pub js_miner_scanner: JsMinerScanner,
    pub sensitive_data_scanner: SensitiveDataScanner,
    pub api_fuzzer_scanner: ApiFuzzerScanner,
    pub api_gateway_scanner: ApiGatewayScanner,
    pub arcgis_rest_scanner: ArcGISRestScanner,
    pub cloud_security_scanner: CloudSecurityScanner,
    pub container_scanner: ContainerScanner,
    pub webauthn_scanner: WebAuthnScanner,
    pub http3_scanner: Http3Scanner,
    pub ssti_advanced_scanner: SstiAdvancedScanner,
    pub cve_2025_55182_scanner: Cve202555182Scanner,
    pub cve_2025_55183_scanner: Cve202555183Scanner,
    pub cve_2025_55184_scanner: Cve202555184Scanner,
    pub azure_apim_scanner: AzureApimScanner,
    pub redos_scanner: RedosScanner,
    pub hpp_scanner: HttpParameterPollutionScanner,
    pub waf_bypass_scanner: WafBypassScanner,
    pub merlin_scanner: MerlinScanner,
    pub tomcat_misconfig_scanner: TomcatMisconfigScanner,
    pub varnish_misconfig_scanner: VarnishMisconfigScanner,
    pub js_sensitive_info_scanner: JsSensitiveInfoScanner,
    pub client_route_auth_bypass_scanner: ClientRouteAuthBypassScanner,
    pub baseline_detector: BaselineDetector,
    pub html_injection_scanner: HtmlInjectionScanner,
    pub rate_limiting_scanner: RateLimitingScanner,
    pub wordpress_security_scanner: WordPressSecurityScanner,
    pub drupal_security_scanner: DrupalSecurityScanner,
    pub laravel_security_scanner: LaravelSecurityScanner,
    pub express_security_scanner: ExpressSecurityScanner,
    pub nextjs_security_scanner: NextJsSecurityScanner,
    pub sveltekit_security_scanner: SvelteKitSecurityScanner,
    pub react_security_scanner: ReactSecurityScanner,
    pub django_security_scanner: DjangoSecurityScanner,
    pub liferay_security_scanner: LiferaySecurityScanner,
    pub joomla_scanner: JoomlaScanner,
    pub rails_scanner: RailsScanner,
    pub spring_scanner: SpringScanner,
    pub fastapi_scanner: FastApiScanner,
    pub aspnet_scanner: AspNetScanner,
    pub go_frameworks_scanner: GoFrameworksScanner,
    pub prototype_pollution_scanner: PrototypePollutionScanner,
    pub host_header_injection_scanner: HostHeaderInjectionScanner,
    pub cognito_enum_scanner: CognitoEnumScanner,
    pub google_dorking_scanner: GoogleDorkingScanner,
    pub log4j_scanner: Log4jScanner,
    pub subdomain_enumerator: SubdomainEnumerator,
    pub compliance_scanner: ComplianceScanner,
    pub dora_scanner: DoraScanner,
    pub nis2_scanner: Nis2Scanner,
    pub postmessage_vulns_scanner: PostMessageVulnsScanner,
    pub dom_clobbering_scanner: DomClobberingScanner,
    pub second_order_injection_scanner: SecondOrderInjectionScanner,
    /// ML model scorer for vulnerability confidence scoring (one-way, no data uploaded)
    pub model_scorer: Option<crate::scorer::ModelScorer>,
    /// ML integration for automatic learning from scan results
    pub ml_integration: Option<crate::ml::MlIntegration>,
    /// Shared intelligence bus for cross-scanner communication
    pub intelligence_bus: Arc<IntelligenceBus>,
    /// Shared response analyzer for intelligent response analysis
    pub response_analyzer: Arc<ResponseAnalyzer>,
}

impl ScanEngine {
    pub fn new(config: ScannerConfig) -> Result<Self> {
        // Create HTTP client with optimizations
        let mut http_client = HttpClient::with_config(
            config.request_timeout_secs,
            config.max_retries,
            config.http2_enabled,
            config.http2_adaptive_window,
            config.http2_max_concurrent_streams,
            config.pool_max_idle_per_host,
        )?;

        // Log HTTP/2 status
        if config.http2_enabled {
            info!(
                "[SUCCESS] HTTP/2 enabled: streams={}, pool={}",
                config.http2_max_concurrent_streams, config.pool_max_idle_per_host
            );
        } else {
            info!("[WARNING]  HTTP/2 disabled");
        }

        // Add response caching if enabled
        if config.cache_enabled {
            http_client =
                http_client.with_cache(config.cache_max_capacity as u64, config.cache_ttl_secs);
            info!(
                "[SUCCESS] Response cache enabled: capacity={}, ttl={}s",
                config.cache_max_capacity, config.cache_ttl_secs
            );
        } else {
            info!("[WARNING]  Response cache disabled");
        }

        // Add rate limiter if enabled
        if config.rate_limit_enabled {
            let rate_limiter_config = RateLimiterConfig {
                default_rps: config.rate_limit_rps,
                min_rps: 10,
                max_rps: config.rate_limit_rps * 10,
                backoff_multiplier: 0.5,
                recovery_multiplier: 1.1,
                adaptive: config.rate_limit_adaptive,
            };

            let rate_limiter = Arc::new(AdaptiveRateLimiter::new(rate_limiter_config));
            http_client = http_client.with_rate_limiter(rate_limiter);

            info!(
                "[SUCCESS] Rate limiting enabled: {}rps, adaptive={}",
                config.rate_limit_rps, config.rate_limit_adaptive
            );
        } else {
            info!("[WARNING]  Rate limiting disabled");
        }

        let http_client = Arc::new(http_client);

        // Phase 3: Advanced Tuning
        let request_batcher = if config.request_batching_enabled {
            let batcher = Arc::new(crate::request_batcher::RequestBatcher::new(
                Arc::clone(&http_client),
                config.batch_size,
            ));
            info!(
                "[SUCCESS] Request batching enabled: batch_size={}",
                config.batch_size
            );
            Some(batcher)
        } else {
            info!("[WARNING]  Request batching disabled");
            None
        };

        let adaptive_concurrency = if config.adaptive_concurrency_enabled {
            let tracker = Arc::new(
                crate::adaptive_concurrency::AdaptiveConcurrencyTracker::new(
                    config.initial_concurrency,
                    config.max_concurrency_per_target,
                ),
            );
            info!(
                "[SUCCESS] Adaptive concurrency enabled: initial={}, max={}",
                config.initial_concurrency, config.max_concurrency_per_target
            );
            Some(tracker)
        } else {
            info!("[WARNING]  Adaptive concurrency disabled");
            None
        };

        let dns_cache = if config.dns_cache_enabled {
            let cache = Arc::new(crate::dns_cache::DnsCache::new());
            info!("[SUCCESS] DNS caching enabled");
            Some(cache)
        } else {
            info!("[WARNING]  DNS caching disabled");
            None
        };

        // Initialize intelligence bus and response analyzer for cross-scanner communication
        let intelligence_bus = Arc::new(IntelligenceBus::new());
        let response_analyzer = Arc::new(ResponseAnalyzer::new());

        Ok(Self {
            request_batcher,
            adaptive_concurrency,
            dns_cache,
            hybrid_xss_detector: HybridXssDetector::new(Arc::clone(&http_client)),
            proof_xss_scanner: ProofXssScanner::new(Arc::clone(&http_client)),
            reflection_xss_scanner: ReflectionXssScanner::new(Arc::clone(&http_client)),
            sqli_scanner: SqliScanner::new(Arc::clone(&http_client)),
            cmdi_scanner: CommandInjectionScanner::new(Arc::clone(&http_client)),
            path_scanner: PathTraversalScanner::new(Arc::clone(&http_client)),
            ssrf_scanner: SsrfScanner::new(Arc::clone(&http_client)),
            ssrf_blind_scanner: SsrfBlindScanner::new(Arc::clone(&http_client)),
            jwt_scanner: JwtScanner::new(Arc::clone(&http_client)),
            nosql_scanner: NoSqlScanner::new(Arc::clone(&http_client)),
            security_headers_scanner: SecurityHeadersScanner::new(Arc::clone(&http_client)),
            cors_scanner: CorsScanner::new(Arc::clone(&http_client)),
            firebase_scanner: FirebaseScanner::new(Arc::clone(&http_client)),
            csrf_scanner: CsrfScanner::new(Arc::clone(&http_client)),
            xxe_scanner: XxeScanner::new(Arc::clone(&http_client)),
            graphql_scanner: GraphQlScanner::new(Arc::clone(&http_client)),
            oauth_scanner: OAuthScanner::new(Arc::clone(&http_client)),
            oidc_scanner: OidcScanner::new(Arc::clone(&http_client)),
            saml_scanner: SamlScanner::new(Arc::clone(&http_client)),
            websocket_scanner: WebSocketScanner::new(Arc::clone(&http_client)),
            grpc_scanner: GrpcScanner::new(Arc::clone(&http_client)),
            auth_bypass_scanner: AuthBypassScanner::new(Arc::clone(&http_client)),
            session_management_scanner: SessionManagementScanner::new(Arc::clone(&http_client)),
            mfa_scanner: MfaScanner::new(Arc::clone(&http_client)),
            idor_scanner: IdorScanner::new(Arc::clone(&http_client)),
            bola_scanner: BolaScanner::new(Arc::clone(&http_client)),
            auth_manager_scanner: AuthManagerScanner::new(Arc::clone(&http_client)),
            advanced_auth_scanner: AdvancedAuthScanner::new(Arc::clone(&http_client)),
            ldap_injection_scanner: LdapInjectionScanner::new(Arc::clone(&http_client)),
            file_upload_scanner: FileUploadScanner::new(Arc::clone(&http_client)),
            open_redirect_scanner: Arc::new(OpenRedirectScanner::new(Arc::clone(&http_client))),
            clickjacking_scanner: ClickjackingScanner::new(Arc::clone(&http_client)),
            crlf_injection_scanner: CrlfInjectionScanner::new(Arc::clone(&http_client)),
            email_header_injection_scanner: EmailHeaderInjectionScanner::new(Arc::clone(
                &http_client,
            )),
            template_injection_scanner: TemplateInjectionScanner::new(Arc::clone(&http_client)),
            deserialization_scanner: DeserializationScanner::new(Arc::clone(&http_client)),
            source_map_scanner: SourceMapScanner::new(Arc::clone(&http_client)),
            favicon_hash_scanner: FaviconHashScanner::new(Arc::clone(&http_client)),
            api_security_scanner: APISecurityScanner::new(Arc::clone(&http_client)),
            http_smuggling_scanner: HTTPSmugglingScanner::new(Arc::clone(&http_client)),
            xml_injection_scanner: XMLInjectionScanner::new(Arc::clone(&http_client)),
            xpath_injection_scanner: XPathInjectionScanner::new(Arc::clone(&http_client)),
            code_injection_scanner: CodeInjectionScanner::new(Arc::clone(&http_client)),
            ssi_injection_scanner: SSIInjectionScanner::new(Arc::clone(&http_client)),
            race_condition_scanner: RaceConditionScanner::new(Arc::clone(&http_client)),
            readme_prompt_injection_scanner: ReadmePromptInjectionScanner::new(Arc::clone(&http_client)),
            mass_assignment_scanner: MassAssignmentScanner::new(Arc::clone(&http_client)),
            information_disclosure_scanner: InformationDisclosureScanner::new(Arc::clone(
                &http_client,
            )),
            cache_poisoning_scanner: CachePoisoningScanner::new(Arc::clone(&http_client)),
            business_logic_scanner: BusinessLogicScanner::new(Arc::clone(&http_client)),
            jwt_vulnerabilities_scanner: JwtVulnerabilitiesScanner::new(Arc::clone(&http_client)),
            graphql_security_scanner: GraphqlSecurityScanner::new(Arc::clone(&http_client)),
            nosql_injection_scanner: NosqlInjectionScanner::new(Arc::clone(&http_client)),
            file_upload_vulnerabilities_scanner: FileUploadVulnerabilitiesScanner::new(Arc::clone(
                &http_client,
            )),
            cors_misconfiguration_scanner: CorsMisconfigurationScanner::new(Arc::clone(
                &http_client,
            )),
            cloud_storage_scanner: CloudStorageScanner::new(Arc::clone(&http_client)),
            framework_vulnerabilities_scanner: FrameworkVulnerabilitiesScanner::new(Arc::clone(
                &http_client,
            )),
            js_miner_scanner: JsMinerScanner::new(Arc::clone(&http_client)),
            sensitive_data_scanner: SensitiveDataScanner::new(Arc::clone(&http_client)),
            api_fuzzer_scanner: ApiFuzzerScanner::new(Arc::clone(&http_client)),
            api_gateway_scanner: ApiGatewayScanner::new(Arc::clone(&http_client)),
            arcgis_rest_scanner: ArcGISRestScanner::new(Arc::clone(&http_client)),
            cloud_security_scanner: CloudSecurityScanner::new(Arc::clone(&http_client)),
            container_scanner: ContainerScanner::new(Arc::clone(&http_client)),
            webauthn_scanner: WebAuthnScanner::new(Arc::clone(&http_client)),
            http3_scanner: Http3Scanner::new(Arc::clone(&http_client)),
            ssti_advanced_scanner: SstiAdvancedScanner::new(Arc::clone(&http_client)),
            cve_2025_55182_scanner: Cve202555182Scanner::new(Arc::clone(&http_client)),
            cve_2025_55183_scanner: Cve202555183Scanner::new(Arc::clone(&http_client)),
            cve_2025_55184_scanner: Cve202555184Scanner::new(Arc::clone(&http_client)),
            azure_apim_scanner: AzureApimScanner::new(Arc::clone(&http_client)),
            redos_scanner: RedosScanner::new(Arc::clone(&http_client)),
            hpp_scanner: HttpParameterPollutionScanner::new(Arc::clone(&http_client)),
            waf_bypass_scanner: WafBypassScanner::new(Arc::clone(&http_client)),
            merlin_scanner: MerlinScanner::new(Arc::clone(&http_client)),
            tomcat_misconfig_scanner: TomcatMisconfigScanner::new(Arc::clone(&http_client)),
            varnish_misconfig_scanner: VarnishMisconfigScanner::new(Arc::clone(&http_client)),
            js_sensitive_info_scanner: JsSensitiveInfoScanner::new(Arc::clone(&http_client)),
            client_route_auth_bypass_scanner: ClientRouteAuthBypassScanner::new(Arc::clone(
                &http_client,
            )),
            baseline_detector: BaselineDetector::new(Arc::clone(&http_client)),
            html_injection_scanner: HtmlInjectionScanner::new(Arc::clone(&http_client)),
            rate_limiting_scanner: RateLimitingScanner::new(Arc::clone(&http_client)),
            wordpress_security_scanner: WordPressSecurityScanner::new(Arc::clone(&http_client)),
            drupal_security_scanner: DrupalSecurityScanner::new(Arc::clone(&http_client)),
            laravel_security_scanner: LaravelSecurityScanner::new(Arc::clone(&http_client)),
            express_security_scanner: ExpressSecurityScanner::new(Arc::clone(&http_client)),
            nextjs_security_scanner: NextJsSecurityScanner::new(Arc::clone(&http_client)),
            sveltekit_security_scanner: SvelteKitSecurityScanner::new(Arc::clone(&http_client)),
            react_security_scanner: ReactSecurityScanner::new(Arc::clone(&http_client)),
            django_security_scanner: DjangoSecurityScanner::new(Arc::clone(&http_client)),
            liferay_security_scanner: LiferaySecurityScanner::new(Arc::clone(&http_client)),
            joomla_scanner: JoomlaScanner::new(Arc::clone(&http_client)),
            rails_scanner: RailsScanner::new(Arc::clone(&http_client)),
            spring_scanner: SpringScanner::new(Arc::clone(&http_client)),
            fastapi_scanner: FastApiScanner::new(Arc::clone(&http_client)),
            aspnet_scanner: AspNetScanner::new(Arc::clone(&http_client)),
            go_frameworks_scanner: GoFrameworksScanner::new(Arc::clone(&http_client)),
            prototype_pollution_scanner: PrototypePollutionScanner::new(Arc::clone(&http_client)),
            host_header_injection_scanner: HostHeaderInjectionScanner::new(Arc::clone(
                &http_client,
            )),
            cognito_enum_scanner: CognitoEnumScanner::new(Arc::clone(&http_client)),
            google_dorking_scanner: GoogleDorkingScanner::new(),
            log4j_scanner: Log4jScanner::new(Arc::clone(&http_client)),
            subdomain_enumerator: SubdomainEnumerator::new(Arc::clone(&http_client)),
            compliance_scanner: ComplianceScanner::new(Arc::clone(&http_client)),
            dora_scanner: DoraScanner::new(Arc::clone(&http_client)),
            nis2_scanner: Nis2Scanner::new(Arc::clone(&http_client)),
            postmessage_vulns_scanner: PostMessageVulnsScanner::new(Arc::clone(&http_client)),
            dom_clobbering_scanner: DomClobberingScanner::new(Arc::clone(&http_client)),
            second_order_injection_scanner: SecondOrderInjectionScanner::new(Arc::clone(&http_client)),
            // Load ML model at scan start (one-way: model downloaded, no data uploaded)
            model_scorer: match crate::ml::FederatedClient::load_cached_model() {
                Ok(model) => {
                    info!(
                        "[ML] Model loaded: {} (v{})",
                        model.weights.model_id, model.weights.version
                    );
                    Some(crate::scorer::ModelScorer::from_model(&model))
                }
                Err(e) => {
                    debug!("No ML model available, scanning without model scoring: {}", e);
                    None
                }
            },
            // Initialize ML integration (fails gracefully if ~/.lonkero not writable)
            ml_integration: crate::ml::MlIntegration::new().ok(),
            intelligence_bus,
            response_analyzer,
            http_client,
            config,
        })
    }

    /// Get the shared intelligence bus for cross-scanner communication
    pub fn intelligence_bus(&self) -> Arc<IntelligenceBus> {
        Arc::clone(&self.intelligence_bus)
    }

    /// Get the shared response analyzer for intelligent response analysis
    pub fn response_analyzer(&self) -> Arc<ResponseAnalyzer> {
        Arc::clone(&self.response_analyzer)
    }

    /// Execute a complete scan job
    ///
    /// IMPORTANT: This function requires prior authorization via `crate::signing::authorize_scan()`.
    /// Unauthorized scans will be rejected to prevent bypass of ban enforcement.
    pub async fn execute_scan(
        &self,
        job: Arc<ScanJob>,
        queue: Arc<RedisQueue>,
    ) -> Result<ScanResults> {
        let start_time = Instant::now();
        let started_at = chrono::Utc::now().to_rfc3339();

        // ============================================================
        // MANDATORY AUTHORIZATION CHECK - CANNOT BE BYPASSED
        // ============================================================
        // This check ensures banned users cannot scan. The authorization
        // must be obtained BEFORE this function is called.
        if !crate::signing::is_scan_authorized() {
            return Err(anyhow::anyhow!(
                "SCAN BLOCKED: Authorization required. Call signing::authorize_scan() before scanning. \
                This ensures banned users cannot access the scanner."
            ));
        }

        // Get the scan token for later signing
        let scan_token = crate::signing::get_scan_token()
            .ok_or_else(|| anyhow::anyhow!("No valid scan token. Re-authorize to continue."))?
            .clone();

        // Track which modules are actually used (for server validation during signing)
        let mut modules_used: Vec<String> = Vec::new();

        // Runtime state verification (anti-tampering)
        if !crate::license::verify_rt_state() {
            return Err(anyhow::anyhow!(
                "Scanner integrity check failed. Please reinstall or contact info@bountyy.fi"
            ));
        }

        // Increment scan counter for tracking
        crate::license::increment_scan_counter();

        // Clone job fields to owned types to fix Send lifetime issues
        let scan_id = job.scan_id.clone();
        let target = job.target.clone();
        let config = job.config.clone();

        info!("Starting scan for target: {}", target);

        let mut all_vulnerabilities: Vec<Vulnerability> = Vec::new();
        let mut total_tests: u64 = 0;

        // ============================================================
        // PARKED SITE DETECTION - Early termination for false positive prevention
        // ============================================================
        // Parked/placeholder domains (GoDaddy, Sedo, Bodis, etc.) respond
        // generically to all requests, causing massive false positives across
        // every scanner module. Detect them early and skip scanning entirely.
        info!("[Baseline] Checking for parked/placeholder site");
        let parked_check = match self.http_client.get(&target).await {
            Ok(response) => {
                let result = BaselineDetector::detect_parked_site(&response);
                result
            }
            Err(_) => (false, None),
        };

        if parked_check.0 {
            let service_name = parked_check.1.as_deref().unwrap_or("Unknown");
            warn!(
                "PARKED SITE DETECTED: {} is a parked/placeholder domain (service: {}). \
                Skipping vulnerability scan to prevent false positives.",
                target, service_name
            );

            // Create an informational finding explaining why the scan was skipped
            let info_vuln = Vulnerability {
                id: uuid::Uuid::new_v4().to_string(),
                vuln_type: "Parked Domain Detected".to_string(),
                severity: Severity::Info,
                confidence: Confidence::High,
                category: "Information".to_string(),
                url: target.clone(),
                parameter: None,
                payload: String::new(),
                description: format!(
                    "The target {} is a parked/placeholder domain hosted by {}. \
                    Parked domains respond generically to all requests and produce \
                    false positive vulnerability findings. The scan was terminated \
                    early to prevent false positive results.",
                    target, service_name
                ),
                evidence: Some(format!("Parking service detected: {}", service_name)),
                cwe: "CWE-0".to_string(),
                cvss: 0.0,
                verified: true,
                false_positive: false,
                remediation: "If this domain should host a real application, configure \
                    proper web hosting. Otherwise, no action needed."
                    .to_string(),
                discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
            };

            let elapsed = start_time.elapsed();
            let license_sig = crate::license::get_license_signature();

            let mut results = ScanResults {
                scan_id: scan_id.clone(),
                target: target.clone(),
                tests_run: 1,
                vulnerabilities: vec![info_vuln],
                started_at,
                completed_at: chrono::Utc::now().to_rfc3339(),
                duration_seconds: elapsed.as_secs_f64(),
                early_terminated: true,
                termination_reason: Some(format!(
                    "Parked domain detected ({})",
                    service_name
                )),
                scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
                license_signature: Some(license_sig),
                quantum_signature: None,
                authorization_token_id: Some(scan_token.token.clone()),
            };

            // Sign the early-terminated results (same flow as normal results)
            let results_hash = crate::signing::hash_results(&results)
                .map_err(|e| anyhow::anyhow!("Failed to hash results: {}", e))?;
            let findings_summary =
                crate::signing::FindingsSummary::from_vulnerabilities(&results.vulnerabilities);

            match crate::signing::sign_results(
                &results_hash,
                &scan_token,
                vec!["baseline_detector".to_string()],
                Some(crate::signing::ScanMetadata {
                    targets_count: Some(1),
                    scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
                    scan_duration_ms: Some(elapsed.as_millis() as u64),
                }),
                Some(findings_summary),
                Some(vec![job.target.clone()]),
            )
            .await
            {
                Ok(signature) => {
                    info!(
                        "[SIGNED] Parked site results signed: {}",
                        signature.algorithm
                    );
                    results.quantum_signature = Some(signature);
                }
                Err(crate::signing::SigningError::ServerUnreachable(msg)) => {
                    error!("Failed to sign results - server unreachable: {}", msg);
                    return Err(anyhow::anyhow!("Signing server unreachable: {}", msg));
                }
                Err(e) => {
                    error!("Failed to sign results: {}", e);
                    return Err(anyhow::anyhow!("Failed to sign results: {}", e));
                }
            }

            return Ok(results);
        }

        // Phase 0: Crawl & Reconnaissance
        info!("[Phase 0] Starting reconnaissance crawl");
        let crawler = WebCrawler::new(Arc::clone(&self.http_client), 3, 50);
        let mut crawl_results = crawler.crawl(&target).await.unwrap_or_else(|e| {
            warn!("Crawler failed: {}, using fallback discovery", e);
            CrawlResults::new()
        });

        // JavaScript Mining for SPA attack surface discovery
        info!("[Phase 0] Mining JavaScript for API endpoints and parameters");
        let js_miner_results = self.js_miner_scanner.scan_full(&target, &config).await?;

        // Merge JS miner findings into crawl_results
        if !js_miner_results.api_endpoints.is_empty() || !js_miner_results.parameters.is_empty() {
            info!(
                "[JS-Miner] Discovered {} API endpoints, {} parameter sets from JavaScript",
                js_miner_results.api_endpoints.len(),
                js_miner_results.parameters.len()
            );

            // Add API endpoints
            crawl_results
                .api_endpoints
                .extend(js_miner_results.api_endpoints.clone());

            // Add form actions
            for action in js_miner_results.form_actions {
                crawl_results.api_endpoints.insert(action);
            }

            // Add parameters - merge into crawl_results.parameters
            for (endpoint, params) in js_miner_results.parameters {
                crawl_results
                    .parameters
                    .entry(endpoint)
                    .or_insert_with(std::collections::HashSet::new)
                    .extend(params);
            }

            // Add GraphQL endpoints for later testing
            for gql_endpoint in &js_miner_results.graphql_endpoints {
                crawl_results.api_endpoints.insert(gql_endpoint.clone());
            }
        }

        // Store JS miner vulnerabilities (will be added later with other findings)
        let js_miner_vulns = js_miner_results.vulnerabilities;
        let js_miner_tests = js_miner_results.tests_run;

        // Framework & Technology Detection
        info!("[Tech] Detecting frameworks and technologies");
        let detector = FrameworkDetector::new(Arc::clone(&self.http_client));
        let detected_tech = detector.detect(&target).await.unwrap_or_else(|e| {
            warn!("Framework detection failed: {}", e);
            HashSet::new()
        });

        info!("[SUCCESS] Detected technologies:");
        for tech in &detected_tech {
            info!(
                "   - {} ({:?}) [confidence: {:?}]",
                tech.name, tech.category, tech.confidence
            );
        }

        // ============================================================
        // v3.0 INTELLIGENT SCAN ORCHESTRATION
        // ============================================================
        // Convert detected technologies to TechCategory for intelligent routing
        let tech_categories: Vec<TechCategory> = detected_tech
            .iter()
            .map(|t| TechCategory::from_detected_technology(&t.name, &format!("{:?}", t.category)))
            .collect();

        // Generate intelligent scan plan (replaces legacy mode-based approach)
        let orchestrator = IntelligentScanOrchestrator::new();
        let scan_plan = orchestrator.generate_scan_plan(&crawl_results, &tech_categories, &target);

        // Log orchestration statistics
        info!("[Orchestrator] v3.0 Intelligent Scan Plan:");
        info!(
            "   - Targets: {}/{} ({:.1}% reduction via deduplication)",
            scan_plan.stats.total_deduplicated,
            scan_plan.stats.total_original,
            scan_plan.stats.reduction_percent
        );
        info!(
            "   - Scanners selected: {} (based on {} technologies)",
            scan_plan.stats.scanners_selected,
            scan_plan.stats.technologies_detected.len()
        );
        info!(
            "   - Parameter risk: {} high, {} medium, {} low",
            scan_plan.stats.high_risk_params,
            scan_plan.stats.medium_risk_params,
            scan_plan.stats.low_risk_params
        );

        if !scan_plan.stats.technologies_detected.is_empty() {
            info!(
                "[Orchestrator] Tech-specific routing: {:?}",
                scan_plan.stats.technologies_detected
            );
            info!(
                "[Orchestrator] Active scanners for this target: {:?}",
                scan_plan
                    .scanners
                    .iter()
                    .map(|s| s.display_name())
                    .collect::<Vec<_>>()
            );
        } else {
            info!("[Orchestrator] No specific tech detected - using fallback scanner set");
        }

        // Subdomain enumeration (if enabled via config or scan config)
        let mut discovered_subdomains = Vec::new();
        if self.config.subdomain_enum_enabled || config.enum_subdomains {
            info!("[Subdomain] Starting subdomain enumeration");

            // Extract domain from target URL
            if let Ok(parsed_url) = url::Url::parse(&target) {
                if let Some(domain_str) = parsed_url.host_str() {
                    // Convert to owned String to avoid lifetime issues
                    let domain = domain_str.to_string();
                    let thorough = self.config.subdomain_enum_thorough
                        || config.scan_mode == ScanMode::Thorough
                        || config.scan_mode == ScanMode::Insane;

                    match self.subdomain_enumerator.enumerate(&domain, thorough).await {
                        Ok(subdomains) => {
                            info!("[SUCCESS] Found {} subdomains", subdomains.len());

                            // Generate findings for discovered subdomains
                            let subdomain_findings = self
                                .subdomain_enumerator
                                .generate_findings(&subdomains, &domain);
                            all_vulnerabilities.extend(subdomain_findings);

                            // Collect accessible subdomain URLs for further scanning
                            for (subdomain, _info) in &subdomains {
                                // Verify HTTP/HTTPS access
                                if let Some(accessible_url) = self
                                    .subdomain_enumerator
                                    .verify_http_access(subdomain)
                                    .await
                                {
                                    discovered_subdomains.push(accessible_url);
                                }
                            }

                            info!(
                                "[SUCCESS] {} subdomains are accessible via HTTP/HTTPS",
                                discovered_subdomains.len()
                            );
                        }
                        Err(e) => {
                            warn!("Subdomain enumeration failed: {}", e);
                        }
                    }
                }
            }
        } else {
            info!("[WARNING]  Subdomain enumeration disabled (set SUBDOMAIN_ENUM_ENABLED=true to enable)");
        }

        // Phase 2 Optimization: CDN Detection
        let cdn_info = if self.config.cdn_detection_enabled {
            self.detect_cdn(&target).await?
        } else {
            None
        };

        // Parse target URL to extract parameters
        let url_data = self.parse_target_url(&target)?;

        // ============================================================
        // v3.0 INTELLIGENT PARAMETER TESTING
        // ============================================================
        // Use prioritized parameters from the intelligent scan plan.
        // Each parameter has a risk score and payload intensity.
        // High-risk parameters get more payloads, low-risk get fewer.

        // Build test_parameters from scan plan (prioritized by risk score)
        let mut test_parameters: Vec<(String, String)> = Vec::new();

        if !scan_plan.prioritized_params.is_empty() {
            info!(
                "[Intelligent] Using {} prioritized parameters from scan plan",
                scan_plan.prioritized_params.len()
            );

            // Log top high-risk parameters
            for param in scan_plan.prioritized_params.iter().take(5) {
                if param.risk_score > 50 {
                    info!(
                        "   - {} (risk: {}, intensity: {:?})",
                        param.name, param.risk_score, param.intensity
                    );
                }
            }

            for param in &scan_plan.prioritized_params {
                test_parameters.push((param.name.clone(), "test".to_string()));
            }
        } else {
            // Fallback: use URL parameters if scan plan has none
            if !url_data.parameters.is_empty() {
                info!(
                    "[TARGET] Using {} parameters from URL",
                    url_data.parameters.len()
                );
                test_parameters.extend(url_data.parameters.clone());
            }

            // Ultimate fallback to common parameter names
            if test_parameters.is_empty() {
                info!("[WARNING] No parameters discovered - testing common parameter names");
                test_parameters = vec![
                    ("id".to_string(), "1".to_string()),
                    ("q".to_string(), "test".to_string()),
                    ("search".to_string(), "test".to_string()),
                    ("query".to_string(), "test".to_string()),
                    ("page".to_string(), "1".to_string()),
                    ("user".to_string(), "test".to_string()),
                    ("name".to_string(), "test".to_string()),
                    ("msg".to_string(), "test".to_string()),
                    ("message".to_string(), "test".to_string()),
                    ("text".to_string(), "test".to_string()),
                    ("content".to_string(), "test".to_string()),
                    ("comment".to_string(), "test".to_string()),
                    ("title".to_string(), "test".to_string()),
                    ("input".to_string(), "test".to_string()),
                    ("url".to_string(), "http://example.com".to_string()),
                    ("redirect".to_string(), "http://example.com".to_string()),
                    ("callback".to_string(), "test".to_string()),
                    ("from".to_string(), "test".to_string()),
                    ("username".to_string(), "test".to_string()),
                    ("email".to_string(), "test@test.com".to_string()),
                    ("file".to_string(), "test.txt".to_string()),
                    ("code".to_string(), "test".to_string()),
                    ("label".to_string(), "test".to_string()),
                    ("header".to_string(), "test".to_string()),
                ];
            }
        }

        // Phase 1: Test URL parameters (or common parameter names if none exist)
        if !test_parameters.is_empty() {
            // Filter out irrelevant parameters (JS framework internals, etc.)
            let original_count = test_parameters.len();
            test_parameters.retain(|(name, _)| Self::is_relevant_parameter(name));
            let filtered_count = original_count - test_parameters.len();
            if filtered_count > 0 {
                info!(
                    "[FILTER] Skipped {} irrelevant parameters (framework internals)",
                    filtered_count
                );
            }

            info!(
                "Testing {} parameters for injection vulnerabilities",
                test_parameters.len()
            );

            for (param_name, _param_value) in &test_parameters {
                // Early termination check
                if self.should_terminate_early(&all_vulnerabilities) {
                    break;
                }

                // SQLi Testing (Professional+, skip if CDN protected)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::SQLI_SCANNER)
                    && !self.should_skip_scanner("sqli", &cdn_info)
                {
                    let (sqli_vulns, sqli_tests) = self
                        .sqli_scanner
                        .scan_parameter(&target, param_name, &config, None)
                        .await?;
                    all_vulnerabilities.extend(sqli_vulns);
                    total_tests += sqli_tests as u64;
                    queue
                        .increment_tests(scan_id.clone(), sqli_tests as u64)
                        .await?;
                }

                // Command Injection Testing (Professional+, skip if CDN protected, intelligent routing)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::COMMAND_INJECTION)
                    && !self.should_skip_scanner("command_injection", &cdn_info)
                    && Self::should_run_scanner_for_param(
                        TechScannerType::CommandInjection,
                        param_name,
                        &scan_plan,
                    )
                {
                    // INTELLIGENT MODE: Get payload intensity for this specific parameter
                    let intensity = Self::get_param_intensity(param_name, &scan_plan);
                    let (cmdi_vulns, cmdi_tests) = self
                        .cmdi_scanner
                        .scan_parameter_with_intensity(&target, param_name, &config, intensity)
                        .await?;
                    all_vulnerabilities.extend(cmdi_vulns);
                    total_tests += cmdi_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), cmdi_tests as u64)
                        .await?;
                }

                // Path Traversal Testing (Professional+, skip if CDN protected, intelligent routing)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::PATH_TRAVERSAL)
                    && !self.should_skip_scanner("path_traversal", &cdn_info)
                    && Self::should_run_scanner_for_param(
                        TechScannerType::PathTraversal,
                        param_name,
                        &scan_plan,
                    )
                {
                    // INTELLIGENT MODE: Get payload intensity for this specific parameter
                    let intensity = Self::get_param_intensity(param_name, &scan_plan);
                    let (path_vulns, path_tests) = self
                        .path_scanner
                        .scan_parameter_with_intensity(&target, param_name, &config, intensity)
                        .await?;
                    all_vulnerabilities.extend(path_vulns);
                    total_tests += path_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), path_tests as u64)
                        .await?;
                }

                // SSRF Testing (Professional+)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::SSRF_SCANNER)
                {
                    let (ssrf_vulns, ssrf_tests) = self
                        .ssrf_scanner
                        .scan_parameter(&target, param_name, &config)
                        .await?;
                    all_vulnerabilities.extend(ssrf_vulns);
                    total_tests += ssrf_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), ssrf_tests as u64)
                        .await?;
                }

                // Blind SSRF with OOB Callback Testing (Professional+)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::SSRF_BLIND)
                {
                    let (ssrf_blind_vulns, ssrf_blind_tests) = self
                        .ssrf_blind_scanner
                        .scan_parameter(&target, param_name, &config)
                        .await?;
                    all_vulnerabilities.extend(ssrf_blind_vulns);
                    total_tests += ssrf_blind_tests as u64;
                    queue
                        .increment_tests(scan_id.clone(), ssrf_blind_tests as u64)
                        .await?;
                }

                // NoSQL Injection Testing (Professional+, skip if CDN protected, intelligent routing)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::NOSQL_SCANNER)
                    && !self.should_skip_scanner("nosql", &cdn_info)
                    && Self::should_run_scanner_for_param(
                        TechScannerType::NoSqlI,
                        param_name,
                        &scan_plan,
                    )
                {
                    // INTELLIGENT MODE: Get payload intensity for this specific parameter
                    let intensity = Self::get_param_intensity(param_name, &scan_plan);
                    let (nosql_vulns, nosql_tests) = self
                        .nosql_scanner
                        .scan_parameter_with_intensity(&target, param_name, &config, intensity)
                        .await?;
                    all_vulnerabilities.extend(nosql_vulns);
                    total_tests += nosql_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), nosql_tests as u64)
                        .await?;
                }

                // XXE Testing (Professional+, skip if CDN protected, intelligent routing)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::XXE_SCANNER)
                    && !self.should_skip_scanner("xxe", &cdn_info)
                    && Self::should_run_scanner_for_param(
                        TechScannerType::Xxe,
                        param_name,
                        &scan_plan,
                    )
                {
                    // INTELLIGENT MODE: Get payload intensity for this specific parameter
                    let intensity = Self::get_param_intensity(param_name, &scan_plan);
                    let (xxe_vulns, xxe_tests) = self
                        .xxe_scanner
                        .scan_parameter_with_intensity(&target, param_name, &config, intensity)
                        .await?;
                    all_vulnerabilities.extend(xxe_vulns);
                    total_tests += xxe_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), xxe_tests as u64)
                        .await?;
                }

                // ReDoS Testing (Professional+, intelligent routing)
                if scan_token
                    .is_module_authorized(crate::modules::ids::advanced_scanning::REDOS_SCANNER)
                    && Self::should_run_scanner_for_param(
                        TechScannerType::ReDoS,
                        param_name,
                        &scan_plan,
                    )
                {
                    // INTELLIGENT MODE: Get payload intensity for this specific parameter
                    let intensity = Self::get_param_intensity(param_name, &scan_plan);
                    let (redos_vulns, redos_tests) = self
                        .redos_scanner
                        .scan_parameter_with_intensity(&target, param_name, &config, intensity)
                        .await?;
                    all_vulnerabilities.extend(redos_vulns);
                    total_tests += redos_tests as u64;

                    queue
                        .increment_tests(scan_id.clone(), redos_tests as u64)
                        .await?;
                }
            }
        }

        // Proof-Based XSS Detection (runs on target + all crawled URLs)
        // Uses mathematical proof of exploitability - no browser required
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::XSS_SCANNER)
            && !self.should_terminate_early(&all_vulnerabilities)
        {
            // Collect all URLs to test: target + crawled URLs (deduplicated)
            let mut xss_urls_to_test: Vec<String> = vec![target.clone()];
            for crawled_url in &crawl_results.crawled_urls {
                if crawled_url != &target && !xss_urls_to_test.contains(crawled_url) {
                    xss_urls_to_test.push(crawled_url.clone());
                }
            }

            info!(
                "[Proof-XSS] Running proof-based XSS detection on {} URLs (no browser)",
                xss_urls_to_test.len()
            );

            for (idx, xss_url) in xss_urls_to_test.iter().enumerate() {
                if self.should_terminate_early(&all_vulnerabilities) {
                    break;
                }

                info!(
                    "[Proof-XSS] Testing URL {}/{}: {}",
                    idx + 1,
                    xss_urls_to_test.len(),
                    xss_url
                );
                let (proof_xss_vulns, proof_xss_tests) = self
                    .proof_xss_scanner
                    .scan(xss_url, &config)
                    .await?;
                all_vulnerabilities.extend(proof_xss_vulns);
                total_tests += proof_xss_tests as u64;
                queue
                    .increment_tests(scan_id.clone(), proof_xss_tests as u64)
                    .await?;
            }

            modules_used.push(crate::modules::ids::advanced_scanning::XSS_SCANNER.to_string());
        }

        // Phase 1b: Test discovered API endpoints from JavaScript
        let api_endpoints: Vec<String> = crawl_results.api_endpoints.iter().cloned().collect();
        if !api_endpoints.is_empty() {
            info!(
                "[Phase 1b] Testing {} API endpoints discovered from JavaScript",
                api_endpoints.len()
            );

            // Get parameters to test on endpoints (from JS discovery, filtered)
            let js_params: Vec<String> = crawl_results
                .parameters
                .get("*")
                .map(|p| {
                    p.iter()
                        .filter(|name| Self::is_relevant_parameter(name))
                        .cloned()
                        .collect()
                })
                .unwrap_or_default();

            // Test up to 10 API endpoints with discovered parameters
            for endpoint in api_endpoints.iter().take(10) {
                // Skip GraphQL endpoints (handled separately by GraphQL scanner)
                if endpoint.to_lowercase().contains("graphql") {
                    continue;
                }

                // Build full URL if endpoint is relative
                let full_url = if endpoint.starts_with("http") {
                    endpoint.clone()
                } else if let Ok(base) = url::Url::parse(&target) {
                    base.join(endpoint)
                        .map(|u| u.to_string())
                        .unwrap_or_else(|_| format!("{}{}", target.trim_end_matches('/'), endpoint))
                } else {
                    format!("{}{}", target.trim_end_matches('/'), endpoint)
                };

                info!("[API-Test] Testing endpoint: {}", full_url);

                // Test with JS-discovered parameters (limit to 10)
                for param in js_params.iter().take(10) {
                    if self.should_terminate_early(&all_vulnerabilities) {
                        break;
                    }

                    // SQLi on API endpoint (Professional+)
                    if scan_token
                        .is_module_authorized(crate::modules::ids::advanced_scanning::SQLI_SCANNER)
                        && !self.should_skip_scanner("sqli", &cdn_info)
                    {
                        let (sqli_vulns, sqli_tests) = self
                            .sqli_scanner
                            .scan_parameter(&full_url, param, &config, None)
                            .await?;
                        all_vulnerabilities.extend(sqli_vulns);
                        total_tests += sqli_tests as u64;
                        queue
                            .increment_tests(scan_id.clone(), sqli_tests as u64)
                            .await?;
                    }
                }
            }
        }

        // Early termination check after parameter scanning
        if self.should_terminate_early(&all_vulnerabilities) {
            let critical_count = all_vulnerabilities
                .iter()
                .filter(|v| v.severity == Severity::Critical)
                .count();

            warn!(
                "[STOP]  Scan terminated early: {} critical vulnerabilities found",
                critical_count
            );
            warn!("[WARNING]  INCOMPLETE SCAN: Some vulnerabilities may have been missed!");

            let elapsed = start_time.elapsed();
            let license_sig = crate::license::get_license_signature();

            let mut results = ScanResults {
                scan_id: scan_id.clone(),
                target: target.clone(),
                tests_run: total_tests,
                vulnerabilities: all_vulnerabilities,
                started_at,
                completed_at: chrono::Utc::now().to_rfc3339(),
                duration_seconds: elapsed.as_secs_f64(),
                early_terminated: true,
                termination_reason: Some(format!(
                    "Scan stopped early after finding {} critical vulnerabilities. Enable comprehensive scanning for full results.",
                    critical_count
                )),
                scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
                license_signature: Some(license_sig),
                quantum_signature: None,
                authorization_token_id: Some(scan_token.token.clone()),
            };

            // Sign even early-terminated results
            // STRICT MODE: Server signature required
            // Note: modules_used is empty for early termination
            if let Ok(results_hash) = crate::signing::hash_results(&results) {
                // Collect privacy-safe findings summary (only counts, no URLs or details)
                let findings_summary =
                    crate::signing::FindingsSummary::from_vulnerabilities(&results.vulnerabilities);

                match crate::signing::sign_results(
                    &results_hash,
                    &scan_token,
                    vec![], // No modules used in early termination
                    Some(crate::signing::ScanMetadata {
                        targets_count: Some(1),
                        scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
                        scan_duration_ms: Some(elapsed.as_millis() as u64),
                    }),
                    Some(findings_summary),
                    Some(vec![job.target.clone()]),
                )
                .await
                {
                    Ok(signature) => {
                        results.quantum_signature = Some(signature);
                    }
                    Err(e) => {
                        // STRICT MODE: Signing failure is fatal
                        return Err(anyhow::anyhow!(
                            "Failed to sign early-terminated results: {}",
                            e
                        ));
                    }
                }
            }

            return Ok(results);
        }

        // Security Headers Check (Free tier)
        info!("Checking security headers");
        modules_used.push(crate::modules::ids::free::SECURITY_HEADERS.to_string());
        let (header_vulns, header_tests) =
            self.security_headers_scanner.scan(&target, &config).await?;
        all_vulnerabilities.extend(header_vulns);
        total_tests += header_tests as u64;
        queue
            .increment_tests(scan_id.clone(), header_tests as u64)
            .await?;

        // CORS Configuration Check (Free tier)
        info!("Checking CORS configuration");
        modules_used.push(crate::modules::ids::free::CORS_BASIC.to_string());
        let (cors_vulns, cors_tests) = self.cors_scanner.scan(&target, &config).await?;
        all_vulnerabilities.extend(cors_vulns);
        total_tests += cors_tests as u64;
        queue
            .increment_tests(scan_id.clone(), cors_tests as u64)
            .await?;

        // CSRF Protection Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::CSRF_SCANNER) {
            info!("Checking CSRF protection");
            modules_used.push(crate::modules::ids::advanced_scanning::CSRF_SCANNER.to_string());
            let (csrf_vulns, csrf_tests) = self.csrf_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(csrf_vulns);
            total_tests += csrf_tests as u64;
            queue
                .increment_tests(scan_id.clone(), csrf_tests as u64)
                .await?;
        }

        // GraphQL API Security Check (Professional+, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::GRAPHQL_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::GraphQL, &scan_plan)
        {
            info!("Checking GraphQL API security");
            modules_used.push(crate::modules::ids::advanced_scanning::GRAPHQL_SCANNER.to_string());
            let (graphql_vulns, graphql_tests) =
                self.graphql_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(graphql_vulns);
            total_tests += graphql_tests as u64;
            queue
                .increment_tests(scan_id.clone(), graphql_tests as u64)
                .await?;
        }

        // OAuth 2.0 Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::OAUTH_SCANNER) {
            info!("Checking OAuth 2.0 security");
            modules_used.push(crate::modules::ids::advanced_scanning::OAUTH_SCANNER.to_string());
            let (oauth_vulns, oauth_tests) = self.oauth_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(oauth_vulns);
            total_tests += oauth_tests as u64;
            queue
                .increment_tests(scan_id.clone(), oauth_tests as u64)
                .await?;
        }

        // SAML Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::SAML_SCANNER) {
            info!("Checking SAML security");
            modules_used.push(crate::modules::ids::advanced_scanning::SAML_SCANNER.to_string());
            let (saml_vulns, saml_tests) = self.saml_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(saml_vulns);
            total_tests += saml_tests as u64;
            queue
                .increment_tests(scan_id.clone(), saml_tests as u64)
                .await?;
        }

        // WebSocket Security Check (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::WEBSOCKET_SCANNER)
        {
            info!("Checking WebSocket security");
            modules_used
                .push(crate::modules::ids::advanced_scanning::WEBSOCKET_SCANNER.to_string());
            let (websocket_vulns, websocket_tests) =
                self.websocket_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(websocket_vulns);
            total_tests += websocket_tests as u64;
            queue
                .increment_tests(scan_id.clone(), websocket_tests as u64)
                .await?;
        }

        // gRPC Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::GRPC_SCANNER) {
            info!("Checking gRPC security");
            modules_used.push(crate::modules::ids::advanced_scanning::GRPC_SCANNER.to_string());
            let (grpc_vulns, grpc_tests) = self.grpc_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(grpc_vulns);
            total_tests += grpc_tests as u64;
            queue
                .increment_tests(scan_id.clone(), grpc_tests as u64)
                .await?;
        }

        // Authentication Bypass Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::AUTH_BYPASS) {
            info!("Checking authentication bypass");
            modules_used.push(crate::modules::ids::advanced_scanning::AUTH_BYPASS.to_string());
            let (auth_bypass_vulns, auth_bypass_tests) =
                self.auth_bypass_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(auth_bypass_vulns);
            total_tests += auth_bypass_tests as u64;
            queue
                .increment_tests(scan_id.clone(), auth_bypass_tests as u64)
                .await?;
        }

        // Client Route Authorization Bypass Check (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::CLIENT_ROUTE_AUTH_BYPASS)
        {
            info!("[ClientRouteAuth] Testing client-side route authorization bypass");
            modules_used
                .push(crate::modules::ids::advanced_scanning::CLIENT_ROUTE_AUTH_BYPASS.to_string());
            let (client_route_vulns, client_route_tests) = self
                .client_route_auth_bypass_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(client_route_vulns);
            total_tests += client_route_tests as u64;
            queue
                .increment_tests(scan_id.clone(), client_route_tests as u64)
                .await?;
        }

        // Session Management Security Check (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::SESSION_MANAGEMENT)
        {
            info!("Checking session management security");
            modules_used
                .push(crate::modules::ids::advanced_scanning::SESSION_MANAGEMENT.to_string());
            let (session_vulns, session_tests) = self
                .session_management_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(session_vulns);
            total_tests += session_tests as u64;
            queue
                .increment_tests(scan_id.clone(), session_tests as u64)
                .await?;
        }

        // MFA Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::MFA_SCANNER) {
            info!("Checking MFA security");
            modules_used.push(crate::modules::ids::advanced_scanning::MFA_SCANNER.to_string());
            let (mfa_vulns, mfa_tests) = self.mfa_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(mfa_vulns);
            total_tests += mfa_tests as u64;
            queue
                .increment_tests(scan_id.clone(), mfa_tests as u64)
                .await?;
        }

        // IDOR Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::IDOR_SCANNER) {
            info!("Checking for IDOR vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::IDOR_SCANNER.to_string());
            let (idor_vulns, idor_tests) = self.idor_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(idor_vulns);
            total_tests += idor_tests as u64;
            queue
                .increment_tests(scan_id.clone(), idor_tests as u64)
                .await?;
        }

        // BOLA Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::BOLA_SCANNER) {
            info!("Checking for BOLA vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::BOLA_SCANNER.to_string());
            let (bola_vulns, bola_tests) = self.bola_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(bola_vulns);
            total_tests += bola_tests as u64;
            queue
                .increment_tests(scan_id.clone(), bola_tests as u64)
                .await?;
        }

        // Authentication Manager Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::AUTH_MANAGER) {
            info!("Checking authentication management security");
            modules_used.push(crate::modules::ids::advanced_scanning::AUTH_MANAGER.to_string());
            let (auth_mgr_vulns, auth_mgr_tests) =
                self.auth_manager_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(auth_mgr_vulns);
            total_tests += auth_mgr_tests as u64;
            queue
                .increment_tests(scan_id.clone(), auth_mgr_tests as u64)
                .await?;
        }

        // LDAP Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::LDAP_INJECTION) {
            info!("Checking for LDAP injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::LDAP_INJECTION.to_string());
            let (ldap_vulns, ldap_tests) =
                self.ldap_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(ldap_vulns);
            total_tests += ldap_tests as u64;
            queue
                .increment_tests(scan_id.clone(), ldap_tests as u64)
                .await?;
        }

        // File Upload Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::FILE_UPLOAD) {
            info!("Checking file upload security");
            modules_used.push(crate::modules::ids::advanced_scanning::FILE_UPLOAD.to_string());
            let (upload_vulns, upload_tests) =
                self.file_upload_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(upload_vulns);
            total_tests += upload_tests as u64;
            queue
                .increment_tests(scan_id.clone(), upload_tests as u64)
                .await?;
        }

        // Open Redirect Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::OPEN_REDIRECT) {
            info!("Checking for open redirect vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::OPEN_REDIRECT.to_string());
            let (redirect_vulns, redirect_tests) =
                self.open_redirect_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(redirect_vulns);
            total_tests += redirect_tests as u64;
            queue
                .increment_tests(scan_id.clone(), redirect_tests as u64)
                .await?;
        }

        // Clickjacking Protection Check (Free tier)
        info!("Checking clickjacking protection");
        modules_used.push(crate::modules::ids::free::CLICKJACKING.to_string());
        let (clickjack_vulns, clickjack_tests) =
            self.clickjacking_scanner.scan(&target, &config).await?;
        all_vulnerabilities.extend(clickjack_vulns);
        total_tests += clickjack_tests as u64;
        queue
            .increment_tests(scan_id.clone(), clickjack_tests as u64)
            .await?;

        // CRLF Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::CRLF_INJECTION) {
            info!("Checking for CRLF injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::CRLF_INJECTION.to_string());
            let (crlf_vulns, crlf_tests) =
                self.crlf_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(crlf_vulns);
            total_tests += crlf_tests as u64;
            queue
                .increment_tests(scan_id.clone(), crlf_tests as u64)
                .await?;
        }

        // Email Header Injection Security Check (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::EMAIL_HEADER_INJECTION)
        {
            info!("Checking for email header injection vulnerabilities");
            modules_used
                .push(crate::modules::ids::advanced_scanning::EMAIL_HEADER_INJECTION.to_string());
            let (email_header_vulns, email_header_tests) = self
                .email_header_injection_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(email_header_vulns);
            total_tests += email_header_tests as u64;
            queue
                .increment_tests(scan_id.clone(), email_header_tests as u64)
                .await?;
        }

        // Template Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::SSTI_SCANNER) {
            info!("Checking for template injection (SSTI) vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::SSTI_SCANNER.to_string());
            let (ssti_vulns, ssti_tests) = self
                .template_injection_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(ssti_vulns);
            total_tests += ssti_tests as u64;
            queue
                .increment_tests(scan_id.clone(), ssti_tests as u64)
                .await?;
        }

        // Deserialization Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::DESERIALIZATION)
        {
            info!("Checking for insecure deserialization vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::DESERIALIZATION.to_string());
            let (deser_vulns, deser_tests) =
                self.deserialization_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(deser_vulns);
            total_tests += deser_tests as u64;
            queue
                .increment_tests(scan_id.clone(), deser_tests as u64)
                .await?;
        }

        // Source Map Scanner (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::SOURCE_MAP_DETECTION)
        {
            info!("Scanning for exposed JavaScript source maps");
            modules_used
                .push(crate::modules::ids::advanced_scanning::SOURCE_MAP_DETECTION.to_string());
            let (sm_vulns, sm_tests) = self.source_map_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(sm_vulns);
            total_tests += sm_tests as u64;
            queue
                .increment_tests(scan_id.clone(), sm_tests as u64)
                .await?;
        }

        // Favicon Hash Scanner (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::FAVICON_HASH_DETECTION)
        {
            info!("Scanning favicon for technology fingerprinting");
            modules_used
                .push(crate::modules::ids::advanced_scanning::FAVICON_HASH_DETECTION.to_string());
            let (fh_vulns, fh_tests) = self.favicon_hash_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(fh_vulns);
            total_tests += fh_tests as u64;
            queue
                .increment_tests(scan_id.clone(), fh_tests as u64)
                .await?;
        }

        // API Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::API_SECURITY) {
            info!("Checking API security");
            modules_used.push(crate::modules::ids::advanced_scanning::API_SECURITY.to_string());
            let (api_vulns, api_tests) = self.api_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(api_vulns);
            total_tests += api_tests as u64;
            queue
                .increment_tests(scan_id.clone(), api_tests as u64)
                .await?;
        }

        // HTTP Request Smuggling Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::HTTP_SMUGGLING) {
            info!("Checking for HTTP request smuggling vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::HTTP_SMUGGLING.to_string());
            let (smuggling_vulns, smuggling_tests) =
                self.http_smuggling_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(smuggling_vulns);
            total_tests += smuggling_tests as u64;
            queue
                .increment_tests(scan_id.clone(), smuggling_tests as u64)
                .await?;
        }

        // XML Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::XML_INJECTION) {
            info!("Checking for XML injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::XML_INJECTION.to_string());
            let (xml_vulns, xml_tests) = self.xml_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(xml_vulns);
            total_tests += xml_tests as u64;
            queue
                .increment_tests(scan_id.clone(), xml_tests as u64)
                .await?;
        }

        // XPath Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::XPATH_INJECTION)
        {
            info!("Checking for XPath injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::XPATH_INJECTION.to_string());
            let (xpath_vulns, xpath_tests) =
                self.xpath_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(xpath_vulns);
            total_tests += xpath_tests as u64;
            queue
                .increment_tests(scan_id.clone(), xpath_tests as u64)
                .await?;
        }

        // Code Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::CODE_INJECTION) {
            info!("Checking for code injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::CODE_INJECTION.to_string());
            let (code_vulns, code_tests) =
                self.code_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(code_vulns);
            total_tests += code_tests as u64;
            queue
                .increment_tests(scan_id.clone(), code_tests as u64)
                .await?;
        }

        // SSI Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::SSI_INJECTION) {
            info!("Checking for SSI injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::SSI_INJECTION.to_string());
            let (ssi_vulns, ssi_tests) = self.ssi_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(ssi_vulns);
            total_tests += ssi_tests as u64;
            queue
                .increment_tests(scan_id.clone(), ssi_tests as u64)
                .await?;
        }

        // Race Condition Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::RACE_CONDITION) {
            info!("Checking for race condition vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::RACE_CONDITION.to_string());
            let (race_vulns, race_tests) =
                self.race_condition_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(race_vulns);
            total_tests += race_tests as u64;
            queue
                .increment_tests(scan_id.clone(), race_tests as u64)
                .await?;
        }

        // Mass Assignment Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::MASS_ASSIGNMENT)
        {
            info!("Checking for mass assignment vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::MASS_ASSIGNMENT.to_string());
            let (ma_vulns, ma_tests) = self.mass_assignment_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(ma_vulns);
            total_tests += ma_tests as u64;
            queue
                .increment_tests(scan_id.clone(), ma_tests as u64)
                .await?;
        }

        // Information Disclosure Security Check (Free tier)
        info!("Checking for information disclosure vulnerabilities");
        modules_used.push(crate::modules::ids::free::INFO_DISCLOSURE_BASIC.to_string());
        let (info_vulns, info_tests) = self
            .information_disclosure_scanner
            .scan(&target, &config)
            .await?;
        all_vulnerabilities.extend(info_vulns);
        total_tests += info_tests as u64;
        queue
            .increment_tests(scan_id.clone(), info_tests as u64)
            .await?;

        // Cache Poisoning Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::CACHE_POISONING)
        {
            info!("Checking for cache poisoning vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::CACHE_POISONING.to_string());
            let (cp_vulns, cp_tests) = self.cache_poisoning_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cp_vulns);
            total_tests += cp_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cp_tests as u64)
                .await?;
        }

        // Business Logic Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::BUSINESS_LOGIC) {
            info!("Checking for business logic vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::BUSINESS_LOGIC.to_string());
            let (bl_vulns, bl_tests) = self.business_logic_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(bl_vulns);
            total_tests += bl_tests as u64;
            queue
                .increment_tests(scan_id.clone(), bl_tests as u64)
                .await?;
        }

        // JWT Vulnerabilities Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::JWT_SCANNER) {
            info!("Checking for JWT vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::JWT_SCANNER.to_string());
            let (jwt_vulns, jwt_tests) = self
                .jwt_vulnerabilities_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(jwt_vulns);
            total_tests += jwt_tests as u64;
            queue
                .increment_tests(scan_id.clone(), jwt_tests as u64)
                .await?;
        }

        // GraphQL Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::GRAPHQL_SCANNER)
        {
            info!("Checking for GraphQL security issues");
            modules_used.push(crate::modules::ids::advanced_scanning::GRAPHQL_SCANNER.to_string());
            let (gql_vulns, gql_tests) =
                self.graphql_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(gql_vulns);
            total_tests += gql_tests as u64;
            queue
                .increment_tests(scan_id.clone(), gql_tests as u64)
                .await?;
        }

        // NoSQL Injection Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::NOSQL_SCANNER) {
            info!("Checking for NoSQL injection vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::NOSQL_SCANNER.to_string());
            let (nosql_vulns, nosql_tests) =
                self.nosql_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(nosql_vulns);
            total_tests += nosql_tests as u64;
            queue
                .increment_tests(scan_id.clone(), nosql_tests as u64)
                .await?;
        }

        // File Upload Vulnerabilities Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::FILE_UPLOAD) {
            info!("Checking for file upload vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::FILE_UPLOAD.to_string());
            let (upload_vulns, upload_tests) = self
                .file_upload_vulnerabilities_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(upload_vulns);
            total_tests += upload_tests as u64;
            queue
                .increment_tests(scan_id.clone(), upload_tests as u64)
                .await?;
        }

        // CORS Misconfiguration Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::CORS_MISCONFIG) {
            info!("Checking for CORS misconfiguration");
            modules_used.push(crate::modules::ids::advanced_scanning::CORS_MISCONFIG.to_string());
            let (cors_misc_vulns, cors_misc_tests) = self
                .cors_misconfiguration_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(cors_misc_vulns);
            total_tests += cors_misc_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cors_misc_tests as u64)
                .await?;
        }

        // Cloud Storage Security Check (Team+)
        if scan_token.is_module_authorized(crate::modules::ids::cloud_scanning::CLOUD_STORAGE) {
            info!("Checking for cloud storage misconfigurations");
            modules_used.push(crate::modules::ids::cloud_scanning::CLOUD_STORAGE.to_string());
            let (cloud_vulns, cloud_tests) =
                self.cloud_storage_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cloud_vulns);
            total_tests += cloud_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cloud_tests as u64)
                .await?;
        }

        // Framework Vulnerabilities Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::FRAMEWORK_VULNS)
        {
            info!("Checking for framework-specific vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::FRAMEWORK_VULNS.to_string());
            let (framework_vulns, framework_tests) = self
                .framework_vulnerabilities_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(framework_vulns);
            total_tests += framework_tests as u64;
            queue
                .increment_tests(scan_id.clone(), framework_tests as u64)
                .await?;
        }

        // JavaScript Mining Security Check (results from Phase 0)
        info!(
            "[JS-Miner] Adding {} vulnerabilities found during reconnaissance",
            js_miner_vulns.len()
        );
        all_vulnerabilities.extend(js_miner_vulns);
        total_tests += js_miner_tests as u64;
        queue
            .increment_tests(scan_id.clone(), js_miner_tests as u64)
            .await?;

        // README Invisible Prompt Injection Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::README_PROMPT_INJECTION) {
            info!("Checking README.md for invisible prompt injection");
            modules_used.push(crate::modules::ids::advanced_scanning::README_PROMPT_INJECTION.to_string());
            let (readme_pi_vulns, readme_pi_tests) =
                self.readme_prompt_injection_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(readme_pi_vulns);
            total_tests += readme_pi_tests as u64;
            queue
                .increment_tests(scan_id.clone(), readme_pi_tests as u64)
                .await?;
        }

        // Sensitive Data Exposure Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::SENSITIVE_DATA) {
            info!("Checking for sensitive data exposure");
            modules_used.push(crate::modules::ids::advanced_scanning::SENSITIVE_DATA.to_string());
            let (sensitive_vulns, sensitive_tests) =
                self.sensitive_data_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(sensitive_vulns);
            total_tests += sensitive_tests as u64;
            queue
                .increment_tests(scan_id.clone(), sensitive_tests as u64)
                .await?;
        }

        // Advanced API Fuzzing (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::API_FUZZER) {
            info!("Running advanced API fuzzing");
            modules_used.push(crate::modules::ids::advanced_scanning::API_FUZZER.to_string());
            let (api_fuzz_vulns, api_fuzz_tests) =
                self.api_fuzzer_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(api_fuzz_vulns);
            total_tests += api_fuzz_tests as u64;
            queue
                .increment_tests(scan_id.clone(), api_fuzz_tests as u64)
                .await?;
        }

        // API Gateway Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::API_GATEWAY) {
            info!("Checking API Gateway security");
            modules_used.push(crate::modules::ids::advanced_scanning::API_GATEWAY.to_string());
            let (apigw_vulns, apigw_tests) =
                self.api_gateway_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(apigw_vulns);
            total_tests += apigw_tests as u64;
            queue
                .increment_tests(scan_id.clone(), apigw_tests as u64)
                .await?;
        }

        // Cloud Security Check (Team+)
        if scan_token.is_module_authorized(crate::modules::ids::cloud_scanning::CLOUD_SECURITY) {
            info!("Checking cloud security vulnerabilities");
            modules_used.push(crate::modules::ids::cloud_scanning::CLOUD_SECURITY.to_string());
            let (cloud_sec_vulns, cloud_sec_tests) =
                self.cloud_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cloud_sec_vulns);
            total_tests += cloud_sec_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cloud_sec_tests as u64)
                .await?;
        }

        // Container Security Check (Team+)
        if scan_token.is_module_authorized(crate::modules::ids::cloud_scanning::CONTAINER_SCANNER) {
            info!("Checking container security");
            modules_used.push(crate::modules::ids::cloud_scanning::CONTAINER_SCANNER.to_string());
            let (container_vulns, container_tests) =
                self.container_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(container_vulns);
            total_tests += container_tests as u64;
            queue
                .increment_tests(scan_id.clone(), container_tests as u64)
                .await?;
        }

        // WebAuthn/FIDO2 Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::WEBAUTHN_SCANNER)
        {
            info!("Checking WebAuthn/FIDO2 security");
            modules_used.push(crate::modules::ids::advanced_scanning::WEBAUTHN_SCANNER.to_string());
            let (webauthn_vulns, webauthn_tests) =
                self.webauthn_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(webauthn_vulns);
            total_tests += webauthn_tests as u64;
            queue
                .increment_tests(scan_id.clone(), webauthn_tests as u64)
                .await?;
        }

        // HTTP/3 & QUIC Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::HTTP3_SCANNER) {
            info!("Checking HTTP/3 and QUIC security");
            modules_used.push(crate::modules::ids::advanced_scanning::HTTP3_SCANNER.to_string());
            let (http3_vulns, http3_tests) = self.http3_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(http3_vulns);
            total_tests += http3_tests as u64;
            queue
                .increment_tests(scan_id.clone(), http3_tests as u64)
                .await?;
        }

        // Advanced SSTI Security Check (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::SSTI_ADVANCED) {
            info!("Checking advanced SSTI vulnerabilities");
            modules_used.push(crate::modules::ids::advanced_scanning::SSTI_ADVANCED.to_string());
            let (ssti_adv_vulns, ssti_adv_tests) =
                self.ssti_advanced_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(ssti_adv_vulns);
            total_tests += ssti_adv_tests as u64;
            queue
                .increment_tests(scan_id.clone(), ssti_adv_tests as u64)
                .await?;
        }

        // CVE-2025-55182: React Server Components RCE (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::cve_scanners::CVE_2025_55182) {
            info!("Checking for CVE-2025-55182 (React2Shell RCE)");
            modules_used.push(crate::modules::ids::cve_scanners::CVE_2025_55182.to_string());
            let (cve_55182_vulns, cve_55182_tests) =
                self.cve_2025_55182_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cve_55182_vulns);
            total_tests += cve_55182_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cve_55182_tests as u64)
                .await?;
        }

        // CVE-2025-55183: React Server Components Source Code Exposure (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::cve_scanners::CVE_2025_55183) {
            info!("Checking for CVE-2025-55183 (RSC Source Code Exposure)");
            modules_used.push(crate::modules::ids::cve_scanners::CVE_2025_55183.to_string());
            let (cve_55183_vulns, cve_55183_tests) =
                self.cve_2025_55183_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cve_55183_vulns);
            total_tests += cve_55183_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cve_55183_tests as u64)
                .await?;
        }

        // CVE-2025-55184: React Server Components DoS (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::cve_scanners::CVE_2025_55184) {
            info!("Checking for CVE-2025-55184 (RSC DoS)");
            modules_used.push(crate::modules::ids::cve_scanners::CVE_2025_55184.to_string());
            let (cve_55184_vulns, cve_55184_tests) =
                self.cve_2025_55184_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(cve_55184_vulns);
            total_tests += cve_55184_tests as u64;
            queue
                .increment_tests(scan_id.clone(), cve_55184_tests as u64)
                .await?;
        }

        // HTTP Parameter Pollution (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::HPP_SCANNER) {
            info!("[HPP] Testing for HTTP Parameter Pollution");
            modules_used.push(crate::modules::ids::advanced_scanning::HPP_SCANNER.to_string());
            let (hpp_vulns, hpp_tests) = self.hpp_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(hpp_vulns);
            total_tests += hpp_tests as u64;
            queue
                .increment_tests(scan_id.clone(), hpp_tests as u64)
                .await?;
        }

        // WAF Bypass Testing (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::WAF_BYPASS) {
            info!("[WAF-Bypass] Testing advanced WAF bypass techniques");
            modules_used.push(crate::modules::ids::advanced_scanning::WAF_BYPASS.to_string());
            let (waf_vulns, waf_tests) = self.waf_bypass_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(waf_vulns);
            total_tests += waf_tests as u64;
            queue
                .increment_tests(scan_id.clone(), waf_tests as u64)
                .await?;
        }

        // Merlin - JavaScript Library Vulnerability Detection (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::MERLIN_SCANNER) {
            info!("[Merlin] Scanning for vulnerable JavaScript libraries");
            modules_used.push(crate::modules::ids::advanced_scanning::MERLIN_SCANNER.to_string());
            let (merlin_vulns, merlin_tests) = self.merlin_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(merlin_vulns);
            total_tests += merlin_tests as u64;
            queue
                .increment_tests(scan_id.clone(), merlin_tests as u64)
                .await?;
        }

        // Tomcat Misconfiguration Scanner (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::TOMCAT_MISCONFIG)
        {
            info!("[Tomcat] Checking for Apache Tomcat misconfigurations");
            modules_used.push(crate::modules::ids::advanced_scanning::TOMCAT_MISCONFIG.to_string());
            let (tomcat_vulns, tomcat_tests) =
                self.tomcat_misconfig_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(tomcat_vulns);
            total_tests += tomcat_tests as u64;
            queue
                .increment_tests(scan_id.clone(), tomcat_tests as u64)
                .await?;
        }

        // Varnish Misconfiguration Scanner (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::VARNISH_MISCONFIG)
        {
            info!("[Varnish] Checking for Varnish cache misconfigurations");
            modules_used
                .push(crate::modules::ids::advanced_scanning::VARNISH_MISCONFIG.to_string());
            let (varnish_vulns, varnish_tests) = self
                .varnish_misconfig_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(varnish_vulns);
            total_tests += varnish_tests as u64;
            queue
                .increment_tests(scan_id.clone(), varnish_tests as u64)
                .await?;
        }

        // JavaScript Sensitive Information Leakage Scanner (Professional+)
        if scan_token
            .is_module_authorized(crate::modules::ids::advanced_scanning::JS_SENSITIVE_INFO)
        {
            info!("[JS-Sensitive] Scanning JavaScript for sensitive information leakage");
            modules_used
                .push(crate::modules::ids::advanced_scanning::JS_SENSITIVE_INFO.to_string());
            let (js_sensitive_vulns, js_sensitive_tests) = self
                .js_sensitive_info_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(js_sensitive_vulns);
            total_tests += js_sensitive_tests as u64;
            queue
                .increment_tests(scan_id.clone(), js_sensitive_tests as u64)
                .await?;
        }

        // Rate Limiting Scanner (Professional+)
        if scan_token.is_module_authorized(crate::modules::ids::advanced_scanning::RATE_LIMITING) {
            info!("[RateLimit] Testing for insufficient rate limiting on authentication endpoints");
            modules_used.push(crate::modules::ids::advanced_scanning::RATE_LIMITING.to_string());
            let (rate_limit_vulns, rate_limit_tests) =
                self.rate_limiting_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(rate_limit_vulns);
            total_tests += rate_limit_tests as u64;
            queue
                .increment_tests(scan_id.clone(), rate_limit_tests as u64)
                .await?;
        }

        // WordPress Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::WORDPRESS_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::WordPress, &scan_plan)
        {
            info!("[WordPress] Advanced WordPress security scanning");
            modules_used.push(crate::modules::ids::cms_security::WORDPRESS_SCANNER.to_string());
            let (wordpress_vulns, wordpress_tests) = self
                .wordpress_security_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(wordpress_vulns);
            total_tests += wordpress_tests as u64;
            queue
                .increment_tests(scan_id.clone(), wordpress_tests as u64)
                .await?;
        } else {
            debug!("[WordPress] Skipping - not detected or not authorized");
        }

        // Drupal Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::DRUPAL_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::Drupal, &scan_plan)
        {
            info!("[Drupal] Advanced Drupal security scanning");
            modules_used.push(crate::modules::ids::cms_security::DRUPAL_SCANNER.to_string());
            let (drupal_vulns, drupal_tests) =
                self.drupal_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(drupal_vulns);
            total_tests += drupal_tests as u64;
            queue
                .increment_tests(scan_id.clone(), drupal_tests as u64)
                .await?;
        } else {
            debug!("[Drupal] Skipping - not detected or not authorized");
        }

        // Laravel Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::LARAVEL_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::Laravel, &scan_plan)
        {
            info!("[Laravel] Advanced Laravel security scanning");
            modules_used.push(crate::modules::ids::cms_security::LARAVEL_SCANNER.to_string());
            let (laravel_vulns, laravel_tests) =
                self.laravel_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(laravel_vulns);
            total_tests += laravel_tests as u64;
            queue
                .increment_tests(scan_id.clone(), laravel_tests as u64)
                .await?;
        } else {
            debug!("[Laravel] Skipping - not detected or not authorized");
        }

        // Express.js Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::EXPRESS_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::Express, &scan_plan)
        {
            info!("[Express] Advanced Express.js/Node.js security scanning");
            modules_used.push(crate::modules::ids::cms_security::EXPRESS_SCANNER.to_string());
            let (express_vulns, express_tests) =
                self.express_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(express_vulns);
            total_tests += express_tests as u64;
            queue
                .increment_tests(scan_id.clone(), express_tests as u64)
                .await?;
        } else {
            debug!("[Express] Skipping - not detected or not authorized");
        }

        // Next.js Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::NEXTJS_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::NextJs, &scan_plan)
        {
            info!("[Next.js] Advanced Next.js security scanning");
            modules_used.push(crate::modules::ids::cms_security::NEXTJS_SCANNER.to_string());
            let (nextjs_vulns, nextjs_tests) =
                self.nextjs_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(nextjs_vulns);
            total_tests += nextjs_tests as u64;
            queue
                .increment_tests(scan_id.clone(), nextjs_tests as u64)
                .await?;
        } else {
            debug!("[Next.js] Skipping - not detected or not authorized");
        }

        // SvelteKit Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::SVELTEKIT_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::SvelteKit, &scan_plan)
        {
            info!("[SvelteKit] Advanced SvelteKit security scanning");
            modules_used.push(crate::modules::ids::cms_security::SVELTEKIT_SCANNER.to_string());
            let (sveltekit_vulns, sveltekit_tests) = self
                .sveltekit_security_scanner
                .scan(&target, &config)
                .await?;
            all_vulnerabilities.extend(sveltekit_vulns);
            total_tests += sveltekit_tests as u64;
            queue
                .increment_tests(scan_id.clone(), sveltekit_tests as u64)
                .await?;
        } else {
            debug!("[SvelteKit] Skipping - not detected or not authorized");
        }

        // React Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::REACT_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::React, &scan_plan)
        {
            info!("[React] Advanced React security scanning");
            modules_used.push(crate::modules::ids::cms_security::REACT_SCANNER.to_string());
            let (react_vulns, react_tests) =
                self.react_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(react_vulns);
            total_tests += react_tests as u64;
            queue
                .increment_tests(scan_id.clone(), react_tests as u64)
                .await?;
        } else {
            debug!("[React] Module not authorized - skipping");
        }

        // Django Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::DJANGO_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::Django, &scan_plan)
        {
            info!("[Django] Advanced Django security scanning");
            modules_used.push(crate::modules::ids::cms_security::DJANGO_SCANNER.to_string());
            let (django_vulns, django_tests) =
                self.django_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(django_vulns);
            total_tests += django_tests as u64;
            queue
                .increment_tests(scan_id.clone(), django_tests as u64)
                .await?;
        } else {
            debug!("[Django] Skipping - not detected or not authorized");
        }

        // Liferay Security Scanner (Personal+ license, intelligent routing)
        if scan_token.is_module_authorized(crate::modules::ids::cms_security::LIFERAY_SCANNER)
            && Self::should_run_endpoint_scanner(TechScannerType::Liferay, &scan_plan)
        {
            info!("[Liferay] Advanced Liferay security scanning");
            modules_used.push(crate::modules::ids::cms_security::LIFERAY_SCANNER.to_string());
            let (liferay_vulns, liferay_tests) =
                self.liferay_security_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(liferay_vulns);
            total_tests += liferay_tests as u64;
            queue
                .increment_tests(scan_id.clone(), liferay_tests as u64)
                .await?;
        } else {
            debug!("[Liferay] Skipping - not detected or not authorized");
        }

        // SOC2/PCI-DSS/HIPAA Compliance Scanner (Enterprise license)
        if scan_token.is_module_authorized(crate::modules::ids::enterprise::COMPLIANCE_SCANNER) {
            info!("[Compliance] SOC2, PCI-DSS, and HIPAA compliance scanning");
            modules_used.push(crate::modules::ids::enterprise::COMPLIANCE_SCANNER.to_string());
            let (compliance_vulns, compliance_tests) =
                self.compliance_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(compliance_vulns);
            total_tests += compliance_tests as u64;
            queue
                .increment_tests(scan_id.clone(), compliance_tests as u64)
                .await?;
        } else {
            debug!("[Compliance] Module not authorized - skipping");
        }

        // DORA Compliance Scanner (Enterprise license)
        if scan_token.is_module_authorized(crate::modules::ids::enterprise::DORA_SCANNER) {
            info!("[DORA] EU Digital Operational Resilience Act compliance scanning");
            modules_used.push(crate::modules::ids::enterprise::DORA_SCANNER.to_string());
            let (dora_vulns, dora_tests) = self.dora_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(dora_vulns);
            total_tests += dora_tests as u64;
            queue
                .increment_tests(scan_id.clone(), dora_tests as u64)
                .await?;
        } else {
            debug!("[DORA] Module not authorized - skipping");
        }

        // NIS2 Compliance Scanner (Enterprise license)
        if scan_token.is_module_authorized(crate::modules::ids::enterprise::NIS2_SCANNER) {
            info!("[NIS2] EU Network and Information Security Directive 2 compliance scanning");
            modules_used.push(crate::modules::ids::enterprise::NIS2_SCANNER.to_string());
            let (nis2_vulns, nis2_tests) = self.nis2_scanner.scan(&target, &config).await?;
            all_vulnerabilities.extend(nis2_vulns);
            total_tests += nis2_tests as u64;
            queue
                .increment_tests(scan_id.clone(), nis2_tests as u64)
                .await?;
        } else {
            debug!("[NIS2] Module not authorized - skipping");
        }

        // Phase 2: Crawler (if enabled)
        if config.enable_crawler {
            info!("Crawler enabled - discovering additional endpoints");
            match self.crawl_target(&target, config.max_depth).await {
                Ok(discovered_urls) => {
                    info!(
                        "Crawler discovered {} additional URLs",
                        discovered_urls.len()
                    );
                    // XSS testing on crawled URLs is now handled in Phase 1
                }
                Err(e) => {
                    warn!("Crawler failed: {}", e);
                }
            }
        }

        // Phase 3: Ultra mode - Additional attack vectors
        if config.scan_mode == ScanMode::Thorough || config.scan_mode == ScanMode::Insane {
            info!("Thorough/Insane mode enabled - testing advanced attack vectors");

            // Note: Time-based blind SQLi is now automatically included in the unified scanner

            // Test for SSRF vulnerabilities
            let ssrf_result = self.test_ssrf(&target, &url_data.parameters).await;
            if let Ok((ssrf_vulns, ssrf_tests)) = ssrf_result {
                all_vulnerabilities.extend(ssrf_vulns);
                total_tests += ssrf_tests as u64;
                queue
                    .increment_tests(scan_id.clone(), ssrf_tests as u64)
                    .await?;
            }
        }

        let elapsed = start_time.elapsed();

        // Deduplicate vulnerabilities - multiple scanners may report the same finding
        // (e.g., session_management and advanced_auth both check SameSite/concurrent sessions)
        let pre_dedup_count = all_vulnerabilities.len();
        {
            let mut seen = std::collections::HashSet::new();
            all_vulnerabilities.retain(|v| {
                let key = format!("{}|{}|{}", v.vuln_type, v.url, v.parameter.as_deref().unwrap_or(""));
                seen.insert(key)
            });
        }
        if all_vulnerabilities.len() < pre_dedup_count {
            info!(
                "Deduplicated {} duplicate findings ({} -> {})",
                pre_dedup_count - all_vulnerabilities.len(),
                pre_dedup_count,
                all_vulnerabilities.len()
            );
        }

        info!(
            "Scan completed: {} vulnerabilities found in {} tests ({:.2}s)",
            all_vulnerabilities.len(),
            total_tests,
            elapsed.as_secs_f64()
        );

        // Embed license signature in results for audit trail (legacy)
        let license_sig = crate::license::get_license_signature();

        // Create preliminary results for hashing
        let mut results = ScanResults {
            scan_id: scan_id.clone(),
            target: target.clone(),
            tests_run: total_tests,
            vulnerabilities: all_vulnerabilities,
            started_at,
            completed_at: chrono::Utc::now().to_rfc3339(),
            duration_seconds: elapsed.as_secs_f64(),
            early_terminated: false,
            termination_reason: None,
            scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
            license_signature: Some(license_sig),
            quantum_signature: None,
            authorization_token_id: Some(scan_token.token.clone()),
        };

        // ============================================================
        // QUANTUM-SAFE SIGNING - MANDATORY FOR ALL RESULTS
        // ============================================================
        // Sign the results with the scan token to prove authenticity.
        // This creates a cryptographic audit trail that cannot be forged.
        // STRICT MODE: Server signature required - no unsigned results allowed.
        let results_hash = crate::signing::hash_results(&results)
            .map_err(|e| anyhow::anyhow!("Failed to hash results: {}", e))?;

        // Collect privacy-safe findings summary (only counts, no URLs or details)
        let findings_summary =
            crate::signing::FindingsSummary::from_vulnerabilities(&results.vulnerabilities);

        info!(
            "[Signing] Signing results with {} modules used, {} findings",
            modules_used.len(),
            findings_summary.total
        );
        match crate::signing::sign_results(
            &results_hash,
            &scan_token,
            modules_used,
            Some(crate::signing::ScanMetadata {
                targets_count: Some(1),
                scanner_version: Some(env!("CARGO_PKG_VERSION").to_string()),
                scan_duration_ms: Some(elapsed.as_millis() as u64),
            }),
            Some(findings_summary),
            Some(vec![job.target.clone()]),
        )
        .await
        {
            Ok(signature) => {
                info!(
                    "[SIGNED] Results signed with algorithm: {}",
                    signature.algorithm
                );
                results.quantum_signature = Some(signature);
            }
            Err(crate::signing::SigningError::ServerUnreachable(msg)) => {
                // STRICT MODE: Signing requires server connection
                error!("Failed to sign results - server unreachable: {}", msg);
                return Err(anyhow::anyhow!("Signing server unreachable: {}", msg));
            }
            Err(e) => {
                // STRICT MODE: No unsigned results allowed
                error!("Failed to sign results: {}", e);
                return Err(anyhow::anyhow!("Failed to sign results: {}", e));
            }
        }

        // ============================================================
        // ML INTEGRATION - AUTOMATIC LEARNING FROM SCAN RESULTS
        // ============================================================
        // Process vulnerabilities for ML learning (runs in background)
        if let Some(ref ml) = self.ml_integration {
            // Learn from each vulnerability found
            for vuln in &results.vulnerabilities {
                // Create a basic response for learning (we don't have the original response here)
                let learning_response = crate::http_client::HttpResponse {
                    status_code: 200,
                    headers: std::collections::HashMap::new(),
                    body: vuln.evidence.clone().unwrap_or_default(),
                    duration_ms: 0,
                };

                if let Err(e) = ml.learn(vuln, &learning_response).await {
                    debug!("ML learning failed for {}: {}", vuln.vuln_type, e);
                }
            }

            // Notify ML system that scan is complete (triggers model sync)
            if let Err(e) = ml.scan_complete().await {
                debug!("ML scan_complete failed: {}", e);
            }
        }

        Ok(results)
    }

    /// Detect if target is behind a CDN
    async fn detect_cdn(&self, target: &str) -> Result<Option<String>> {
        use crate::cdn_detector;

        debug!("Checking CDN protection for: {}", target);

        match self.http_client.get(target).await {
            Ok(response) => {
                if let Some(cdn_name) = cdn_detector::is_cdn_protected(&response) {
                    info!(
                        "[CDN] CDN detected: {} - Optimizing scan strategy",
                        cdn_name
                    );
                    return Ok(Some(cdn_name));
                }
                Ok(None)
            }
            Err(_) => {
                // If initial request fails, proceed without CDN detection
                Ok(None)
            }
        }
    }

    /// Check if a parameter name is relevant for security testing
    /// Filters out JavaScript framework internals, crypto libraries, and other noise
    fn is_relevant_parameter(param_name: &str) -> bool {
        let param_lower = param_name.to_lowercase();

        // Skip parameters starting with underscore (usually internal/private)
        if param_name.starts_with('_') {
            return false;
        }

        // Skip UUID-like parameters (f_xxx, generated IDs)
        if param_name.starts_with("f_") && param_name.len() > 10 {
            return false;
        }

        // Skip Vue.js / Nuxt internals
        let vue_internals = [
            "vnode",
            "scopedslots",
            "vuesignature",
            "vuex",
            "vuecomponent",
            "$attrs",
            "$listeners",
            "$slots",
            "$refs",
            "$el",
            "$options",
        ];
        if vue_internals.iter().any(|v| param_lower == *v) {
            return false;
        }

        // Skip Apollo GraphQL internals
        let apollo_internals = [
            "apollo",
            "apollopromises",
            "apolloinitdata",
            "apolloprovider",
            "apolloutil",
            "apolloclients",
            "apollostate",
        ];
        if apollo_internals.iter().any(|a| param_lower.contains(a)) {
            return false;
        }

        // Skip Sentry monitoring internals
        if param_lower.contains("sentry") {
            return false;
        }

        // Skip crypto library references
        let crypto_libs = [
            "elliptic",
            "secp256k1",
            "ripple",
            "ecdsa",
            "ed25519",
            "curve25519",
        ];
        if crypto_libs.iter().any(|c| param_lower == *c) {
            return false;
        }

        // Skip *Service, *Provider patterns (service references, not input params)
        if (param_lower.ends_with("service") || param_lower.ends_with("provider"))
            && param_name.len() > 10
        {
            return false;
        }

        // Skip common JS framework internals
        let framework_internals = [
            "morph",
            "prefetch",
            "deep",
            "intersection",
            "wrapper",
            "tune",
            "palette",
            "scroll",
            "live",
            "normal",
            "alarm",
            "mutation",
            "getmetahtml",
            "routename",
            "checkoutparams",
        ];
        if framework_internals.iter().any(|f| param_lower == *f) {
            return false;
        }

        true
    }

    /// Check if we should skip a scanner based on CDN detection
    fn should_skip_scanner(&self, scanner_name: &str, cdn_info: &Option<String>) -> bool {
        if !self.config.cdn_detection_enabled {
            return false;
        }

        if let Some(_cdn_name) = cdn_info {
            use crate::cdn_detector::get_scanners_to_skip_for_cdn;
            let skip_list = get_scanners_to_skip_for_cdn(_cdn_name);
            if skip_list.contains(&scanner_name.to_string()) {
                debug!("[Skip] Skipping {} (CDN-protected)", scanner_name);
                return true;
            }
        }
        false
    }

    /// Check if a scanner should run for a specific parameter based on intelligent scan plan.
    ///
    /// This is the CORE of context-aware scanning:
    /// 1. Check if the scanner is in the global scan_plan.scanners list (tech-based routing)
    /// 2. Check if the parameter has this scanner in its suggested_scanners (parameter-specific routing)
    /// 3. Universal/core scanners always run (XSS, SQLi, SSRF, CORS, SecurityHeaders)
    fn should_run_scanner_for_param(
        scanner_type: TechScannerType,
        param_name: &str,
        scan_plan: &IntelligentScanPlan,
    ) -> bool {
        // Universal scanners ALWAYS run regardless of context
        let universal_scanners = [TechScannerType::SecurityHeaders, TechScannerType::Cors];
        if universal_scanners.contains(&scanner_type) {
            return true;
        }

        // Core vulnerability scanners always run (deduplicated, not spray-and-pray)
        let core_scanners = [
            TechScannerType::Xss,
            TechScannerType::SqlI,
            TechScannerType::Ssrf,
            TechScannerType::SsrfBlind,
        ];
        if core_scanners.contains(&scanner_type) {
            return true;
        }

        // Check 1: Is this scanner in the global scan plan based on detected tech?
        let in_global_plan = scan_plan.scanners.contains(&scanner_type);

        // Check 2: Does this specific parameter suggest this scanner?
        let param_suggests_scanner = scan_plan
            .prioritized_params
            .iter()
            .find(|p| p.name.eq_ignore_ascii_case(param_name))
            .map(|p| p.suggested_scanners.contains(&scanner_type))
            .unwrap_or(false);

        // If parameter has specific suggestions, honor them
        // If no specific suggestions, fall back to global plan
        if let Some(param) = scan_plan
            .prioritized_params
            .iter()
            .find(|p| p.name.eq_ignore_ascii_case(param_name))
        {
            if !param.suggested_scanners.is_empty() {
                // Parameter has explicit suggestions - only run those
                let should_run = param_suggests_scanner;
                if !should_run {
                    debug!(
                        "[IntelligentRouting] Skipping {} for param '{}' (not in suggested_scanners: {:?})",
                        scanner_type.display_name(), param_name, param.suggested_scanners
                    );
                }
                return should_run;
            }
        }

        // No parameter-specific suggestions - use global tech-based plan
        if !in_global_plan {
            debug!(
                "[IntelligentRouting] Skipping {} for param '{}' (not in tech-based scan plan)",
                scanner_type.display_name(),
                param_name
            );
        }
        in_global_plan
    }

    /// Get the payload intensity for a specific parameter from the scan plan.
    /// Returns the parameter's intensity if found, or Standard as default.
    fn get_param_intensity(
        param_name: &str,
        scan_plan: &IntelligentScanPlan,
    ) -> registry::PayloadIntensity {
        scan_plan
            .prioritized_params
            .iter()
            .find(|p| p.name.eq_ignore_ascii_case(param_name))
            .map(|p| p.intensity.clone())
            .unwrap_or(registry::PayloadIntensity::Standard)
    }

    /// Check if an endpoint-level scanner should run based on the intelligent scan plan.
    /// This is for scanners that don't operate on specific parameters but on the endpoint itself.
    fn should_run_endpoint_scanner(
        scanner_type: TechScannerType,
        scan_plan: &IntelligentScanPlan,
    ) -> bool {
        // Universal scanners ALWAYS run
        let universal_scanners = [
            TechScannerType::SecurityHeaders,
            TechScannerType::Cors,
            TechScannerType::Clickjacking,
        ];
        if universal_scanners.contains(&scanner_type) {
            return true;
        }

        // Core vulnerability scanners always run
        let core_scanners = [
            TechScannerType::Xss,
            TechScannerType::SqlI,
            TechScannerType::Ssrf,
            TechScannerType::SsrfBlind,
            TechScannerType::Csrf,
        ];
        if core_scanners.contains(&scanner_type) {
            return true;
        }

        // Check if scanner is in global scan plan
        let in_plan = scan_plan.scanners.contains(&scanner_type);
        if !in_plan {
            debug!(
                "[IntelligentRouting] Skipping endpoint scanner {} (not in tech-based scan plan, detected tech: {:?})",
                scanner_type.display_name(),
                scan_plan.technologies
            );
        }
        in_plan
    }

    /// Check if we should terminate early due to critical vulnerabilities
    fn should_terminate_early(&self, vulnerabilities: &[Vulnerability]) -> bool {
        if !self.config.early_termination_enabled {
            return false;
        }

        let critical_count = vulnerabilities
            .iter()
            .filter(|v| v.severity == Severity::Critical)
            .count();

        if critical_count > 0 {
            warn!(
                "[ALERT] Early termination: {} critical vulnerabilities found",
                critical_count
            );
            true
        } else {
            false
        }
    }

    /// Parse target URL and extract parameters
    fn parse_target_url(&self, target: &str) -> Result<UrlData> {
        let parsed = url::Url::parse(target).context("Failed to parse target URL")?;

        let mut parameters = Vec::new();

        // Extract query parameters
        for (name, value) in parsed.query_pairs() {
            parameters.push((name.to_string(), value.to_string()));
        }

        let scheme = parsed.scheme().to_string();
        let host = parsed.host_str().unwrap_or("").to_string();
        let path = parsed.path().to_string();

        Ok(UrlData {
            base_url: format!("{}://{}{}", scheme, host, path),
            parameters,
        })
    }

    /// Crawl target to discover additional URLs
    async fn crawl_target(&self, start_url: &str, max_depth: u32) -> Result<Vec<String>> {
        use regex::Regex;
        use std::collections::HashSet;

        let mut discovered = HashSet::new();
        let mut to_visit = vec![(start_url.to_string(), 0u32)];
        let mut visited = HashSet::new();

        let parsed_start = url::Url::parse(start_url)?;
        let base_domain = parsed_start.host_str().unwrap_or("").to_string();
        let scheme = parsed_start.scheme().to_string();

        let link_regex = Regex::new(r#"href=["']([^"']+)["']"#)?;

        while let Some((current_url, depth)) = to_visit.pop() {
            if depth >= max_depth || visited.contains(&current_url) {
                continue;
            }

            visited.insert(current_url.clone());

            match self.http_client.get(&current_url).await {
                Ok(response) => {
                    // Extract links from HTML
                    for cap in link_regex.captures_iter(&response.body) {
                        if let Some(link) = cap.get(1) {
                            let link_string = link.as_str().to_string();

                            // Build absolute URL
                            let absolute_url = if link_string.starts_with("http") {
                                link_string.clone()
                            } else if link_string.starts_with('/') {
                                format!("{}://{}{}", &scheme, &base_domain, &link_string)
                            } else {
                                continue; // Skip relative URLs for now
                            };

                            // Only crawl same domain
                            if let Ok(parsed) = url::Url::parse(&absolute_url) {
                                if parsed.host_str() == Some(base_domain.as_str()) {
                                    discovered.insert(absolute_url.clone());
                                    if depth + 1 < max_depth {
                                        to_visit.push((absolute_url, depth + 1));
                                    }
                                }
                            }
                        }
                    }
                }
                Err(e) => {
                    debug!("Failed to crawl {}: {}", current_url, e);
                }
            }
        }

        Ok(discovered.into_iter().collect())
    }

    /// Test for SSRF (Server-Side Request Forgery) vulnerabilities
    async fn test_ssrf(
        &self,
        base_url: &str,
        parameters: &[(String, String)],
    ) -> Result<(Vec<Vulnerability>, usize)> {
        use crate::types::{Confidence, Severity};

        let mut vulnerabilities = Vec::new();
        let mut tests_run = 0;

        // SSRF test payloads - Convert to owned Strings to avoid &str lifetime issues across await
        let ssrf_payloads: Vec<String> = vec![
            "http://169.254.169.254/latest/meta-data/".to_string(), // AWS metadata
            "http://metadata.google.internal/".to_string(),         // GCP metadata
            "http://localhost:80".to_string(),
            "http://127.0.0.1:22".to_string(),
            "http://0.0.0.0:3306".to_string(),
            "file:///etc/passwd".to_string(),
            "gopher://127.0.0.1:25/".to_string(),
        ];

        for (param_name, _) in parameters {
            for payload in &ssrf_payloads {
                tests_run += 1;

                let test_url = if base_url.contains('?') {
                    format!(
                        "{}&{}={}",
                        base_url,
                        param_name,
                        urlencoding::encode(payload)
                    )
                } else {
                    format!(
                        "{}?{}={}",
                        base_url,
                        param_name,
                        urlencoding::encode(payload)
                    )
                };

                match self.http_client.get(&test_url).await {
                    Ok(response) => {
                        // Check for SSRF indicators
                        let has_metadata = response.body.contains("ami-id")
                            || response.body.contains("instance-id")
                            || response.body.contains("meta-data");
                        // Require specific internal service fingerprints
                        // Removed "SSH-" which matches documentation about SSH versions
                        let has_internal_response =
                            response.body.contains("root:x:0:0:") || response.body.contains("SSH-2.0-OpenSSH");

                        if has_metadata || has_internal_response {
                            info!("SSRF vulnerability detected in parameter '{}'", param_name);

                            let vuln = Vulnerability {
                                id: format!("ssrf_{}", uuid::Uuid::new_v4().to_string()),
                                vuln_type: "Server-Side Request Forgery (SSRF)".to_string(),
                                severity: Severity::Critical,
                                confidence: Confidence::High,
                                category: "SSRF".to_string(),
                                url: test_url.clone(),
                                parameter: Some(param_name.clone()),
                                payload: payload.to_string(),
                                description: format!(
                                    "SSRF vulnerability detected in parameter '{}'. The application makes requests to attacker-controlled URLs.",
                                    param_name
                                ),
                                evidence: Some("Internal service response detected".to_string()),
                                cwe: "CWE-918".to_string(),
                                cvss: 9.1,
                                verified: true,
                                false_positive: false,
                                remediation: "1. Validate and sanitize all URLs\n2. Use allowlists for permitted domains\n3. Disable unnecessary URL schemes (file://, gopher://)\n4. Implement network segmentation".to_string(),
                                discovered_at: chrono::Utc::now().to_rfc3339(),
                ml_confidence: None,
                ml_data: None,
                            };

                            vulnerabilities.push(vuln);
                            break; // Found SSRF, no need to test more payloads for this param
                        }
                    }
                    Err(e) => {
                        debug!("SSRF test failed: {}", e);
                    }
                }
            }
        }

        Ok((vulnerabilities, tests_run))
    }
}

// UUID generation
mod uuid {
    use rand::Rng;

    pub struct Uuid;

    impl Uuid {
        pub fn new_v4() -> Self {
            Self
        }

        pub fn to_string(&self) -> String {
            let mut rng = rand::rng();
            format!(
                "{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
                rng.random::<u32>(),
                rng.random::<u16>(),
                rng.random::<u16>(),
                rng.random::<u16>(),
                rng.random::<u64>() & 0xffffffffffff
            )
        }
    }
}

struct UrlData {
    base_url: String,
    parameters: Vec<(String, String)>,
}