@clearrecord/check 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/bin/check.js +1147 -203
- package/bin/thin-client.js +2 -2
- package/package.json +2 -2
package/bin/check.js
CHANGED
|
@@ -107,7 +107,7 @@ var require_path = __commonJS({
|
|
|
107
107
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
108
108
|
exports2.convertPosixPathToPattern = exports2.convertWindowsPathToPattern = exports2.convertPathToPattern = exports2.escapePosixPath = exports2.escapeWindowsPath = exports2.escape = exports2.removeLeadingDotSegment = exports2.makeAbsolute = exports2.unixify = void 0;
|
|
109
109
|
var os = require("os");
|
|
110
|
-
var
|
|
110
|
+
var path7 = require("path");
|
|
111
111
|
var IS_WINDOWS_PLATFORM = os.platform() === "win32";
|
|
112
112
|
var LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2;
|
|
113
113
|
var POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
|
|
@@ -119,7 +119,7 @@ var require_path = __commonJS({
|
|
|
119
119
|
}
|
|
120
120
|
exports2.unixify = unixify;
|
|
121
121
|
function makeAbsolute(cwd, filepath) {
|
|
122
|
-
return
|
|
122
|
+
return path7.resolve(cwd, filepath);
|
|
123
123
|
}
|
|
124
124
|
exports2.makeAbsolute = makeAbsolute;
|
|
125
125
|
function removeLeadingDotSegment(entry) {
|
|
@@ -1416,7 +1416,7 @@ var require_braces = __commonJS({
|
|
|
1416
1416
|
var require_constants2 = __commonJS({
|
|
1417
1417
|
"node_modules/micromatch/node_modules/picomatch/lib/constants.js"(exports2, module2) {
|
|
1418
1418
|
"use strict";
|
|
1419
|
-
var
|
|
1419
|
+
var path7 = require("path");
|
|
1420
1420
|
var WIN_SLASH = "\\\\/";
|
|
1421
1421
|
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
1422
1422
|
var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
@@ -1590,7 +1590,7 @@ var require_constants2 = __commonJS({
|
|
|
1590
1590
|
/* | */
|
|
1591
1591
|
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
1592
1592
|
/* \uFEFF */
|
|
1593
|
-
SEP:
|
|
1593
|
+
SEP: path7.sep,
|
|
1594
1594
|
/**
|
|
1595
1595
|
* Create EXTGLOB_CHARS
|
|
1596
1596
|
*/
|
|
@@ -1617,7 +1617,7 @@ var require_constants2 = __commonJS({
|
|
|
1617
1617
|
var require_utils2 = __commonJS({
|
|
1618
1618
|
"node_modules/micromatch/node_modules/picomatch/lib/utils.js"(exports2) {
|
|
1619
1619
|
"use strict";
|
|
1620
|
-
var
|
|
1620
|
+
var path7 = require("path");
|
|
1621
1621
|
var win32 = process.platform === "win32";
|
|
1622
1622
|
var {
|
|
1623
1623
|
REGEX_BACKSLASH,
|
|
@@ -1646,7 +1646,7 @@ var require_utils2 = __commonJS({
|
|
|
1646
1646
|
if (options && typeof options.windows === "boolean") {
|
|
1647
1647
|
return options.windows;
|
|
1648
1648
|
}
|
|
1649
|
-
return win32 === true ||
|
|
1649
|
+
return win32 === true || path7.sep === "\\";
|
|
1650
1650
|
};
|
|
1651
1651
|
exports2.escapeLast = (input, char, lastIdx) => {
|
|
1652
1652
|
const idx = input.lastIndexOf(char, lastIdx);
|
|
@@ -2510,9 +2510,9 @@ var require_parse2 = __commonJS({
|
|
|
2510
2510
|
const idx = prev.value.lastIndexOf("[");
|
|
2511
2511
|
const pre = prev.value.slice(0, idx);
|
|
2512
2512
|
const rest2 = prev.value.slice(idx + 2);
|
|
2513
|
-
const
|
|
2514
|
-
if (
|
|
2515
|
-
prev.value = pre +
|
|
2513
|
+
const posix2 = POSIX_REGEX_SOURCE[rest2];
|
|
2514
|
+
if (posix2) {
|
|
2515
|
+
prev.value = pre + posix2;
|
|
2516
2516
|
state.backtrack = true;
|
|
2517
2517
|
advance();
|
|
2518
2518
|
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
@@ -3010,7 +3010,7 @@ var require_parse2 = __commonJS({
|
|
|
3010
3010
|
var require_picomatch = __commonJS({
|
|
3011
3011
|
"node_modules/micromatch/node_modules/picomatch/lib/picomatch.js"(exports2, module2) {
|
|
3012
3012
|
"use strict";
|
|
3013
|
-
var
|
|
3013
|
+
var path7 = require("path");
|
|
3014
3014
|
var scan = require_scan();
|
|
3015
3015
|
var parse = require_parse2();
|
|
3016
3016
|
var utils = require_utils2();
|
|
@@ -3033,7 +3033,7 @@ var require_picomatch = __commonJS({
|
|
|
3033
3033
|
throw new TypeError("Expected pattern to be a non-empty string");
|
|
3034
3034
|
}
|
|
3035
3035
|
const opts = options || {};
|
|
3036
|
-
const
|
|
3036
|
+
const posix2 = utils.isWindows(options);
|
|
3037
3037
|
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
3038
3038
|
const state = regex.state;
|
|
3039
3039
|
delete regex.state;
|
|
@@ -3043,8 +3043,8 @@ var require_picomatch = __commonJS({
|
|
|
3043
3043
|
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
3044
3044
|
}
|
|
3045
3045
|
const matcher = (input, returnObject = false) => {
|
|
3046
|
-
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
|
3047
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
3046
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix: posix2 });
|
|
3047
|
+
const result = { glob, state, regex, posix: posix2, input, output, match, isMatch };
|
|
3048
3048
|
if (typeof opts.onResult === "function") {
|
|
3049
3049
|
opts.onResult(result);
|
|
3050
3050
|
}
|
|
@@ -3069,7 +3069,7 @@ var require_picomatch = __commonJS({
|
|
|
3069
3069
|
}
|
|
3070
3070
|
return matcher;
|
|
3071
3071
|
};
|
|
3072
|
-
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
3072
|
+
picomatch.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
|
|
3073
3073
|
if (typeof input !== "string") {
|
|
3074
3074
|
throw new TypeError("Expected input to be a string");
|
|
3075
3075
|
}
|
|
@@ -3077,7 +3077,7 @@ var require_picomatch = __commonJS({
|
|
|
3077
3077
|
return { isMatch: false, output: "" };
|
|
3078
3078
|
}
|
|
3079
3079
|
const opts = options || {};
|
|
3080
|
-
const format = opts.format || (
|
|
3080
|
+
const format = opts.format || (posix2 ? utils.toPosixSlashes : null);
|
|
3081
3081
|
let match = input === glob;
|
|
3082
3082
|
let output = match && format ? format(input) : input;
|
|
3083
3083
|
if (match === false) {
|
|
@@ -3086,16 +3086,16 @@ var require_picomatch = __commonJS({
|
|
|
3086
3086
|
}
|
|
3087
3087
|
if (match === false || opts.capture === true) {
|
|
3088
3088
|
if (opts.matchBase === true || opts.basename === true) {
|
|
3089
|
-
match = picomatch.matchBase(input, regex, options,
|
|
3089
|
+
match = picomatch.matchBase(input, regex, options, posix2);
|
|
3090
3090
|
} else {
|
|
3091
3091
|
match = regex.exec(output);
|
|
3092
3092
|
}
|
|
3093
3093
|
}
|
|
3094
3094
|
return { isMatch: Boolean(match), match, output };
|
|
3095
3095
|
};
|
|
3096
|
-
picomatch.matchBase = (input, glob, options,
|
|
3096
|
+
picomatch.matchBase = (input, glob, options, posix2 = utils.isWindows(options)) => {
|
|
3097
3097
|
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
|
3098
|
-
return regex.test(
|
|
3098
|
+
return regex.test(path7.basename(input));
|
|
3099
3099
|
};
|
|
3100
3100
|
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
3101
3101
|
picomatch.parse = (pattern, options) => {
|
|
@@ -3282,9 +3282,9 @@ var require_micromatch = __commonJS({
|
|
|
3282
3282
|
return [].concat(patterns).every((p) => picomatch(p, options)(str));
|
|
3283
3283
|
};
|
|
3284
3284
|
micromatch.capture = (glob, input, options) => {
|
|
3285
|
-
let
|
|
3285
|
+
let posix2 = utils.isWindows(options);
|
|
3286
3286
|
let regex = picomatch.makeRe(String(glob), { ...options, capture: true });
|
|
3287
|
-
let match = regex.exec(
|
|
3287
|
+
let match = regex.exec(posix2 ? utils.toPosixSlashes(input) : input);
|
|
3288
3288
|
if (match) {
|
|
3289
3289
|
return match.slice(1).map((v) => v === void 0 ? "" : v);
|
|
3290
3290
|
}
|
|
@@ -3322,7 +3322,7 @@ var require_pattern = __commonJS({
|
|
|
3322
3322
|
"use strict";
|
|
3323
3323
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3324
3324
|
exports2.isAbsolute = exports2.partitionAbsoluteAndRelative = exports2.removeDuplicateSlashes = exports2.matchAny = exports2.convertPatternsToRe = exports2.makeRe = exports2.getPatternParts = exports2.expandBraceExpansion = exports2.expandPatternsWithBraceExpansion = exports2.isAffectDepthOfReadingPattern = exports2.endsWithSlashGlobStar = exports2.hasGlobStar = exports2.getBaseDirectory = exports2.isPatternRelatedToParentDirectory = exports2.getPatternsOutsideCurrentDirectory = exports2.getPatternsInsideCurrentDirectory = exports2.getPositivePatterns = exports2.getNegativePatterns = exports2.isPositivePattern = exports2.isNegativePattern = exports2.convertToNegativePattern = exports2.convertToPositivePattern = exports2.isDynamicPattern = exports2.isStaticPattern = void 0;
|
|
3325
|
-
var
|
|
3325
|
+
var path7 = require("path");
|
|
3326
3326
|
var globParent = require_glob_parent();
|
|
3327
3327
|
var micromatch = require_micromatch();
|
|
3328
3328
|
var GLOBSTAR = "**";
|
|
@@ -3417,8 +3417,8 @@ var require_pattern = __commonJS({
|
|
|
3417
3417
|
}
|
|
3418
3418
|
exports2.endsWithSlashGlobStar = endsWithSlashGlobStar;
|
|
3419
3419
|
function isAffectDepthOfReadingPattern(pattern) {
|
|
3420
|
-
const
|
|
3421
|
-
return endsWithSlashGlobStar(pattern) || isStaticPattern(
|
|
3420
|
+
const basename3 = path7.basename(pattern);
|
|
3421
|
+
return endsWithSlashGlobStar(pattern) || isStaticPattern(basename3);
|
|
3422
3422
|
}
|
|
3423
3423
|
exports2.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
|
|
3424
3424
|
function expandPatternsWithBraceExpansion(patterns) {
|
|
@@ -3463,19 +3463,19 @@ var require_pattern = __commonJS({
|
|
|
3463
3463
|
exports2.removeDuplicateSlashes = removeDuplicateSlashes;
|
|
3464
3464
|
function partitionAbsoluteAndRelative(patterns) {
|
|
3465
3465
|
const absolute = [];
|
|
3466
|
-
const
|
|
3466
|
+
const relative2 = [];
|
|
3467
3467
|
for (const pattern of patterns) {
|
|
3468
3468
|
if (isAbsolute(pattern)) {
|
|
3469
3469
|
absolute.push(pattern);
|
|
3470
3470
|
} else {
|
|
3471
|
-
|
|
3471
|
+
relative2.push(pattern);
|
|
3472
3472
|
}
|
|
3473
3473
|
}
|
|
3474
|
-
return [absolute,
|
|
3474
|
+
return [absolute, relative2];
|
|
3475
3475
|
}
|
|
3476
3476
|
exports2.partitionAbsoluteAndRelative = partitionAbsoluteAndRelative;
|
|
3477
3477
|
function isAbsolute(pattern) {
|
|
3478
|
-
return
|
|
3478
|
+
return path7.isAbsolute(pattern);
|
|
3479
3479
|
}
|
|
3480
3480
|
exports2.isAbsolute = isAbsolute;
|
|
3481
3481
|
}
|
|
@@ -3652,8 +3652,8 @@ var require_utils3 = __commonJS({
|
|
|
3652
3652
|
exports2.errno = errno;
|
|
3653
3653
|
var fs3 = require_fs();
|
|
3654
3654
|
exports2.fs = fs3;
|
|
3655
|
-
var
|
|
3656
|
-
exports2.path =
|
|
3655
|
+
var path7 = require_path();
|
|
3656
|
+
exports2.path = path7;
|
|
3657
3657
|
var pattern = require_pattern();
|
|
3658
3658
|
exports2.pattern = pattern;
|
|
3659
3659
|
var stream = require_stream();
|
|
@@ -3765,8 +3765,8 @@ var require_async = __commonJS({
|
|
|
3765
3765
|
"use strict";
|
|
3766
3766
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3767
3767
|
exports2.read = void 0;
|
|
3768
|
-
function read(
|
|
3769
|
-
settings.fs.lstat(
|
|
3768
|
+
function read(path7, settings, callback) {
|
|
3769
|
+
settings.fs.lstat(path7, (lstatError, lstat) => {
|
|
3770
3770
|
if (lstatError !== null) {
|
|
3771
3771
|
callFailureCallback(callback, lstatError);
|
|
3772
3772
|
return;
|
|
@@ -3775,7 +3775,7 @@ var require_async = __commonJS({
|
|
|
3775
3775
|
callSuccessCallback(callback, lstat);
|
|
3776
3776
|
return;
|
|
3777
3777
|
}
|
|
3778
|
-
settings.fs.stat(
|
|
3778
|
+
settings.fs.stat(path7, (statError, stat) => {
|
|
3779
3779
|
if (statError !== null) {
|
|
3780
3780
|
if (settings.throwErrorOnBrokenSymbolicLink) {
|
|
3781
3781
|
callFailureCallback(callback, statError);
|
|
@@ -3807,13 +3807,13 @@ var require_sync = __commonJS({
|
|
|
3807
3807
|
"use strict";
|
|
3808
3808
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3809
3809
|
exports2.read = void 0;
|
|
3810
|
-
function read(
|
|
3811
|
-
const lstat = settings.fs.lstatSync(
|
|
3810
|
+
function read(path7, settings) {
|
|
3811
|
+
const lstat = settings.fs.lstatSync(path7);
|
|
3812
3812
|
if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
|
|
3813
3813
|
return lstat;
|
|
3814
3814
|
}
|
|
3815
3815
|
try {
|
|
3816
|
-
const stat = settings.fs.statSync(
|
|
3816
|
+
const stat = settings.fs.statSync(path7);
|
|
3817
3817
|
if (settings.markSymbolicLink) {
|
|
3818
3818
|
stat.isSymbolicLink = () => true;
|
|
3819
3819
|
}
|
|
@@ -3884,17 +3884,17 @@ var require_out = __commonJS({
|
|
|
3884
3884
|
var sync = require_sync();
|
|
3885
3885
|
var settings_1 = require_settings();
|
|
3886
3886
|
exports2.Settings = settings_1.default;
|
|
3887
|
-
function stat(
|
|
3887
|
+
function stat(path7, optionsOrSettingsOrCallback, callback) {
|
|
3888
3888
|
if (typeof optionsOrSettingsOrCallback === "function") {
|
|
3889
|
-
async.read(
|
|
3889
|
+
async.read(path7, getSettings(), optionsOrSettingsOrCallback);
|
|
3890
3890
|
return;
|
|
3891
3891
|
}
|
|
3892
|
-
async.read(
|
|
3892
|
+
async.read(path7, getSettings(optionsOrSettingsOrCallback), callback);
|
|
3893
3893
|
}
|
|
3894
3894
|
exports2.stat = stat;
|
|
3895
|
-
function statSync(
|
|
3895
|
+
function statSync(path7, optionsOrSettings) {
|
|
3896
3896
|
const settings = getSettings(optionsOrSettings);
|
|
3897
|
-
return sync.read(
|
|
3897
|
+
return sync.read(path7, settings);
|
|
3898
3898
|
}
|
|
3899
3899
|
exports2.statSync = statSync;
|
|
3900
3900
|
function getSettings(settingsOrOptions = {}) {
|
|
@@ -4110,16 +4110,16 @@ var require_async2 = __commonJS({
|
|
|
4110
4110
|
return;
|
|
4111
4111
|
}
|
|
4112
4112
|
const tasks = names.map((name) => {
|
|
4113
|
-
const
|
|
4113
|
+
const path7 = common.joinPathSegments(directory, name, settings.pathSegmentSeparator);
|
|
4114
4114
|
return (done) => {
|
|
4115
|
-
fsStat.stat(
|
|
4115
|
+
fsStat.stat(path7, settings.fsStatSettings, (error, stats) => {
|
|
4116
4116
|
if (error !== null) {
|
|
4117
4117
|
done(error);
|
|
4118
4118
|
return;
|
|
4119
4119
|
}
|
|
4120
4120
|
const entry = {
|
|
4121
4121
|
name,
|
|
4122
|
-
path:
|
|
4122
|
+
path: path7,
|
|
4123
4123
|
dirent: utils.fs.createDirentFromStats(name, stats)
|
|
4124
4124
|
};
|
|
4125
4125
|
if (settings.stats) {
|
|
@@ -4237,7 +4237,7 @@ var require_settings2 = __commonJS({
|
|
|
4237
4237
|
"node_modules/@nodelib/fs.scandir/out/settings.js"(exports2) {
|
|
4238
4238
|
"use strict";
|
|
4239
4239
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4240
|
-
var
|
|
4240
|
+
var path7 = require("path");
|
|
4241
4241
|
var fsStat = require_out();
|
|
4242
4242
|
var fs3 = require_fs4();
|
|
4243
4243
|
var Settings = class {
|
|
@@ -4245,7 +4245,7 @@ var require_settings2 = __commonJS({
|
|
|
4245
4245
|
this._options = _options;
|
|
4246
4246
|
this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
|
|
4247
4247
|
this.fs = fs3.createFileSystemAdapter(this._options.fs);
|
|
4248
|
-
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator,
|
|
4248
|
+
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path7.sep);
|
|
4249
4249
|
this.stats = this._getValue(this._options.stats, false);
|
|
4250
4250
|
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
|
4251
4251
|
this.fsStatSettings = new fsStat.Settings({
|
|
@@ -4272,17 +4272,17 @@ var require_out2 = __commonJS({
|
|
|
4272
4272
|
var sync = require_sync2();
|
|
4273
4273
|
var settings_1 = require_settings2();
|
|
4274
4274
|
exports2.Settings = settings_1.default;
|
|
4275
|
-
function scandir(
|
|
4275
|
+
function scandir(path7, optionsOrSettingsOrCallback, callback) {
|
|
4276
4276
|
if (typeof optionsOrSettingsOrCallback === "function") {
|
|
4277
|
-
async.read(
|
|
4277
|
+
async.read(path7, getSettings(), optionsOrSettingsOrCallback);
|
|
4278
4278
|
return;
|
|
4279
4279
|
}
|
|
4280
|
-
async.read(
|
|
4280
|
+
async.read(path7, getSettings(optionsOrSettingsOrCallback), callback);
|
|
4281
4281
|
}
|
|
4282
4282
|
exports2.scandir = scandir;
|
|
4283
|
-
function scandirSync(
|
|
4283
|
+
function scandirSync(path7, optionsOrSettings) {
|
|
4284
4284
|
const settings = getSettings(optionsOrSettings);
|
|
4285
|
-
return sync.read(
|
|
4285
|
+
return sync.read(path7, settings);
|
|
4286
4286
|
}
|
|
4287
4287
|
exports2.scandirSync = scandirSync;
|
|
4288
4288
|
function getSettings(settingsOrOptions = {}) {
|
|
@@ -4930,7 +4930,7 @@ var require_settings3 = __commonJS({
|
|
|
4930
4930
|
"node_modules/@nodelib/fs.walk/out/settings.js"(exports2) {
|
|
4931
4931
|
"use strict";
|
|
4932
4932
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
4933
|
-
var
|
|
4933
|
+
var path7 = require("path");
|
|
4934
4934
|
var fsScandir = require_out2();
|
|
4935
4935
|
var Settings = class {
|
|
4936
4936
|
constructor(_options = {}) {
|
|
@@ -4940,7 +4940,7 @@ var require_settings3 = __commonJS({
|
|
|
4940
4940
|
this.deepFilter = this._getValue(this._options.deepFilter, null);
|
|
4941
4941
|
this.entryFilter = this._getValue(this._options.entryFilter, null);
|
|
4942
4942
|
this.errorFilter = this._getValue(this._options.errorFilter, null);
|
|
4943
|
-
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator,
|
|
4943
|
+
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path7.sep);
|
|
4944
4944
|
this.fsScandirSettings = new fsScandir.Settings({
|
|
4945
4945
|
followSymbolicLinks: this._options.followSymbolicLinks,
|
|
4946
4946
|
fs: this._options.fs,
|
|
@@ -5002,7 +5002,7 @@ var require_reader2 = __commonJS({
|
|
|
5002
5002
|
"node_modules/fast-glob/out/readers/reader.js"(exports2) {
|
|
5003
5003
|
"use strict";
|
|
5004
5004
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5005
|
-
var
|
|
5005
|
+
var path7 = require("path");
|
|
5006
5006
|
var fsStat = require_out();
|
|
5007
5007
|
var utils = require_utils3();
|
|
5008
5008
|
var Reader = class {
|
|
@@ -5015,7 +5015,7 @@ var require_reader2 = __commonJS({
|
|
|
5015
5015
|
});
|
|
5016
5016
|
}
|
|
5017
5017
|
_getFullEntryPath(filepath) {
|
|
5018
|
-
return
|
|
5018
|
+
return path7.resolve(this._settings.cwd, filepath);
|
|
5019
5019
|
}
|
|
5020
5020
|
_makeEntry(stats, pattern) {
|
|
5021
5021
|
const entry = {
|
|
@@ -5431,7 +5431,7 @@ var require_provider = __commonJS({
|
|
|
5431
5431
|
"node_modules/fast-glob/out/providers/provider.js"(exports2) {
|
|
5432
5432
|
"use strict";
|
|
5433
5433
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
5434
|
-
var
|
|
5434
|
+
var path7 = require("path");
|
|
5435
5435
|
var deep_1 = require_deep();
|
|
5436
5436
|
var entry_1 = require_entry();
|
|
5437
5437
|
var error_1 = require_error();
|
|
@@ -5445,7 +5445,7 @@ var require_provider = __commonJS({
|
|
|
5445
5445
|
this.entryTransformer = new entry_2.default(this._settings);
|
|
5446
5446
|
}
|
|
5447
5447
|
_getRootDirectory(task) {
|
|
5448
|
-
return
|
|
5448
|
+
return path7.resolve(this._settings.cwd, task.base);
|
|
5449
5449
|
}
|
|
5450
5450
|
_getReaderOptions(task) {
|
|
5451
5451
|
const basePath = task.base === "." ? "" : task.base;
|
|
@@ -5736,19 +5736,19 @@ var require_out4 = __commonJS({
|
|
|
5736
5736
|
return utils.path.convertPathToPattern(source);
|
|
5737
5737
|
}
|
|
5738
5738
|
FastGlob2.convertPathToPattern = convertPathToPattern;
|
|
5739
|
-
let
|
|
5740
|
-
(function(
|
|
5739
|
+
let posix2;
|
|
5740
|
+
(function(posix3) {
|
|
5741
5741
|
function escapePath2(source) {
|
|
5742
5742
|
assertPatternsInput(source);
|
|
5743
5743
|
return utils.path.escapePosixPath(source);
|
|
5744
5744
|
}
|
|
5745
|
-
|
|
5745
|
+
posix3.escapePath = escapePath2;
|
|
5746
5746
|
function convertPathToPattern2(source) {
|
|
5747
5747
|
assertPatternsInput(source);
|
|
5748
5748
|
return utils.path.convertPosixPathToPattern(source);
|
|
5749
5749
|
}
|
|
5750
|
-
|
|
5751
|
-
})(
|
|
5750
|
+
posix3.convertPathToPattern = convertPathToPattern2;
|
|
5751
|
+
})(posix2 = FastGlob2.posix || (FastGlob2.posix = {}));
|
|
5752
5752
|
let win32;
|
|
5753
5753
|
(function(win322) {
|
|
5754
5754
|
function escapePath2(source) {
|
|
@@ -5790,11 +5790,12 @@ __export(local_cli_exports, {
|
|
|
5790
5790
|
parseCliArgs: () => parseCliArgs
|
|
5791
5791
|
});
|
|
5792
5792
|
module.exports = __toCommonJS(local_cli_exports);
|
|
5793
|
-
var
|
|
5793
|
+
var path6 = __toESM(require("path"));
|
|
5794
5794
|
var fs2 = __toESM(require("fs/promises"));
|
|
5795
5795
|
|
|
5796
5796
|
// src/engine.ts
|
|
5797
5797
|
var fs = __toESM(require("fs/promises"));
|
|
5798
|
+
var path5 = __toESM(require("path"));
|
|
5798
5799
|
|
|
5799
5800
|
// src/crawler.ts
|
|
5800
5801
|
var import_fast_glob = __toESM(require_out4());
|
|
@@ -5805,8 +5806,21 @@ var Crawler = class {
|
|
|
5805
5806
|
"**/node_modules/**",
|
|
5806
5807
|
"**/.next/**",
|
|
5807
5808
|
"**/.git/**",
|
|
5809
|
+
"**/.turbo/**",
|
|
5810
|
+
"**/.vercel/**",
|
|
5808
5811
|
"**/dist/**",
|
|
5809
|
-
"**/build/**"
|
|
5812
|
+
"**/build/**",
|
|
5813
|
+
"**/coverage/**",
|
|
5814
|
+
"**/out/**",
|
|
5815
|
+
"**/__tests__/**",
|
|
5816
|
+
"**/tests/**",
|
|
5817
|
+
"**/test/**",
|
|
5818
|
+
"**/__mocks__/**",
|
|
5819
|
+
"**/mocks/**",
|
|
5820
|
+
"**/fixtures/**",
|
|
5821
|
+
"**/*.test.*",
|
|
5822
|
+
"**/*.spec.*",
|
|
5823
|
+
"**/*.stories.*"
|
|
5810
5824
|
];
|
|
5811
5825
|
constructor(rootDir) {
|
|
5812
5826
|
this.rootDir = rootDir;
|
|
@@ -5817,24 +5831,40 @@ var Crawler = class {
|
|
|
5817
5831
|
"secret-scanner": [],
|
|
5818
5832
|
"billing-auditor": [],
|
|
5819
5833
|
"index-detector": [],
|
|
5820
|
-
"dependency-triage": []
|
|
5834
|
+
"dependency-triage": [],
|
|
5835
|
+
"route-auth-analyzer": []
|
|
5821
5836
|
};
|
|
5822
|
-
const allFiles = await (0, import_fast_glob.default)(
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5837
|
+
const allFiles = await (0, import_fast_glob.default)(
|
|
5838
|
+
["**/*.{ts,tsx,js,jsx,mjs,cjs,sql,prisma,json,toml}", "**/.env*"],
|
|
5839
|
+
{
|
|
5840
|
+
cwd: this.rootDir,
|
|
5841
|
+
ignore: this.ignorePatterns,
|
|
5842
|
+
absolute: true,
|
|
5843
|
+
dot: true
|
|
5844
|
+
}
|
|
5845
|
+
);
|
|
5827
5846
|
for (const filePath of allFiles) {
|
|
5828
|
-
const ext = import_path.default.extname(filePath);
|
|
5847
|
+
const ext = import_path.default.extname(filePath).toLowerCase();
|
|
5829
5848
|
const fileName = import_path.default.basename(filePath);
|
|
5849
|
+
const lowerFileName = fileName.toLowerCase();
|
|
5850
|
+
const normalized = filePath.replace(/\\/g, "/").toLowerCase();
|
|
5830
5851
|
if (ext === ".sql") {
|
|
5831
5852
|
manifest["rls-analyzer"].push(filePath);
|
|
5832
5853
|
manifest["index-detector"].push(filePath);
|
|
5833
5854
|
}
|
|
5834
|
-
if (
|
|
5855
|
+
if (ext === ".prisma") {
|
|
5856
|
+
manifest["index-detector"].push(filePath);
|
|
5857
|
+
}
|
|
5858
|
+
if ([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"].includes(ext)) {
|
|
5859
|
+
manifest["secret-scanner"].push(filePath);
|
|
5860
|
+
manifest["route-auth-analyzer"].push(filePath);
|
|
5861
|
+
} else if (/^\.env(?:\.[a-z0-9_-]+)?$/i.test(lowerFileName) && !/(?:example|template|sample)/i.test(lowerFileName)) {
|
|
5835
5862
|
manifest["secret-scanner"].push(filePath);
|
|
5836
5863
|
}
|
|
5837
|
-
if (
|
|
5864
|
+
if (lowerFileName === "config.toml" && normalized.includes("supabase")) {
|
|
5865
|
+
manifest["route-auth-analyzer"].push(filePath);
|
|
5866
|
+
}
|
|
5867
|
+
if (normalized.includes("webhook")) {
|
|
5838
5868
|
manifest["billing-auditor"].push(filePath);
|
|
5839
5869
|
}
|
|
5840
5870
|
if (fileName === "package.json") {
|
|
@@ -5913,101 +5943,231 @@ ${f.remediation.fixScript}
|
|
|
5913
5943
|
};
|
|
5914
5944
|
|
|
5915
5945
|
// src/analyzers/rls-analyzer.ts
|
|
5946
|
+
var IGNORED_SYSTEM_TABLES = /* @__PURE__ */ new Set([
|
|
5947
|
+
"_prisma_migrations",
|
|
5948
|
+
"__drizzle_migrations",
|
|
5949
|
+
"schema_migrations"
|
|
5950
|
+
]);
|
|
5951
|
+
var PUBLIC_CATALOG_TABLES = /* @__PURE__ */ new Set([
|
|
5952
|
+
"plans",
|
|
5953
|
+
"products",
|
|
5954
|
+
"prices",
|
|
5955
|
+
"categories",
|
|
5956
|
+
"tags",
|
|
5957
|
+
"countries"
|
|
5958
|
+
]);
|
|
5959
|
+
var SERVER_ONLY_DENY_ALL_TABLES = /* @__PURE__ */ new Set([
|
|
5960
|
+
"customers",
|
|
5961
|
+
"webhook_events",
|
|
5962
|
+
"stripe_events",
|
|
5963
|
+
"audit_logs",
|
|
5964
|
+
"rate_limits"
|
|
5965
|
+
]);
|
|
5966
|
+
function stripSqlCommentsPreservingLines(sql) {
|
|
5967
|
+
const withoutBlock = sql.replace(
|
|
5968
|
+
/\/\*[\s\S]*?\*\//g,
|
|
5969
|
+
(block) => block.replace(/[^\r\n]/g, " ")
|
|
5970
|
+
);
|
|
5971
|
+
return withoutBlock.split(/\r?\n/).map((line) => line.replace(/--.*$/, "")).join("\n");
|
|
5972
|
+
}
|
|
5973
|
+
function getLineNumberAtIndex(content, index) {
|
|
5974
|
+
return content.slice(0, Math.max(0, index)).split(/\r?\n/).length;
|
|
5975
|
+
}
|
|
5916
5976
|
var RlsAnalyzer = class {
|
|
5917
5977
|
async analyze(filePath, content) {
|
|
5978
|
+
return this.analyzeMigrationSuite([{ filePath, content }]);
|
|
5979
|
+
}
|
|
5980
|
+
analyzeMigrationSuite(files, options) {
|
|
5981
|
+
if (options?.isNonSupabaseOrmOnly || files.length === 0) {
|
|
5982
|
+
return [];
|
|
5983
|
+
}
|
|
5918
5984
|
const findings = [];
|
|
5919
|
-
const
|
|
5920
|
-
const
|
|
5921
|
-
const
|
|
5922
|
-
const
|
|
5923
|
-
const
|
|
5924
|
-
const
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
const
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5985
|
+
const createdTables = /* @__PURE__ */ new Map();
|
|
5986
|
+
const rlsEnabledTables = /* @__PURE__ */ new Map();
|
|
5987
|
+
const intentionalNoPolicyTables = /* @__PURE__ */ new Set();
|
|
5988
|
+
const policyTables = /* @__PURE__ */ new Set();
|
|
5989
|
+
const permissivePolicies = [];
|
|
5990
|
+
for (const { filePath, content } of files) {
|
|
5991
|
+
const rawLines = content.split(/\r?\n/);
|
|
5992
|
+
const sqlClean = stripSqlCommentsPreservingLines(content);
|
|
5993
|
+
const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:([a-zA-Z0-9_]+)\.)?["`]?([a-zA-Z0-9_]+)["`]?/gi;
|
|
5994
|
+
let ctMatch;
|
|
5995
|
+
while ((ctMatch = createTableRegex.exec(sqlClean)) !== null) {
|
|
5996
|
+
const schemaName = (ctMatch[1] || "public").toLowerCase();
|
|
5997
|
+
const rawName = ctMatch[2] || "";
|
|
5998
|
+
const tbl = rawName.toLowerCase();
|
|
5999
|
+
if (schemaName === "public" && tbl && !IGNORED_SYSTEM_TABLES.has(tbl)) {
|
|
6000
|
+
if (!createdTables.has(tbl)) {
|
|
6001
|
+
createdTables.set(tbl, {
|
|
6002
|
+
rawName,
|
|
6003
|
+
filePath,
|
|
6004
|
+
line: getLineNumberAtIndex(sqlClean, ctMatch.index)
|
|
6005
|
+
});
|
|
6006
|
+
}
|
|
6007
|
+
}
|
|
5935
6008
|
}
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
6009
|
+
const enableRlsRegex = /ALTER\s+TABLE\s+(?:ONLY\s+)?(?:IF\s+EXISTS\s+)?(?:([a-zA-Z0-9_]+)\.)?["`]?([a-zA-Z0-9_]+)["`]?\s+ENABLE\s+ROW\s+LEVEL\s+SECURITY/gi;
|
|
6010
|
+
let rlsMatch;
|
|
6011
|
+
while ((rlsMatch = enableRlsRegex.exec(sqlClean)) !== null) {
|
|
6012
|
+
const schemaName = (rlsMatch[1] || "public").toLowerCase();
|
|
6013
|
+
const rawName = rlsMatch[2] || "";
|
|
6014
|
+
const tbl = rawName.toLowerCase();
|
|
6015
|
+
if (schemaName === "public" && tbl && !rlsEnabledTables.has(tbl)) {
|
|
6016
|
+
const line = getLineNumberAtIndex(sqlClean, rlsMatch.index);
|
|
6017
|
+
rlsEnabledTables.set(tbl, {
|
|
6018
|
+
rawName,
|
|
6019
|
+
filePath,
|
|
6020
|
+
line
|
|
6021
|
+
});
|
|
6022
|
+
const nearbyRaw = rawLines.slice(Math.max(0, line - 6), Math.min(rawLines.length, line + 4)).join("\n");
|
|
6023
|
+
if (/no\s+policies|private\s+table|service_role\s+only/i.test(nearbyRaw)) {
|
|
6024
|
+
intentionalNoPolicyTables.add(tbl);
|
|
6025
|
+
}
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
const policyStmtRegex = /CREATE\s+POLICY\s+([^;]+?)\bON\s+(?:([a-zA-Z0-9_]+)\.)?["`]?([a-zA-Z0-9_]+)["`]?([^;]*);/gis;
|
|
6029
|
+
const paddedSql = `${sqlClean};`;
|
|
6030
|
+
let polMatch;
|
|
6031
|
+
while ((polMatch = policyStmtRegex.exec(paddedSql)) !== null) {
|
|
6032
|
+
const polName = polMatch[1] || "";
|
|
6033
|
+
const schemaName = (polMatch[2] || "public").toLowerCase();
|
|
6034
|
+
const rawName = polMatch[3] || "";
|
|
6035
|
+
const tbl = rawName.toLowerCase();
|
|
6036
|
+
const polBody = polMatch[4] || "";
|
|
6037
|
+
if (schemaName !== "public" || !tbl) continue;
|
|
6038
|
+
policyTables.add(tbl);
|
|
6039
|
+
const hasToServiceRole = /\bTO\s+service_role\b/i.test(polBody);
|
|
6040
|
+
const hasToPublicSelect = /\bFOR\s+SELECT\s+TO\s+public\b/i.test(polBody);
|
|
6041
|
+
const hasTrueExpr = /\b(?:USING|WITH\s+CHECK)\s*\(\s*true\s*\)/i.test(polBody);
|
|
6042
|
+
const isReadOnlySelect = /\bFOR\s+SELECT\b/i.test(polBody);
|
|
6043
|
+
const isServiceNamedWithoutRole = /service[_\s-]?role/i.test(polName) && !hasToServiceRole;
|
|
6044
|
+
const isPermissive = hasToPublicSelect || hasTrueExpr && !hasToServiceRole && (!isReadOnlySelect || !PUBLIC_CATALOG_TABLES.has(tbl) || isServiceNamedWithoutRole);
|
|
6045
|
+
if (isPermissive) {
|
|
6046
|
+
permissivePolicies.push({
|
|
6047
|
+
rawName,
|
|
6048
|
+
filePath,
|
|
6049
|
+
line: getLineNumberAtIndex(sqlClean, polMatch.index),
|
|
6050
|
+
isToPublic: hasToPublicSelect
|
|
6051
|
+
});
|
|
6052
|
+
}
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6055
|
+
for (const [tbl, info] of createdTables.entries()) {
|
|
6056
|
+
if (!rlsEnabledTables.has(tbl)) {
|
|
5939
6057
|
findings.push({
|
|
5940
6058
|
id: "CR-ARCH-02",
|
|
5941
6059
|
moduleId: "rls-analyzer",
|
|
5942
6060
|
title: "Anonymous Table Dump",
|
|
5943
6061
|
severity: "CRITICAL",
|
|
5944
|
-
cvssScore: 9.
|
|
6062
|
+
cvssScore: 9.5,
|
|
5945
6063
|
location: {
|
|
5946
|
-
filePath,
|
|
5947
|
-
startLine:
|
|
5948
|
-
endLine:
|
|
6064
|
+
filePath: info.filePath,
|
|
6065
|
+
startLine: info.line,
|
|
6066
|
+
endLine: info.line,
|
|
5949
6067
|
startCol: 1,
|
|
5950
6068
|
endCol: 100,
|
|
5951
|
-
snippet: `CREATE TABLE public.${
|
|
6069
|
+
snippet: `CREATE TABLE public.${info.rawName}`
|
|
5952
6070
|
},
|
|
5953
6071
|
analysis: {
|
|
5954
|
-
description: `The '${
|
|
5955
|
-
aiContrast: "Generic LLMs often assume RLS is handled globally
|
|
5956
|
-
empiricalProof: `curl -X GET 'https://[PROJECT].supabase.co/rest/v1/${
|
|
6072
|
+
description: `The '${info.rawName}' table is created without Row Level Security enabled across SQL migrations.`,
|
|
6073
|
+
aiContrast: "Generic LLMs often assume RLS is handled globally or check a single file in isolation.",
|
|
6074
|
+
empiricalProof: `curl -X GET 'https://[PROJECT].supabase.co/rest/v1/${info.rawName}?select=*' -H 'apikey: [ANON_KEY]'`
|
|
5957
6075
|
},
|
|
5958
6076
|
remediation: {
|
|
5959
6077
|
summary: "Enable RLS and restrict access to authenticated users.",
|
|
5960
|
-
fixScript: `ALTER TABLE public.${
|
|
5961
|
-
CREATE POLICY "Users can read own" ON public.${
|
|
5962
|
-
prTitle: `Security: Enable RLS on ${
|
|
6078
|
+
fixScript: `ALTER TABLE public.${info.rawName} ENABLE ROW LEVEL SECURITY;
|
|
6079
|
+
CREATE POLICY "Users can read own" ON public.${info.rawName} FOR SELECT TO authenticated USING (auth.uid() = id);`,
|
|
6080
|
+
prTitle: `Security: Enable RLS on ${info.rawName} table`
|
|
5963
6081
|
},
|
|
5964
6082
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
5965
6083
|
});
|
|
5966
|
-
}
|
|
5967
|
-
|
|
6084
|
+
}
|
|
6085
|
+
}
|
|
6086
|
+
for (const [tbl, info] of rlsEnabledTables.entries()) {
|
|
6087
|
+
const isIntentionalDenyAll = intentionalNoPolicyTables.has(tbl) || policyTables.size > 0 && SERVER_ONLY_DENY_ALL_TABLES.has(tbl);
|
|
6088
|
+
if (!policyTables.has(tbl) && !isIntentionalDenyAll) {
|
|
5968
6089
|
findings.push({
|
|
5969
6090
|
id: "CR-ARCH-03",
|
|
5970
6091
|
moduleId: "rls-analyzer",
|
|
5971
|
-
title: "
|
|
5972
|
-
severity: "
|
|
5973
|
-
cvssScore: 8.
|
|
6092
|
+
title: "RLS Enabled Without Policy (CVE-2025-48757 Zero-Policy Trap)",
|
|
6093
|
+
severity: "HIGH",
|
|
6094
|
+
cvssScore: 8.8,
|
|
5974
6095
|
location: {
|
|
5975
|
-
filePath,
|
|
5976
|
-
startLine:
|
|
5977
|
-
endLine:
|
|
6096
|
+
filePath: info.filePath,
|
|
6097
|
+
startLine: info.line,
|
|
6098
|
+
endLine: info.line,
|
|
5978
6099
|
startCol: 1,
|
|
5979
6100
|
endCol: 100,
|
|
5980
|
-
snippet: `
|
|
6101
|
+
snippet: `ALTER TABLE public.${info.rawName} ENABLE ROW LEVEL SECURITY (0 policies)`
|
|
5981
6102
|
},
|
|
5982
6103
|
analysis: {
|
|
5983
|
-
description: `The '${
|
|
5984
|
-
aiContrast: "
|
|
5985
|
-
empiricalProof: `
|
|
6104
|
+
description: `The '${info.rawName}' table enables RLS without defining explicit CREATE POLICY rules across SQL migrations.`,
|
|
6105
|
+
aiContrast: "Many scanners stop once ENABLE ROW LEVEL SECURITY appears, missing incomplete policy coverage.",
|
|
6106
|
+
empiricalProof: `SELECT tablename, policyname FROM pg_policies WHERE tablename = '${info.rawName}';`
|
|
5986
6107
|
},
|
|
5987
6108
|
remediation: {
|
|
5988
|
-
summary: "
|
|
5989
|
-
fixScript: `
|
|
5990
|
-
|
|
5991
|
-
prTitle: `Security: Restrict ${table} access to authenticated users`
|
|
6109
|
+
summary: "Define explicit authenticated tenant policies on the RLS-enabled table.",
|
|
6110
|
+
fixScript: `CREATE POLICY "Authenticated Read" ON public.${info.rawName} FOR SELECT TO authenticated USING (auth.uid() = user_id);`,
|
|
6111
|
+
prTitle: `Security: Add explicit RLS policies to ${info.rawName}`
|
|
5992
6112
|
},
|
|
5993
6113
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
5994
6114
|
});
|
|
5995
6115
|
}
|
|
5996
6116
|
}
|
|
6117
|
+
for (const perm of permissivePolicies) {
|
|
6118
|
+
findings.push({
|
|
6119
|
+
id: "CR-ARCH-03",
|
|
6120
|
+
moduleId: "rls-analyzer",
|
|
6121
|
+
title: "Publicly Accessible Data",
|
|
6122
|
+
severity: "CRITICAL",
|
|
6123
|
+
cvssScore: 9.1,
|
|
6124
|
+
location: {
|
|
6125
|
+
filePath: perm.filePath,
|
|
6126
|
+
startLine: perm.line,
|
|
6127
|
+
endLine: perm.line,
|
|
6128
|
+
startCol: 1,
|
|
6129
|
+
endCol: 100,
|
|
6130
|
+
snippet: perm.isToPublic ? "CREATE POLICY ... TO public" : "CREATE POLICY ... USING (true)"
|
|
6131
|
+
},
|
|
6132
|
+
analysis: {
|
|
6133
|
+
description: `The '${perm.rawName}' table has an overly permissive RLS policy (TO public or USING (true) without TO service_role).`,
|
|
6134
|
+
aiContrast: "Agents see a policy exists and assume it is secure without inspecting role and predicate bounds.",
|
|
6135
|
+
empiricalProof: `curl -X GET 'https://[PROJECT].supabase.co/rest/v1/${perm.rawName}?select=*' -H 'apikey: [ANON_KEY]'`
|
|
6136
|
+
},
|
|
6137
|
+
remediation: {
|
|
6138
|
+
summary: "Restrict the policy to authenticated users or service_role only.",
|
|
6139
|
+
fixScript: `DROP POLICY IF EXISTS "Public Read" ON public.${perm.rawName};
|
|
6140
|
+
CREATE POLICY "Authenticated Read" ON public.${perm.rawName} FOR SELECT TO authenticated USING (auth.uid() = user_id);`,
|
|
6141
|
+
prTitle: `Security: Restrict ${perm.rawName} access to authenticated users`
|
|
6142
|
+
},
|
|
6143
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6144
|
+
});
|
|
6145
|
+
}
|
|
5997
6146
|
return findings;
|
|
5998
6147
|
}
|
|
5999
6148
|
};
|
|
6000
6149
|
|
|
6001
6150
|
// src/analyzers/secret-scanner.ts
|
|
6151
|
+
var import_path2 = __toESM(require("path"));
|
|
6002
6152
|
var SecretScanner = class {
|
|
6003
6153
|
secretPatterns = [
|
|
6154
|
+
{
|
|
6155
|
+
id: "CR-SEC-01",
|
|
6156
|
+
title: "Google / Firebase Server API Key Leak",
|
|
6157
|
+
regex: /AIza[0-9A-Za-z_-]{35}/g,
|
|
6158
|
+
severity: "HIGH",
|
|
6159
|
+
cvssScore: 7.5,
|
|
6160
|
+
aiContrast: "AI helpers rarely check whether an AIza key is unrestricted in frontend JS.",
|
|
6161
|
+
empiricalProof: 'curl "https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=AIza..."',
|
|
6162
|
+
remediation: "Restrict HTTP referrers / APIs in GCP Console or move key to a server-only env var."
|
|
6163
|
+
},
|
|
6004
6164
|
{
|
|
6005
6165
|
id: "CR-SEC-02",
|
|
6006
6166
|
title: "Supabase Service Role Leak",
|
|
6007
|
-
regex: /sb_admin_[a-zA-Z0-9]
|
|
6167
|
+
regex: /(?:sb_admin_[a-zA-Z0-9]+|sb_secret_[a-zA-Z0-9_-]{16,}|SUPABASE_SERVICE_ROLE_KEY\s*[:=]\s*['"](?:eyJ[a-zA-Z0-9_-]+|sb_admin_[a-zA-Z0-9]+|sb_secret_[a-zA-Z0-9_-]+|[^'"]{24,})['"])/g,
|
|
6008
6168
|
severity: "CRITICAL",
|
|
6009
6169
|
cvssScore: 9.8,
|
|
6010
|
-
aiContrast: "General LLMs often ignore strings starting with sb_admin_ as they look like internal IDs. They fail to recognize this as the bypass-all-RLS master key.",
|
|
6170
|
+
aiContrast: "General LLMs often ignore strings starting with sb_admin_ / sb_secret_ as they look like internal IDs. They fail to recognize this as the bypass-all-RLS master key.",
|
|
6011
6171
|
empiricalProof: "curl -X GET 'https://[PROJECT].supabase.co/rest/v1/any_table?select=*' -H 'apikey: [SERVICE_ROLE_KEY]'",
|
|
6012
6172
|
remediation: "Move this key to a server-side .env file and never expose it to the client bundle."
|
|
6013
6173
|
},
|
|
@@ -6020,20 +6180,64 @@ var SecretScanner = class {
|
|
|
6020
6180
|
aiContrast: 'AI agents may see "sk_live" and assume it is a configuration constant. They fail to flag it as an immediate financial risk.',
|
|
6021
6181
|
empiricalProof: "curl https://api.stripe.com/v1/charges -u sk_live_...:",
|
|
6022
6182
|
remediation: "Immediately rotate this key in the Stripe Dashboard and move it to a secure secret manager."
|
|
6183
|
+
},
|
|
6184
|
+
{
|
|
6185
|
+
id: "CR-SEC-04",
|
|
6186
|
+
title: "AWS IAM Access Key ID Leak",
|
|
6187
|
+
regex: /AKIA(?!IOSFODNN7EXAMPLE)[0-9A-Z]{16}/g,
|
|
6188
|
+
severity: "CRITICAL",
|
|
6189
|
+
cvssScore: 9,
|
|
6190
|
+
aiContrast: "Long-lived AKIA credentials grant programmatic AWS S3/IAM access if leaked in git.",
|
|
6191
|
+
empiricalProof: "aws sts get-caller-identity with extracted AKIA access key",
|
|
6192
|
+
remediation: "Revoke the IAM access key immediately in AWS IAM and adopt short-lived OIDC roles."
|
|
6193
|
+
},
|
|
6194
|
+
{
|
|
6195
|
+
id: "CR-SEC-05",
|
|
6196
|
+
title: "RSA / PEM Private Key Leak",
|
|
6197
|
+
regex: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/g,
|
|
6198
|
+
severity: "CRITICAL",
|
|
6199
|
+
cvssScore: 9.5,
|
|
6200
|
+
aiContrast: "Private cryptographic keys inside source files allow token forgery or MITM compromise.",
|
|
6201
|
+
empiricalProof: "PEM private key header committed directly in repository",
|
|
6202
|
+
remediation: "Remove PEM block from repository, rotate the signing key, and inject via KMS / secret manager."
|
|
6203
|
+
},
|
|
6204
|
+
{
|
|
6205
|
+
id: "CR-SEC-06",
|
|
6206
|
+
title: "Client-Exposed Secret Env Prefix (NEXT_PUBLIC_ / VITE_)",
|
|
6207
|
+
regex: /(?:NEXT_PUBLIC_|VITE_)[A-Z0-9_]*(?:SERVICE_ROLE|SECRET_KEY|SECRET|WEBHOOK_SECRET|PRIVATE_KEY|PRIVATE|ADMIN_KEY)[A-Z0-9_]*/g,
|
|
6208
|
+
severity: "CRITICAL",
|
|
6209
|
+
cvssScore: 9.3,
|
|
6210
|
+
aiContrast: "Frameworks inline NEXT_PUBLIC_* and VITE_* variables verbatim into browser bundles.",
|
|
6211
|
+
empiricalProof: "Any visitor can inspect compiled browser JS chunks to read the credential.",
|
|
6212
|
+
remediation: "Remove the NEXT_PUBLIC_ / VITE_ prefix so the key stays strictly on the server."
|
|
6023
6213
|
}
|
|
6024
6214
|
];
|
|
6025
6215
|
async analyze(filePath, content) {
|
|
6026
6216
|
const findings = [];
|
|
6027
|
-
|
|
6217
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
6218
|
+
const baseName = import_path2.default.basename(normalized);
|
|
6219
|
+
const lowerBaseName = baseName.toLowerCase();
|
|
6220
|
+
if (/(?:^|\/)(?:__tests__|tests?|__mocks__|mocks?|fixtures?)\//i.test(normalized) || /\.(?:test|spec|stories)\.[jt]sx?$/i.test(normalized)) {
|
|
6028
6221
|
return [];
|
|
6029
6222
|
}
|
|
6223
|
+
const isEnvTemplateFile = lowerBaseName.includes(".env") && /(?:example|template|sample)/i.test(lowerBaseName);
|
|
6224
|
+
if (isEnvTemplateFile) {
|
|
6225
|
+
return [];
|
|
6226
|
+
}
|
|
6227
|
+
const isTrackedDotEnvSecretFile = /^\.env(?:\.[a-z0-9_-]+)?$/i.test(lowerBaseName) && !isEnvTemplateFile;
|
|
6228
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, (b) => b.replace(/[^\r\n]/g, " ")).replace(/\/\/.*$/gm, "");
|
|
6229
|
+
const isClientComponentFile = /^\s*['"]use client['"]/m.test(codeOnly);
|
|
6030
6230
|
for (const pattern of this.secretPatterns) {
|
|
6231
|
+
if (pattern.id === "CR-SEC-01" && content.includes("authDomain") && content.includes("projectId")) {
|
|
6232
|
+
continue;
|
|
6233
|
+
}
|
|
6031
6234
|
const matches = content.matchAll(pattern.regex);
|
|
6032
6235
|
for (const match of matches) {
|
|
6033
6236
|
const secret = match[0];
|
|
6034
6237
|
if (secret.toUpperCase().includes("EXAMPLE")) {
|
|
6035
6238
|
continue;
|
|
6036
6239
|
}
|
|
6240
|
+
const line = this.getLineNumber(content, match.index ?? 0);
|
|
6037
6241
|
findings.push({
|
|
6038
6242
|
id: pattern.id,
|
|
6039
6243
|
moduleId: "secret-scanner",
|
|
@@ -6042,8 +6246,8 @@ var SecretScanner = class {
|
|
|
6042
6246
|
cvssScore: pattern.cvssScore,
|
|
6043
6247
|
location: {
|
|
6044
6248
|
filePath,
|
|
6045
|
-
startLine:
|
|
6046
|
-
endLine: this.getLineNumber(content, match.index + secret.length),
|
|
6249
|
+
startLine: line,
|
|
6250
|
+
endLine: this.getLineNumber(content, (match.index ?? 0) + secret.length),
|
|
6047
6251
|
startCol: 1,
|
|
6048
6252
|
endCol: 100,
|
|
6049
6253
|
snippet: secret
|
|
@@ -6055,13 +6259,115 @@ var SecretScanner = class {
|
|
|
6055
6259
|
},
|
|
6056
6260
|
remediation: {
|
|
6057
6261
|
summary: pattern.remediation,
|
|
6058
|
-
fixScript: "// Remove hardcoded secret and
|
|
6262
|
+
fixScript: "// Remove hardcoded secret and load from server-only environment variable",
|
|
6059
6263
|
prTitle: `Security: Remove leaked secret from ${filePath}`
|
|
6060
6264
|
},
|
|
6061
6265
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6062
6266
|
});
|
|
6063
6267
|
}
|
|
6064
6268
|
}
|
|
6269
|
+
const hasAlreadyFlaggedSec02 = findings.some((f) => f.id === "CR-SEC-02");
|
|
6270
|
+
if (!hasAlreadyFlaggedSec02) {
|
|
6271
|
+
const trackedEnvMatch = isTrackedDotEnvSecretFile ? content.match(/^\s*(?:export\s+)?SUPABASE_SERVICE_ROLE_KEY\s*=\s*\S+/m) : null;
|
|
6272
|
+
const clientRefMatch = isClientComponentFile ? codeOnly.match(
|
|
6273
|
+
/(?:process\.env|import\.meta\.env)(?:\.SUPABASE_SERVICE_ROLE_KEY|\[\s*['"]SUPABASE_SERVICE_ROLE_KEY['"]\s*\])/i
|
|
6274
|
+
) : null;
|
|
6275
|
+
const leakMatch = trackedEnvMatch || clientRefMatch;
|
|
6276
|
+
if (leakMatch && leakMatch.index !== void 0) {
|
|
6277
|
+
const line = this.getLineNumber(content, leakMatch.index);
|
|
6278
|
+
findings.push({
|
|
6279
|
+
id: "CR-SEC-02",
|
|
6280
|
+
moduleId: "secret-scanner",
|
|
6281
|
+
title: "Supabase Service Role Leak",
|
|
6282
|
+
severity: "CRITICAL",
|
|
6283
|
+
cvssScore: 9.8,
|
|
6284
|
+
location: {
|
|
6285
|
+
filePath,
|
|
6286
|
+
startLine: line,
|
|
6287
|
+
endLine: line,
|
|
6288
|
+
startCol: 1,
|
|
6289
|
+
endCol: 100,
|
|
6290
|
+
snippet: leakMatch[0].trim()
|
|
6291
|
+
},
|
|
6292
|
+
analysis: {
|
|
6293
|
+
description: 'SUPABASE_SERVICE_ROLE_KEY is committed in a tracked .env file or referenced directly inside a "use client" component.',
|
|
6294
|
+
aiContrast: "Client-bundled or git-tracked service role keys grant full RLS bypass across all tables.",
|
|
6295
|
+
empiricalProof: "curl -X GET 'https://[PROJECT].supabase.co/rest/v1/any_table?select=*' -H 'apikey: [SERVICE_ROLE_KEY]'"
|
|
6296
|
+
},
|
|
6297
|
+
remediation: {
|
|
6298
|
+
summary: "Keep SUPABASE_SERVICE_ROLE_KEY strictly in gitignored server environment variables with server-only module guards.",
|
|
6299
|
+
fixScript: "import 'server-only';",
|
|
6300
|
+
prTitle: `Security: Isolate SUPABASE_SERVICE_ROLE_KEY from client/git in ${filePath}`
|
|
6301
|
+
},
|
|
6302
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6303
|
+
});
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
if (/\.(?:ts|tsx|js|jsx|mjs|cjs)$/i.test(baseName)) {
|
|
6307
|
+
const dangerousBrowserMatch = codeOnly.match(/dangerouslyAllowBrowser\s*:\s*true/);
|
|
6308
|
+
const clientAiMatch = isClientComponentFile ? codeOnly.match(/\bnew\s+(?:OpenAI|Anthropic)\s*\(/) : null;
|
|
6309
|
+
const aiLeakMatch = dangerousBrowserMatch || clientAiMatch;
|
|
6310
|
+
if (aiLeakMatch && aiLeakMatch.index !== void 0) {
|
|
6311
|
+
const line = this.getLineNumber(codeOnly, aiLeakMatch.index);
|
|
6312
|
+
findings.push({
|
|
6313
|
+
id: "CR-SEC-07",
|
|
6314
|
+
moduleId: "secret-scanner",
|
|
6315
|
+
title: "Browser-Exposed AI SDK (dangerouslyAllowBrowser)",
|
|
6316
|
+
severity: "CRITICAL",
|
|
6317
|
+
cvssScore: 9,
|
|
6318
|
+
location: {
|
|
6319
|
+
filePath,
|
|
6320
|
+
startLine: line,
|
|
6321
|
+
endLine: line,
|
|
6322
|
+
startCol: 1,
|
|
6323
|
+
endCol: 100,
|
|
6324
|
+
snippet: aiLeakMatch[0]
|
|
6325
|
+
},
|
|
6326
|
+
analysis: {
|
|
6327
|
+
description: "OpenAI or Anthropic SDK is instantiated in a browser client component or with dangerouslyAllowBrowser: true.",
|
|
6328
|
+
aiContrast: "Shipping dangerouslyAllowBrowser: true exposes your OpenAI/Anthropic billing key to every visitor.",
|
|
6329
|
+
empiricalProof: "Browser network tab exposes Authorization: Bearer sk-... on client LLM calls."
|
|
6330
|
+
},
|
|
6331
|
+
remediation: {
|
|
6332
|
+
summary: "Move AI SDK calls into a Next.js App Router API Route (/api/ai) and remove dangerouslyAllowBrowser.",
|
|
6333
|
+
fixScript: "// Move OpenAI/Anthropic SDK instantiation to server-only route.ts",
|
|
6334
|
+
prTitle: `Security: Move browser-exposed AI SDK to server route in ${filePath}`
|
|
6335
|
+
},
|
|
6336
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6337
|
+
});
|
|
6338
|
+
}
|
|
6339
|
+
const rawSqlRegex = /\$(?:queryRawUnsafe|executeRawUnsafe)\s*\(|\.(?:query|execute)\s*\(\s*`[^`]*(?:SELECT|INSERT|UPDATE|DELETE)[^`]*\$\{/i;
|
|
6340
|
+
const sqlMatch = codeOnly.match(rawSqlRegex);
|
|
6341
|
+
if (sqlMatch && sqlMatch.index !== void 0) {
|
|
6342
|
+
const line = this.getLineNumber(codeOnly, sqlMatch.index);
|
|
6343
|
+
findings.push({
|
|
6344
|
+
id: "CR-DB-01",
|
|
6345
|
+
moduleId: "rls-analyzer",
|
|
6346
|
+
title: "Unparameterized Raw SQL Query / Injection Vector",
|
|
6347
|
+
severity: "CRITICAL",
|
|
6348
|
+
cvssScore: 9.4,
|
|
6349
|
+
location: {
|
|
6350
|
+
filePath,
|
|
6351
|
+
startLine: line,
|
|
6352
|
+
endLine: line,
|
|
6353
|
+
startCol: 1,
|
|
6354
|
+
endCol: 100,
|
|
6355
|
+
snippet: sqlMatch[0].slice(0, 80)
|
|
6356
|
+
},
|
|
6357
|
+
analysis: {
|
|
6358
|
+
description: "Database query uses $queryRawUnsafe or raw template literal interpolation (${...}) inside SQL statements, exposing the database to SQL injection.",
|
|
6359
|
+
aiContrast: "AI code generators frequently emit $queryRawUnsafe(`SELECT ... ${input}`) instead of parameterized tagged templates.",
|
|
6360
|
+
empiricalProof: "email=' OR '1'='1' -- dumps unauthorized rows via unparameterized SQL"
|
|
6361
|
+
},
|
|
6362
|
+
remediation: {
|
|
6363
|
+
summary: "Replace $queryRawUnsafe / string-interpolated queries with parameterized $queryRaw tagged templates or $1 placeholders.",
|
|
6364
|
+
fixScript: "await pool.query('SELECT * FROM users WHERE email = $1', [email]);",
|
|
6365
|
+
prTitle: `Security: Parameterize raw SQL query in ${filePath}`
|
|
6366
|
+
},
|
|
6367
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6368
|
+
});
|
|
6369
|
+
}
|
|
6370
|
+
}
|
|
6065
6371
|
return findings;
|
|
6066
6372
|
}
|
|
6067
6373
|
getLineNumber(content, index) {
|
|
@@ -6070,70 +6376,157 @@ var SecretScanner = class {
|
|
|
6070
6376
|
};
|
|
6071
6377
|
|
|
6072
6378
|
// src/analyzers/billing-auditor.ts
|
|
6379
|
+
var import_path3 = __toESM(require("path"));
|
|
6073
6380
|
var BillingAuditor = class {
|
|
6074
6381
|
async analyze(filePath, content) {
|
|
6075
6382
|
const findings = [];
|
|
6076
|
-
const
|
|
6077
|
-
const
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
filePath,
|
|
6087
|
-
startLine: 1,
|
|
6088
|
-
endLine: 1,
|
|
6089
|
-
startCol: 1,
|
|
6090
|
-
endCol: 100,
|
|
6091
|
-
snippet: "Logic found updating subscription without signature verification."
|
|
6092
|
-
},
|
|
6093
|
-
analysis: {
|
|
6094
|
-
description: "The Stripe webhook handler processes payment events without verifying the Stripe-Signature header.",
|
|
6095
|
-
aiContrast: "General AI agents often check if a webhook exists, but they rarely verify that the event was actually sent by Stripe and not forged by a malicious user.",
|
|
6096
|
-
empiricalProof: `curl -X POST https://[PROJECT].com/api/webhooks/stripe -d '{"type": "checkout.session.completed", "data": {"object": {"customer": "attacker_id"}}} '`
|
|
6097
|
-
},
|
|
6098
|
-
remediation: {
|
|
6099
|
-
summary: "Use stripe.webhooks.constructEvent() to verify the webhook signature.",
|
|
6100
|
-
fixScript: "const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);",
|
|
6101
|
-
prTitle: "Security: Add Stripe signature verification"
|
|
6102
|
-
},
|
|
6103
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6104
|
-
});
|
|
6383
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
6384
|
+
const lowerPath = normalizedPath.toLowerCase();
|
|
6385
|
+
const baseName = import_path3.default.basename(normalizedPath);
|
|
6386
|
+
if (/(?:^|\/)(?:__tests__|tests?|__mocks__|mocks?|fixtures?)\//i.test(normalizedPath) || /\.(?:test|spec|stories)\.[jt]sx?$/i.test(normalizedPath)) {
|
|
6387
|
+
return [];
|
|
6388
|
+
}
|
|
6389
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, (b) => b.replace(/[^\r\n]/g, " ")).replace(/\/\/.*$/gm, "");
|
|
6390
|
+
const isHttpWebhookEndpoint = lowerPath.includes("webhook") && (baseName === "route.ts" || baseName === "route.js" || /\/pages\/api\/.+\.(?:ts|js|mjs)$/i.test(normalizedPath) || /\/supabase\/functions\/[^/]+\/index\.(?:ts|js)$/i.test(normalizedPath) || /\bapp\.post\s*\(/.test(codeOnly));
|
|
6391
|
+
if (!isHttpWebhookEndpoint) {
|
|
6392
|
+
return [];
|
|
6105
6393
|
}
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6394
|
+
const isLemonRoute = lowerPath.includes("lemon") || /lemonsqueezy|x-signature/i.test(codeOnly);
|
|
6395
|
+
if (isLemonRoute) {
|
|
6396
|
+
const hasLemonVerify = codeOnly.toLowerCase().includes("x-signature") || codeOnly.includes("createHmac") || codeOnly.includes("timingSafeEqual");
|
|
6397
|
+
if (!hasLemonVerify) {
|
|
6109
6398
|
findings.push({
|
|
6110
6399
|
id: "CR-BIL-02",
|
|
6111
6400
|
moduleId: "billing-auditor",
|
|
6112
|
-
title: "
|
|
6113
|
-
severity: "
|
|
6114
|
-
cvssScore:
|
|
6401
|
+
title: "Unverified Lemon Squeezy Webhook Handler",
|
|
6402
|
+
severity: "CRITICAL",
|
|
6403
|
+
cvssScore: 8.8,
|
|
6115
6404
|
location: {
|
|
6116
6405
|
filePath,
|
|
6117
6406
|
startLine: 1,
|
|
6118
6407
|
endLine: 1,
|
|
6119
6408
|
startCol: 1,
|
|
6120
6409
|
endCol: 100,
|
|
6121
|
-
snippet:
|
|
6410
|
+
snippet: "Lemon Squeezy webhook missing X-Signature HMAC-SHA256 verification"
|
|
6122
6411
|
},
|
|
6123
6412
|
analysis: {
|
|
6124
|
-
description: "
|
|
6125
|
-
aiContrast:
|
|
6126
|
-
empiricalProof:
|
|
6127
|
-
remediation: "Ensure STRIPE_WEBHOOK_SECRET is loaded from an environment variable."
|
|
6413
|
+
description: "Lemon Squeezy webhook handler processes subscription events without verifying the X-Signature HMAC-SHA256 digest.",
|
|
6414
|
+
aiContrast: "AI helpers often check req.json() payloads while omitting crypto.timingSafeEqual signature validation.",
|
|
6415
|
+
empiricalProof: `curl -X POST https://[PROJECT].com/api/webhooks/lemonsqueezy -d '{"meta":{"event_name":"subscription_created"}}'`
|
|
6128
6416
|
},
|
|
6129
6417
|
remediation: {
|
|
6130
|
-
summary: "
|
|
6131
|
-
fixScript:
|
|
6132
|
-
prTitle: "Security:
|
|
6418
|
+
summary: "Verify X-Signature with HMAC-SHA256 and timingSafeEqual against LEMONSQUEEZY_WEBHOOK_SECRET.",
|
|
6419
|
+
fixScript: 'crypto.timingSafeEqual(digest, Buffer.from(signature, "utf8"))',
|
|
6420
|
+
prTitle: "Security: Verify Lemon Squeezy webhook HMAC signature"
|
|
6133
6421
|
},
|
|
6134
6422
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6135
6423
|
});
|
|
6136
6424
|
}
|
|
6425
|
+
return findings;
|
|
6426
|
+
}
|
|
6427
|
+
const isPaddleRoute = lowerPath.includes("paddle") || /paddle-signature|paddle\.webhooks/i.test(codeOnly);
|
|
6428
|
+
if (isPaddleRoute) {
|
|
6429
|
+
const hasPaddleVerify = codeOnly.toLowerCase().includes("paddle-signature") || codeOnly.includes("webhooks.unmarshal") || codeOnly.includes("createHmac");
|
|
6430
|
+
if (!hasPaddleVerify) {
|
|
6431
|
+
findings.push({
|
|
6432
|
+
id: "CR-BIL-03",
|
|
6433
|
+
moduleId: "billing-auditor",
|
|
6434
|
+
title: "Unverified Paddle Webhook Handler",
|
|
6435
|
+
severity: "CRITICAL",
|
|
6436
|
+
cvssScore: 8.8,
|
|
6437
|
+
location: {
|
|
6438
|
+
filePath,
|
|
6439
|
+
startLine: 1,
|
|
6440
|
+
endLine: 1,
|
|
6441
|
+
startCol: 1,
|
|
6442
|
+
endCol: 100,
|
|
6443
|
+
snippet: "Paddle webhook missing Paddle-Signature unmarshal verification"
|
|
6444
|
+
},
|
|
6445
|
+
analysis: {
|
|
6446
|
+
description: "Paddle webhook endpoint processes billing events without verifying Paddle-Signature via paddle.webhooks.unmarshal.",
|
|
6447
|
+
aiContrast: "Generic code reviewers rarely inspect Paddle unmarshal verification.",
|
|
6448
|
+
empiricalProof: `curl -X POST https://[PROJECT].com/api/webhooks/paddle -d '{"event_type":"subscription.activated"}'`
|
|
6449
|
+
},
|
|
6450
|
+
remediation: {
|
|
6451
|
+
summary: "Validate Paddle-Signature header with paddle.webhooks.unmarshal().",
|
|
6452
|
+
fixScript: "const event = await paddle.webhooks.unmarshal(rawBody, process.env.PADDLE_WEBHOOK_SECRET!, sig);",
|
|
6453
|
+
prTitle: "Security: Verify Paddle webhook signature"
|
|
6454
|
+
},
|
|
6455
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6456
|
+
});
|
|
6457
|
+
}
|
|
6458
|
+
return findings;
|
|
6459
|
+
}
|
|
6460
|
+
const isStripeRoute = lowerPath.includes("stripe") || /\bnew\s+Stripe\b|stripe\.webhooks/i.test(codeOnly) || /update.*subscriptions|create.*customer|grant.*access|db\..*update|prisma\..*update|supabase\..*update/i.test(
|
|
6461
|
+
codeOnly
|
|
6462
|
+
);
|
|
6463
|
+
if (isStripeRoute) {
|
|
6464
|
+
const hasConstructEvent = codeOnly.includes("constructEvent") || codeOnly.includes("constructEventAsync") || codeOnly.toLowerCase().includes("stripe-signature");
|
|
6465
|
+
const hasPostHandlerOrMutation = /\bexport\s+(?:async\s+)?(?:function|const)\s+POST\b/.test(codeOnly) || /\bexport\s+default\b/.test(codeOnly) || /\bapp\.post\s*\(/.test(codeOnly) || /update.*subscriptions|create.*customer|grant.*access|db\..*update|prisma\..*update|supabase\..*update/i.test(
|
|
6466
|
+
codeOnly
|
|
6467
|
+
);
|
|
6468
|
+
if (hasPostHandlerOrMutation && !hasConstructEvent) {
|
|
6469
|
+
findings.push({
|
|
6470
|
+
id: "CR-BIL-01",
|
|
6471
|
+
moduleId: "billing-auditor",
|
|
6472
|
+
title: "Unsigned Stripe Webhook",
|
|
6473
|
+
severity: "CRITICAL",
|
|
6474
|
+
cvssScore: 9.5,
|
|
6475
|
+
location: {
|
|
6476
|
+
filePath,
|
|
6477
|
+
startLine: 1,
|
|
6478
|
+
endLine: 1,
|
|
6479
|
+
startCol: 1,
|
|
6480
|
+
endCol: 100,
|
|
6481
|
+
snippet: "Stripe webhook handler parses POST payload without signature verification."
|
|
6482
|
+
},
|
|
6483
|
+
analysis: {
|
|
6484
|
+
description: "The Stripe webhook handler processes payment events without verifying the Stripe-Signature header.",
|
|
6485
|
+
aiContrast: "General AI agents often check if a webhook exists, but fail to verify stripe.webhooks.constructEvent().",
|
|
6486
|
+
empiricalProof: `curl -X POST https://[PROJECT].com/api/webhooks/stripe -d '{"type": "checkout.session.completed", "data": {"object": {"customer": "attacker_id"}}}'`
|
|
6487
|
+
},
|
|
6488
|
+
remediation: {
|
|
6489
|
+
summary: "Use stripe.webhooks.constructEvent() to verify the webhook signature.",
|
|
6490
|
+
fixScript: "const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);",
|
|
6491
|
+
prTitle: "Security: Add Stripe signature verification"
|
|
6492
|
+
},
|
|
6493
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6494
|
+
});
|
|
6495
|
+
}
|
|
6496
|
+
if (codeOnly.includes("constructEvent")) {
|
|
6497
|
+
const secretMatch = codeOnly.match(
|
|
6498
|
+
/constructEvent\s*\(\s*[^,]+,\s*[^,]+,\s*['"]([^'"]*)['"]/
|
|
6499
|
+
);
|
|
6500
|
+
const secretVal = secretMatch?.[1] ?? null;
|
|
6501
|
+
if (secretVal !== null && (secretVal === "" || secretVal.toLowerCase().includes("placeholder"))) {
|
|
6502
|
+
findings.push({
|
|
6503
|
+
id: "CR-BIL-02",
|
|
6504
|
+
moduleId: "billing-auditor",
|
|
6505
|
+
title: "Missing Webhook Secret",
|
|
6506
|
+
severity: "HIGH",
|
|
6507
|
+
cvssScore: 7.2,
|
|
6508
|
+
location: {
|
|
6509
|
+
filePath,
|
|
6510
|
+
startLine: 1,
|
|
6511
|
+
endLine: 1,
|
|
6512
|
+
startCol: 1,
|
|
6513
|
+
endCol: 100,
|
|
6514
|
+
snippet: `constructEvent(..., '${secretVal}')`
|
|
6515
|
+
},
|
|
6516
|
+
analysis: {
|
|
6517
|
+
description: "The Stripe webhook secret is either empty or uses a placeholder value.",
|
|
6518
|
+
aiContrast: 'AI agents see a call to constructEvent and mark it "secure" without checking if the secret is an empty string.',
|
|
6519
|
+
empiricalProof: "The webhook secret is empty; signature verification is inoperable."
|
|
6520
|
+
},
|
|
6521
|
+
remediation: {
|
|
6522
|
+
summary: "Inject the webhook secret from environment variables.",
|
|
6523
|
+
fixScript: "stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);",
|
|
6524
|
+
prTitle: "Security: Fix empty webhook secret"
|
|
6525
|
+
},
|
|
6526
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6527
|
+
});
|
|
6528
|
+
}
|
|
6529
|
+
}
|
|
6137
6530
|
}
|
|
6138
6531
|
return findings;
|
|
6139
6532
|
}
|
|
@@ -6143,22 +6536,88 @@ var BillingAuditor = class {
|
|
|
6143
6536
|
var IndexDetector = class {
|
|
6144
6537
|
async analyze(filePath, content) {
|
|
6145
6538
|
const findings = [];
|
|
6539
|
+
if (filePath.endsWith(".prisma")) {
|
|
6540
|
+
const modelBlocks = content.split(/^model\s+(\w+)\s*\{/m);
|
|
6541
|
+
for (let i = 1; i < modelBlocks.length; i += 2) {
|
|
6542
|
+
const modelName = modelBlocks[i] || "Model";
|
|
6543
|
+
const body = (modelBlocks[i + 1] || "").split(/\n\}/)[0] || "";
|
|
6544
|
+
const indexedFields = /* @__PURE__ */ new Set();
|
|
6545
|
+
const blockIndexRegex = /@@(?:index|unique|id)\s*\(\s*\[([^\]]+)\]/g;
|
|
6546
|
+
let idxMatch;
|
|
6547
|
+
while ((idxMatch = blockIndexRegex.exec(body)) !== null) {
|
|
6548
|
+
const rawGroup = idxMatch[1] || "";
|
|
6549
|
+
for (const rawField of rawGroup.split(",")) {
|
|
6550
|
+
const cleanField = rawField.trim().split(/[\s(:]/)[0];
|
|
6551
|
+
if (cleanField) indexedFields.add(cleanField);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
const relationMatches = Array.from(
|
|
6555
|
+
body.matchAll(/@relation\s*\([^)]*fields:\s*\[([^\]]+)\]/g)
|
|
6556
|
+
);
|
|
6557
|
+
for (const match of relationMatches) {
|
|
6558
|
+
const group = match[1] || "";
|
|
6559
|
+
const fkFields = group.split(",").map((s) => s.trim()).filter(Boolean);
|
|
6560
|
+
for (const fkField of fkFields) {
|
|
6561
|
+
if (indexedFields.has(fkField)) continue;
|
|
6562
|
+
const fieldAlreadyIndexedRegex = new RegExp(
|
|
6563
|
+
`^\\s*${fkField}\\b[^\\n]*@(?:id|unique)\\b`,
|
|
6564
|
+
"m"
|
|
6565
|
+
);
|
|
6566
|
+
if (!fieldAlreadyIndexedRegex.test(body)) {
|
|
6567
|
+
findings.push({
|
|
6568
|
+
id: "CR-PERF-01",
|
|
6569
|
+
moduleId: "index-detector",
|
|
6570
|
+
title: "Missing Prisma Relation Index",
|
|
6571
|
+
severity: "MEDIUM",
|
|
6572
|
+
cvssScore: 4.5,
|
|
6573
|
+
location: {
|
|
6574
|
+
filePath,
|
|
6575
|
+
startLine: 1,
|
|
6576
|
+
endLine: 1,
|
|
6577
|
+
startCol: 1,
|
|
6578
|
+
endCol: 100,
|
|
6579
|
+
snippet: `model ${modelName} FK ${fkField}`
|
|
6580
|
+
},
|
|
6581
|
+
analysis: {
|
|
6582
|
+
description: `Prisma model ${modelName} defines a foreign-key relation on '${fkField}' without an @@index([${fkField}]) directive.`,
|
|
6583
|
+
aiContrast: "Deterministic Prisma schema inspection catches missing relation indexes that trigger full-table scans on joins.",
|
|
6584
|
+
empiricalProof: `model ${modelName} { ... @@index([${fkField}]) }`
|
|
6585
|
+
},
|
|
6586
|
+
remediation: {
|
|
6587
|
+
summary: `Add @@index([${fkField}]) to Prisma model ${modelName}.`,
|
|
6588
|
+
fixScript: ` @@index([${fkField}])`,
|
|
6589
|
+
prTitle: `Perf: Add Prisma index on ${modelName}.${fkField}`
|
|
6590
|
+
},
|
|
6591
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6592
|
+
});
|
|
6593
|
+
break;
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
}
|
|
6597
|
+
}
|
|
6598
|
+
return findings;
|
|
6599
|
+
}
|
|
6146
6600
|
const indices = /* @__PURE__ */ new Set();
|
|
6147
|
-
const indexRegex = /CREATE\s+INDEX\s+[\
|
|
6601
|
+
const indexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[\w"_]+\s+ON\s+(?:public\.)?["`]?(\w+)["`]?(?:\s+USING\s+\w+)?\s*\(\s*["`]?(\w+)["`]?/gi;
|
|
6148
6602
|
let indexMatch;
|
|
6149
6603
|
while ((indexMatch = indexRegex.exec(content)) !== null) {
|
|
6150
|
-
|
|
6604
|
+
const tbl = indexMatch[1];
|
|
6605
|
+
const col = indexMatch[2];
|
|
6606
|
+
if (tbl && col) {
|
|
6607
|
+
indices.add(`${tbl}.${col}`);
|
|
6608
|
+
}
|
|
6151
6609
|
}
|
|
6152
6610
|
const tableBlocks = content.split(/CREATE\s+TABLE/i);
|
|
6153
6611
|
for (let i = 1; i < tableBlocks.length; i++) {
|
|
6154
|
-
const block = tableBlocks[i];
|
|
6155
|
-
const tableNameMatch = block.match(/^\s*(?:public\.)?(\w+)
|
|
6156
|
-
|
|
6157
|
-
|
|
6612
|
+
const block = tableBlocks[i] || "";
|
|
6613
|
+
const tableNameMatch = block.match(/^\s*(?:IF\s+NOT\s+EXISTS\s+)?(?:public\.)?["`]?(\w+)["`]?/i);
|
|
6614
|
+
const tableName = tableNameMatch?.[1];
|
|
6615
|
+
if (!tableName) continue;
|
|
6158
6616
|
const fkRegex = /(\w+)\s+uuid\s+REFERENCES/gi;
|
|
6159
6617
|
let fkMatch;
|
|
6160
6618
|
while ((fkMatch = fkRegex.exec(block)) !== null) {
|
|
6161
6619
|
const columnName = fkMatch[1];
|
|
6620
|
+
if (!columnName) continue;
|
|
6162
6621
|
const key = `${tableName}.${columnName}`;
|
|
6163
6622
|
if (!indices.has(key)) {
|
|
6164
6623
|
findings.push({
|
|
@@ -6197,23 +6656,51 @@ var IndexDetector = class {
|
|
|
6197
6656
|
// src/analyzers/dependency-triage.ts
|
|
6198
6657
|
var DependencyTriage = class {
|
|
6199
6658
|
safeVersions = {
|
|
6200
|
-
|
|
6201
|
-
|
|
6659
|
+
next: "14.0.0",
|
|
6660
|
+
react: "18.0.0"
|
|
6202
6661
|
};
|
|
6203
6662
|
async analyze(filePath, content) {
|
|
6204
6663
|
const findings = [];
|
|
6205
6664
|
let pkg;
|
|
6206
6665
|
try {
|
|
6207
6666
|
pkg = JSON.parse(content);
|
|
6208
|
-
} catch
|
|
6667
|
+
} catch {
|
|
6209
6668
|
return [];
|
|
6210
6669
|
}
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6670
|
+
if (pkg?.deprecated) {
|
|
6671
|
+
findings.push({
|
|
6672
|
+
id: "CR-MAIN-01",
|
|
6673
|
+
moduleId: "dependency-triage",
|
|
6674
|
+
title: "Package is explicitly deprecated",
|
|
6675
|
+
severity: "MEDIUM",
|
|
6676
|
+
cvssScore: 6,
|
|
6677
|
+
location: {
|
|
6678
|
+
filePath,
|
|
6679
|
+
startLine: 1,
|
|
6680
|
+
endLine: 1,
|
|
6681
|
+
startCol: 1,
|
|
6682
|
+
endCol: 100,
|
|
6683
|
+
snippet: `"deprecated": ${JSON.stringify(pkg.deprecated)}`
|
|
6684
|
+
},
|
|
6685
|
+
analysis: {
|
|
6686
|
+
description: "Package manifest marks this module as deprecated, signaling unpatched upstream CVEs during M&A diligence.",
|
|
6687
|
+
aiContrast: "Automated code generators rarely check whether the package manifest itself is marked deprecated.",
|
|
6688
|
+
empiricalProof: 'Inspect "deprecated" field in package.json.'
|
|
6689
|
+
},
|
|
6690
|
+
remediation: {
|
|
6691
|
+
summary: "Migrate away from deprecated package manifests and update dependencies."
|
|
6692
|
+
},
|
|
6693
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6694
|
+
});
|
|
6695
|
+
}
|
|
6696
|
+
const prodDependencies = pkg?.dependencies && typeof pkg.dependencies === "object" ? pkg.dependencies : {};
|
|
6697
|
+
for (const [lib, version] of Object.entries(prodDependencies)) {
|
|
6698
|
+
const safeVer = this.safeVersions[lib];
|
|
6699
|
+
if (safeVer && typeof version === "string") {
|
|
6700
|
+
const majorToken = version.replace(/[^0-9.]/g, "").split(".")[0] || "";
|
|
6701
|
+
const currentMajor = parseInt(majorToken, 10);
|
|
6702
|
+
const safeMajor = parseInt(safeVer.split(".")[0] || "0", 10);
|
|
6703
|
+
if (!Number.isNaN(currentMajor) && currentMajor < safeMajor) {
|
|
6217
6704
|
findings.push({
|
|
6218
6705
|
id: "CR-DEBT-01",
|
|
6219
6706
|
moduleId: "dependency-triage",
|
|
@@ -6229,12 +6716,12 @@ var DependencyTriage = class {
|
|
|
6229
6716
|
snippet: `"${lib}": "${version}"`
|
|
6230
6717
|
},
|
|
6231
6718
|
analysis: {
|
|
6232
|
-
description: `The project is using ${lib} v${version}, but v${
|
|
6233
|
-
aiContrast: "Standard audit tools list all outdated packages. We specifically highlight
|
|
6719
|
+
description: `The project is using ${lib} v${version}, but v${safeVer} is the current baseline.`,
|
|
6720
|
+
aiContrast: "Standard audit tools list all outdated packages. We specifically highlight production runtimes that impact the exit multiple.",
|
|
6234
6721
|
empiricalProof: `Check the changelog for ${lib} v${safeMajor}.0.0 to see the critical architectural shifts missed.`
|
|
6235
6722
|
},
|
|
6236
6723
|
remediation: {
|
|
6237
|
-
summary: `Upgrade ${lib} to v${
|
|
6724
|
+
summary: `Upgrade ${lib} to v${safeVer} or higher.`
|
|
6238
6725
|
},
|
|
6239
6726
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6240
6727
|
});
|
|
@@ -6245,8 +6732,143 @@ var DependencyTriage = class {
|
|
|
6245
6732
|
}
|
|
6246
6733
|
};
|
|
6247
6734
|
|
|
6735
|
+
// src/analyzers/route-auth-analyzer.ts
|
|
6736
|
+
var import_path4 = __toESM(require("path"));
|
|
6737
|
+
var RouteAuthAnalyzer = class {
|
|
6738
|
+
async analyze(filePath, content, options) {
|
|
6739
|
+
const findings = [];
|
|
6740
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
6741
|
+
const lowerPath = normalizedPath.toLowerCase();
|
|
6742
|
+
const baseName = import_path4.default.basename(normalizedPath);
|
|
6743
|
+
const lowerName = baseName.toLowerCase();
|
|
6744
|
+
if (/(?:^|\/)(?:__tests__|tests?|__mocks__|mocks?|fixtures?)\//i.test(normalizedPath) || /\.(?:test|spec|stories)\.[jt]sx?$/i.test(normalizedPath)) {
|
|
6745
|
+
return [];
|
|
6746
|
+
}
|
|
6747
|
+
if (lowerName === "config.toml" && lowerPath.includes("supabase")) {
|
|
6748
|
+
const uncommented = content.split(/\r?\n/).map((line) => line.replace(/#.*$/, "")).join("\n");
|
|
6749
|
+
const fnSectionRegex = /\[functions\.([a-zA-Z0-9_-]+)\]([\s\S]*?)(?=\n\[|$)/g;
|
|
6750
|
+
let fnMatch;
|
|
6751
|
+
while ((fnMatch = fnSectionRegex.exec(uncommented)) !== null) {
|
|
6752
|
+
const fnName = fnMatch[1] || "";
|
|
6753
|
+
const sectionBody = fnMatch[2] || "";
|
|
6754
|
+
const isWebhookOrPublicFn = /(?:webhook|stripe|lemon|paddle|public|health)/i.test(fnName);
|
|
6755
|
+
if (!isWebhookOrPublicFn && /verify_jwt\s*=\s*false/i.test(sectionBody)) {
|
|
6756
|
+
const line = uncommented.slice(0, fnMatch.index).split(/\r?\n/).length;
|
|
6757
|
+
findings.push({
|
|
6758
|
+
id: "CR-ARCH-01",
|
|
6759
|
+
moduleId: "route-auth-analyzer",
|
|
6760
|
+
title: `Unauthenticated Supabase Edge Function in config.toml (${fnName})`,
|
|
6761
|
+
severity: "CRITICAL",
|
|
6762
|
+
cvssScore: 9.2,
|
|
6763
|
+
location: {
|
|
6764
|
+
filePath,
|
|
6765
|
+
startLine: line,
|
|
6766
|
+
endLine: line,
|
|
6767
|
+
startCol: 1,
|
|
6768
|
+
endCol: 100,
|
|
6769
|
+
snippet: `[functions.${fnName}] verify_jwt = false`
|
|
6770
|
+
},
|
|
6771
|
+
analysis: {
|
|
6772
|
+
description: `supabase/config.toml disables JWT authentication (verify_jwt = false) on non-webhook Edge Function "${fnName}".`,
|
|
6773
|
+
aiContrast: "Developers often set verify_jwt = false during debugging and ship unauthenticated Edge Functions to production.",
|
|
6774
|
+
empiricalProof: `curl -X POST https://[PROJECT].supabase.co/functions/v1/${fnName}`
|
|
6775
|
+
},
|
|
6776
|
+
remediation: {
|
|
6777
|
+
summary: "Re-enable JWT verification on non-webhook Supabase Edge Functions.",
|
|
6778
|
+
fixScript: `[functions.${fnName}]
|
|
6779
|
+
verify_jwt = true`,
|
|
6780
|
+
prTitle: `Security: Enable verify_jwt on Edge Function ${fnName}`
|
|
6781
|
+
},
|
|
6782
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6783
|
+
});
|
|
6784
|
+
}
|
|
6785
|
+
}
|
|
6786
|
+
return findings;
|
|
6787
|
+
}
|
|
6788
|
+
const isAppRouterEndpoint = baseName === "route.ts" || baseName === "route.js";
|
|
6789
|
+
const isPagesRouterEndpoint = /\/pages\/api\/.+\.(?:ts|js|mjs)$/i.test(normalizedPath) && (content.includes("export default") || content.includes("module.exports"));
|
|
6790
|
+
const isRemixActionEndpoint = /\/app\/routes\/.+\.(?:tsx|ts|jsx|js)$/i.test(normalizedPath) && /export\s+(?:async\s+)?function\s+action\b/.test(content);
|
|
6791
|
+
const isSupabaseEdgeFunction = /\/supabase\/functions\/[^/]+\/index\.(?:ts|js)$/i.test(normalizedPath) && (/\bserve\s*\(/.test(content) || /\bDeno\.serve\s*\(/.test(content));
|
|
6792
|
+
const isNextServerActionFile = /\.(?:ts|tsx|js|jsx)$/i.test(baseName) && !isAppRouterEndpoint && !isPagesRouterEndpoint && !isSupabaseEdgeFunction && (/^\s*['"]use server['"]/m.test(content) || /export\s+async\s+function\s+\w+\s*\([^)]*\)\s*\{\s*['"]use server['"]/m.test(content)) && /\bexport\s+async\s+function\b/.test(content);
|
|
6793
|
+
if (!isAppRouterEndpoint && !isPagesRouterEndpoint && !isRemixActionEndpoint && !isSupabaseEdgeFunction && !isNextServerActionFile) {
|
|
6794
|
+
return [];
|
|
6795
|
+
}
|
|
6796
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, (b) => b.replace(/[^\r\n]/g, " ")).replace(/\/\/.*$/gm, "");
|
|
6797
|
+
const isPublicAuthOrWebhookPath = /\/(?:\(auth\)\/)?(?:auth\/)?(?:\([^/]+\)\/)?(?:callback|confirm|login|signin|sign-in|signup|sign-up|register|logout|signout|sign-out|reset-password|forgot-password|verify|magic-link)\b/i.test(
|
|
6798
|
+
normalizedPath
|
|
6799
|
+
) || /(?:^|\/)(?:auth[-_.]?actions?|actions\/auth|sign[-_]?in\.actions?|sign[-_]?up\.actions?)\.[jt]sx?$/i.test(
|
|
6800
|
+
normalizedPath
|
|
6801
|
+
) || normalizedPath.includes("[...nextauth]") || normalizedPath.includes("/api/auth/") || /\/pages\/api\/hello\.[jt]s$/i.test(normalizedPath) || lowerPath.includes("webhook") || /\/api\/(?:health|status|ping|public|og)\b/i.test(normalizedPath) || codeOnly.includes("NextAuth(") || codeOnly.includes("toNextJsHandler(") || codeOnly.includes("ImageResponse") || codeOnly.includes("exchangeCodeForSession") || codeOnly.includes("verifyOtp") || codeOnly.includes("signInWithPassword") || codeOnly.includes("signInWithOAuth") || codeOnly.includes("signInWithOtp") || codeOnly.includes("resetPasswordForEmail") || codeOnly.includes("signUp(") || codeOnly.includes("signOut(");
|
|
6802
|
+
if (isPublicAuthOrWebhookPath) {
|
|
6803
|
+
return [];
|
|
6804
|
+
}
|
|
6805
|
+
if ((isAppRouterEndpoint || isPagesRouterEndpoint) && options?.middlewareProtectsApi) {
|
|
6806
|
+
return [];
|
|
6807
|
+
}
|
|
6808
|
+
const hasMutatingAppMethod = /\bexport\s+(?:async\s+)?function\s+(?:POST|PUT|DELETE|PATCH)\b/.test(codeOnly) || /\bexport\s+const\s+(?:POST|PUT|DELETE|PATCH)\b/.test(codeOnly);
|
|
6809
|
+
if (isAppRouterEndpoint && !hasMutatingAppMethod) {
|
|
6810
|
+
return [];
|
|
6811
|
+
}
|
|
6812
|
+
const hasAuth = codeOnly.includes("auth()") || codeOnly.includes("auth.getUser") || codeOnly.includes("auth.getSession") || codeOnly.includes("auth.api.getSession") || codeOnly.includes("getServerSession") || codeOnly.includes("getSession") || codeOnly.includes("requireUser") || codeOnly.includes("currentUser") || codeOnly.includes("authenticator") || codeOnly.includes("protectedProcedure") || codeOnly.includes("createProtectedRoute") || codeOnly.includes("constructEvent") || codeOnly.includes("createHmac") || codeOnly.includes("unmarshal") || codeOnly.includes("timingSafeEqual") || /\b(?:getUser|getCurrentUser|validateRequest|getKindeServerSession)\s*\(/.test(codeOnly) || /headers(?:\(\))?\.get\s*\(\s*['"](?:authorization|x-api-key|stripe-signature|x-signature|paddle-signature)['"]\s*\)/i.test(
|
|
6813
|
+
codeOnly
|
|
6814
|
+
) || /req\.headers\[['"](?:authorization|x-api-key|stripe-signature)['"]\]/i.test(codeOnly) || /\b(?:verify|authenticate|validate|require|assert|checkAuth|withAuth|ensureAuth|requireSession)[A-Za-z0-9_]*\s*\(/.test(
|
|
6815
|
+
codeOnly
|
|
6816
|
+
);
|
|
6817
|
+
if (!hasAuth) {
|
|
6818
|
+
const fnMatch = codeOnly.match(
|
|
6819
|
+
isSupabaseEdgeFunction ? /serve\s*\(/ : /export\s+(?:default\s+)?(?:async\s+)?(?:function|const)/
|
|
6820
|
+
);
|
|
6821
|
+
const startLine = fnMatch && fnMatch.index !== void 0 ? codeOnly.slice(0, fnMatch.index).split(/\r?\n/).length : 1;
|
|
6822
|
+
findings.push({
|
|
6823
|
+
id: "CR-ARCH-01",
|
|
6824
|
+
moduleId: "route-auth-analyzer",
|
|
6825
|
+
title: "Unprotected API Route detected",
|
|
6826
|
+
severity: "CRITICAL",
|
|
6827
|
+
cvssScore: 9.2,
|
|
6828
|
+
location: {
|
|
6829
|
+
filePath,
|
|
6830
|
+
startLine,
|
|
6831
|
+
endLine: startLine,
|
|
6832
|
+
startCol: 1,
|
|
6833
|
+
endCol: 100,
|
|
6834
|
+
snippet: "Mutating route handler lacks session verification or API signature check."
|
|
6835
|
+
},
|
|
6836
|
+
analysis: {
|
|
6837
|
+
description: "Route handler executes server mutations without verifying caller session cookies or cryptographic request headers.",
|
|
6838
|
+
aiContrast: "LLM-generated API routes frequently omit session authentication at the top of POST/PUT/DELETE handlers.",
|
|
6839
|
+
empiricalProof: `curl -X POST https://[PROJECT].com/api/... -H "Content-Type: application/json"`
|
|
6840
|
+
},
|
|
6841
|
+
remediation: {
|
|
6842
|
+
summary: "Verify authenticated user session before executing handler mutations.",
|
|
6843
|
+
fixScript: 'const { data: { user } } = await supabase.auth.getUser(); if (!user) return Response.json({ error: "Unauthorized" }, { status: 401 });',
|
|
6844
|
+
prTitle: "Security: Add caller auth guard to mutating API route"
|
|
6845
|
+
},
|
|
6846
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6847
|
+
});
|
|
6848
|
+
}
|
|
6849
|
+
return findings;
|
|
6850
|
+
}
|
|
6851
|
+
};
|
|
6852
|
+
|
|
6248
6853
|
// src/auditor/risk-matrix.ts
|
|
6249
6854
|
var RISK_MATRIX = {
|
|
6855
|
+
"CR-ARCH-01": {
|
|
6856
|
+
findingId: "CR-ARCH-01",
|
|
6857
|
+
moduleId: "route-auth-analyzer",
|
|
6858
|
+
technicalTitle: "Unprotected API Route",
|
|
6859
|
+
impact: {
|
|
6860
|
+
category: "DATA_BREACH_LIABILITY",
|
|
6861
|
+
summary: "Mutating server endpoint executes database or paid API operations without verifying caller session or authorization credentials.",
|
|
6862
|
+
worstCaseScenario: "Unauthenticated attackers invoke production mutation routes directly to modify tenant records, spoof state, or drain paid AI/API quotas.",
|
|
6863
|
+
buyerObjection: "Technical diligence audit flags unauthenticated server endpoints exposed to the public internet, triggering immediate security remediation holdbacks."
|
|
6864
|
+
},
|
|
6865
|
+
valuation: {
|
|
6866
|
+
dealSeverity: "DEAL_KILLER",
|
|
6867
|
+
multipleImpact: "-1.5x to -2.0x ARR Haircut or LOI Security Gate",
|
|
6868
|
+
mnaCategory: "Access Control & API Boundary Security",
|
|
6869
|
+
executiveVerdict: "Critical authentication boundary failure. Buyers require authenticated session guards on every mutating server endpoint prior to closing."
|
|
6870
|
+
}
|
|
6871
|
+
},
|
|
6250
6872
|
"CR-ARCH-02": {
|
|
6251
6873
|
findingId: "CR-ARCH-02",
|
|
6252
6874
|
moduleId: "rls-analyzer",
|
|
@@ -6270,15 +6892,49 @@ var RISK_MATRIX = {
|
|
|
6270
6892
|
technicalTitle: "Publicly Accessible Data",
|
|
6271
6893
|
impact: {
|
|
6272
6894
|
category: "DATA_BREACH_LIABILITY",
|
|
6273
|
-
summary: "Table RLS policy explicitly targets 'public'
|
|
6895
|
+
summary: "Table RLS policy is missing or explicitly targets 'public' / USING (true), granting open world access or zero-policy lockout.",
|
|
6274
6896
|
worstCaseScenario: "Automated web scrapers extract complete application state; proprietary data sets and user lists leaked and weaponized by competitors.",
|
|
6275
|
-
buyerObjection: "Diligence team identifies
|
|
6897
|
+
buyerObjection: "Diligence team identifies incomplete or permissive RLS policies opening data to the public internet and demands proof of tenant isolation."
|
|
6276
6898
|
},
|
|
6277
6899
|
valuation: {
|
|
6278
6900
|
dealSeverity: "DEAL_KILLER",
|
|
6279
6901
|
multipleImpact: "-1.5x ARR Discount & 30-day Diligence Freeze",
|
|
6280
6902
|
mnaCategory: "Access Control & Tenant Isolation",
|
|
6281
|
-
executiveVerdict: "Severe compliance failure.
|
|
6903
|
+
executiveVerdict: "Severe compliance failure. Incomplete or permissive RLS policies signal undisciplined engineering, triggering deep forensics and deal retrades."
|
|
6904
|
+
}
|
|
6905
|
+
},
|
|
6906
|
+
"CR-DB-01": {
|
|
6907
|
+
findingId: "CR-DB-01",
|
|
6908
|
+
moduleId: "rls-analyzer",
|
|
6909
|
+
technicalTitle: "Unparameterized Raw SQL Injection Vector",
|
|
6910
|
+
impact: {
|
|
6911
|
+
category: "DATA_BREACH_LIABILITY",
|
|
6912
|
+
summary: "Application interpolates untrusted input directly into raw SQL queries ($queryRawUnsafe / template literals), enabling SQL injection.",
|
|
6913
|
+
worstCaseScenario: "Attacker injects arbitrary SQL payloads to exfiltrate full production tables, escalate privileges, or drop tenant schemas.",
|
|
6914
|
+
buyerObjection: "Classic OWASP SQL Injection vulnerability discovered in data layer; acquirer security counsel blocks closing until parameterized queries are verified."
|
|
6915
|
+
},
|
|
6916
|
+
valuation: {
|
|
6917
|
+
dealSeverity: "DEAL_KILLER",
|
|
6918
|
+
multipleImpact: "Immediate LOI Freeze & Mandatory Forensic Audit",
|
|
6919
|
+
mnaCategory: "Database Security & Injection Prevention",
|
|
6920
|
+
executiveVerdict: "Non-negotiable deal killer. Raw SQL injection vectors represent catastrophic data breach exposure and must be parameterized immediately."
|
|
6921
|
+
}
|
|
6922
|
+
},
|
|
6923
|
+
"CR-SEC-01": {
|
|
6924
|
+
findingId: "CR-SEC-01",
|
|
6925
|
+
moduleId: "secret-scanner",
|
|
6926
|
+
technicalTitle: "Google / Cloud Server API Key Leak",
|
|
6927
|
+
impact: {
|
|
6928
|
+
category: "FINANCIAL_REVENUE_FRAUD",
|
|
6929
|
+
summary: "Hardcoded Google Cloud server credential committed to source control exposes cloud and AI billing quotas.",
|
|
6930
|
+
worstCaseScenario: "Automated GitHub scrapers abuse leaked API credentials within minutes, generating five-figure cloud/LLM billing charges.",
|
|
6931
|
+
buyerObjection: "Hardcoded cloud credentials indicate weak secret hygiene; buyer demands full credential rotation before handover."
|
|
6932
|
+
},
|
|
6933
|
+
valuation: {
|
|
6934
|
+
dealSeverity: "DEAL_KILLER",
|
|
6935
|
+
multipleImpact: "Mandatory Key Rotation Gate Prior to Closing",
|
|
6936
|
+
mnaCategory: "Cloud Credential Hygiene",
|
|
6937
|
+
executiveVerdict: "Immediate credential hygiene blocker requiring server environment isolation and key rotation prior to handover."
|
|
6282
6938
|
}
|
|
6283
6939
|
},
|
|
6284
6940
|
"CR-SEC-02": {
|
|
@@ -6315,6 +6971,74 @@ var RISK_MATRIX = {
|
|
|
6315
6971
|
executiveVerdict: "Immediate financial deal killer. Live payment keys in source control contaminate financial statements and expose the business to direct capital loss."
|
|
6316
6972
|
}
|
|
6317
6973
|
},
|
|
6974
|
+
"CR-SEC-04": {
|
|
6975
|
+
findingId: "CR-SEC-04",
|
|
6976
|
+
moduleId: "secret-scanner",
|
|
6977
|
+
technicalTitle: "AWS IAM Access Key ID Leak",
|
|
6978
|
+
impact: {
|
|
6979
|
+
category: "DATA_BREACH_LIABILITY",
|
|
6980
|
+
summary: "Long-lived AWS IAM Access Key ID (AKIA*) committed to repository, exposing cloud infrastructure to unauthorized access.",
|
|
6981
|
+
worstCaseScenario: "Attackers enumerate S3 buckets, Secrets Manager, and EC2/RDS snapshots or spin up unauthorized compute infrastructure.",
|
|
6982
|
+
buyerObjection: "Cloud IAM root/programmatic credentials committed to git trigger mandatory CloudTrail compromise review."
|
|
6983
|
+
},
|
|
6984
|
+
valuation: {
|
|
6985
|
+
dealSeverity: "DEAL_KILLER",
|
|
6986
|
+
multipleImpact: "Immediate Cloud Security Freeze & IAM Audit",
|
|
6987
|
+
mnaCategory: "Cloud IAM & Infrastructure Security",
|
|
6988
|
+
executiveVerdict: "Critical cloud credential exposure. Revoke leaked IAM keys immediately and transition to short-lived OIDC roles."
|
|
6989
|
+
}
|
|
6990
|
+
},
|
|
6991
|
+
"CR-SEC-05": {
|
|
6992
|
+
findingId: "CR-SEC-05",
|
|
6993
|
+
moduleId: "secret-scanner",
|
|
6994
|
+
technicalTitle: "RSA / PEM Private Key Leak",
|
|
6995
|
+
impact: {
|
|
6996
|
+
category: "DATA_BREACH_LIABILITY",
|
|
6997
|
+
summary: "Unencrypted PEM/RSA/OpenSSH private key committed directly in source control.",
|
|
6998
|
+
worstCaseScenario: "Anyone with repository access can forge cryptographic JWTs/webhooks or impersonate production servers via SSH/TLS.",
|
|
6999
|
+
buyerObjection: "Compromised cryptographic signing keys require full history scrubbing and certificate re-issuance before closing."
|
|
7000
|
+
},
|
|
7001
|
+
valuation: {
|
|
7002
|
+
dealSeverity: "DEAL_KILLER",
|
|
7003
|
+
multipleImpact: "Immediate Cryptographic Key Revocation Gate",
|
|
7004
|
+
mnaCategory: "Cryptographic Key Hygiene",
|
|
7005
|
+
executiveVerdict: "Fatal cryptographic key leak. Revoke key pair immediately and purge PEM material from git history."
|
|
7006
|
+
}
|
|
7007
|
+
},
|
|
7008
|
+
"CR-SEC-06": {
|
|
7009
|
+
findingId: "CR-SEC-06",
|
|
7010
|
+
moduleId: "secret-scanner",
|
|
7011
|
+
technicalTitle: "Client-Exposed Secret Env Prefix",
|
|
7012
|
+
impact: {
|
|
7013
|
+
category: "DATA_BREACH_LIABILITY",
|
|
7014
|
+
summary: "Server secret variable uses NEXT_PUBLIC_ or VITE_ prefix, forcing Next.js/Vite to inline the credential into public browser JS.",
|
|
7015
|
+
worstCaseScenario: "Every website visitor receives privileged backend API or database secrets inside compiled client JavaScript chunks.",
|
|
7016
|
+
buyerObjection: "Frontend bundle inspection reveals leaked server secrets; acquirer halts diligence until secrets are rotated and isolated."
|
|
7017
|
+
},
|
|
7018
|
+
valuation: {
|
|
7019
|
+
dealSeverity: "DEAL_KILLER",
|
|
7020
|
+
multipleImpact: "-2.0x ARR Haircut & Mandatory Secret Rotation",
|
|
7021
|
+
mnaCategory: "Client/Server Bundle Isolation",
|
|
7022
|
+
executiveVerdict: "Critical client-bundle leak. Strip NEXT_PUBLIC_/VITE_ prefixes from all private keys and rotate exposed credentials."
|
|
7023
|
+
}
|
|
7024
|
+
},
|
|
7025
|
+
"CR-SEC-07": {
|
|
7026
|
+
findingId: "CR-SEC-07",
|
|
7027
|
+
moduleId: "secret-scanner",
|
|
7028
|
+
technicalTitle: "Browser-Exposed AI SDK",
|
|
7029
|
+
impact: {
|
|
7030
|
+
category: "FINANCIAL_REVENUE_FRAUD",
|
|
7031
|
+
summary: "OpenAI or Anthropic SDK initialized in browser bundle or with dangerouslyAllowBrowser: true.",
|
|
7032
|
+
worstCaseScenario: "Visitors extract live LLM API keys from browser DevTools and rack up thousands of dollars in unauthorized inference spend.",
|
|
7033
|
+
buyerObjection: "Unit economics and COGS are exposed to uncapped API key abuse from client-side LLM instantiation."
|
|
7034
|
+
},
|
|
7035
|
+
valuation: {
|
|
7036
|
+
dealSeverity: "DEAL_KILLER",
|
|
7037
|
+
multipleImpact: "-1.5x ARR Margin Risk & Key Rotation Gate",
|
|
7038
|
+
mnaCategory: "AI Infrastructure & COGS Protection",
|
|
7039
|
+
executiveVerdict: "Immediate COGS and credential exposure. Proxy all LLM calls through authenticated server-only route handlers."
|
|
7040
|
+
}
|
|
7041
|
+
},
|
|
6318
7042
|
"CR-BIL-01": {
|
|
6319
7043
|
findingId: "CR-BIL-01",
|
|
6320
7044
|
moduleId: "billing-auditor",
|
|
@@ -6338,9 +7062,9 @@ var RISK_MATRIX = {
|
|
|
6338
7062
|
technicalTitle: "Missing Webhook Secret",
|
|
6339
7063
|
impact: {
|
|
6340
7064
|
category: "FINANCIAL_REVENUE_FRAUD",
|
|
6341
|
-
summary: "
|
|
6342
|
-
worstCaseScenario: "
|
|
6343
|
-
buyerObjection: "Billing integration is
|
|
7065
|
+
summary: "Webhook signature validation is missing (Lemon Squeezy X-Signature) or invoked with an empty/placeholder secret, rendering verification inoperable.",
|
|
7066
|
+
worstCaseScenario: "Spoofed subscription payloads unlock paid tiers for free or legitimate renewal webhooks fail verification.",
|
|
7067
|
+
buyerObjection: "Billing integration is unverified or brittle. Buyer's engineering lead will flag revenue collection risk during code review."
|
|
6344
7068
|
},
|
|
6345
7069
|
valuation: {
|
|
6346
7070
|
dealSeverity: "ESCROW_HOLDBACK",
|
|
@@ -6349,13 +7073,30 @@ var RISK_MATRIX = {
|
|
|
6349
7073
|
executiveVerdict: "Operational due diligence flag. Causes transaction delay while buyer demands proof of revenue reconciliation and webhook delivery logs."
|
|
6350
7074
|
}
|
|
6351
7075
|
},
|
|
7076
|
+
"CR-BIL-03": {
|
|
7077
|
+
findingId: "CR-BIL-03",
|
|
7078
|
+
moduleId: "billing-auditor",
|
|
7079
|
+
technicalTitle: "Unverified Paddle Webhook Handler",
|
|
7080
|
+
impact: {
|
|
7081
|
+
category: "FINANCIAL_REVENUE_FRAUD",
|
|
7082
|
+
summary: "Paddle billing webhook processes subscription lifecycle events without verifying Paddle-Signature via paddle.webhooks.unmarshal.",
|
|
7083
|
+
worstCaseScenario: "Attackers POST forged subscription.activated events to provision paid seats without paying.",
|
|
7084
|
+
buyerObjection: "Subscription state in database cannot be trusted without cryptographic Paddle webhook verification."
|
|
7085
|
+
},
|
|
7086
|
+
valuation: {
|
|
7087
|
+
dealSeverity: "VALUATION_HAIRCUT",
|
|
7088
|
+
multipleImpact: "-1.0x to -1.5x ARR Valuation Haircut",
|
|
7089
|
+
mnaCategory: "Revenue Recognition & Fraud Prevention",
|
|
7090
|
+
executiveVerdict: "Material billing integrity flaw requiring cryptographic webhook signature verification before financial diligence."
|
|
7091
|
+
}
|
|
7092
|
+
},
|
|
6352
7093
|
"CR-PERF-01": {
|
|
6353
7094
|
findingId: "CR-PERF-01",
|
|
6354
7095
|
moduleId: "index-detector",
|
|
6355
7096
|
technicalTitle: "Missing Foreign Key Index",
|
|
6356
7097
|
impact: {
|
|
6357
7098
|
category: "INFRASTRUCTURE_COLLAPSE",
|
|
6358
|
-
summary: "Relational foreign key column lacks an index, forcing
|
|
7099
|
+
summary: "Relational foreign key column lacks an index, forcing sequential table scans on every joined query.",
|
|
6359
7100
|
worstCaseScenario: "As tenant data reaches 50k+ rows, database CPU saturates at 100%, cascading query timeouts crash the API, and customer churn accelerates.",
|
|
6360
7101
|
buyerObjection: "Database architecture will not scale post-acquisition without refactoring. Buyer discounts purchase price to cover necessary engineering re-architecture."
|
|
6361
7102
|
},
|
|
@@ -6366,6 +7107,23 @@ var RISK_MATRIX = {
|
|
|
6366
7107
|
executiveVerdict: "Classic post-LOI re-trade weapon. Acquirers leverage predictable latency spikes to negotiate a haircut on the agreed multiple."
|
|
6367
7108
|
}
|
|
6368
7109
|
},
|
|
7110
|
+
"CR-MAIN-01": {
|
|
7111
|
+
findingId: "CR-MAIN-01",
|
|
7112
|
+
moduleId: "dependency-triage",
|
|
7113
|
+
technicalTitle: "Deprecated Package Manifest",
|
|
7114
|
+
impact: {
|
|
7115
|
+
category: "TECHNICAL_DEBT_REWRITE",
|
|
7116
|
+
summary: "Package manifest is explicitly marked deprecated, signaling unmaintained upstream dependencies.",
|
|
7117
|
+
worstCaseScenario: "Deprecated modules accumulate unpatched CVEs and break clean production builds on modern Node runtimes.",
|
|
7118
|
+
buyerObjection: "Buyer deducts engineering remediation hours required to replace deprecated packages post-acquisition."
|
|
7119
|
+
},
|
|
7120
|
+
valuation: {
|
|
7121
|
+
dealSeverity: "RENEGOTIATION_TRIGGER",
|
|
7122
|
+
multipleImpact: "-$15,000 to -$40,000 Technical Debt Deduction",
|
|
7123
|
+
mnaCategory: "Maintainability & Tech Debt",
|
|
7124
|
+
executiveVerdict: "Replace deprecated packages prior to listing to eliminate avoidable buyer re-trade leverage."
|
|
7125
|
+
}
|
|
7126
|
+
},
|
|
6369
7127
|
"CR-DEBT-01": {
|
|
6370
7128
|
findingId: "CR-DEBT-01",
|
|
6371
7129
|
moduleId: "dependency-triage",
|
|
@@ -6646,6 +7404,9 @@ var ExecutiveAuditor = class {
|
|
|
6646
7404
|
};
|
|
6647
7405
|
|
|
6648
7406
|
// src/engine.ts
|
|
7407
|
+
function stripCodeExt(relPath) {
|
|
7408
|
+
return relPath.replace(/\.(?:tsx|ts|jsx|js|mjs|cjs)$/i, "").replace(/\/index$/i, "");
|
|
7409
|
+
}
|
|
6649
7410
|
var ClearRecordEngine = class {
|
|
6650
7411
|
constructor(rootDir) {
|
|
6651
7412
|
this.rootDir = rootDir;
|
|
@@ -6653,12 +7414,14 @@ var ClearRecordEngine = class {
|
|
|
6653
7414
|
this.synthesizer = new ReportSynthesizer();
|
|
6654
7415
|
this.enrichmentService = new EnrichmentService();
|
|
6655
7416
|
this.executiveAuditor = new ExecutiveAuditor();
|
|
7417
|
+
this.rlsAnalyzer = new RlsAnalyzer();
|
|
6656
7418
|
this.analyzers = {
|
|
6657
|
-
"rls-analyzer":
|
|
7419
|
+
"rls-analyzer": this.rlsAnalyzer,
|
|
6658
7420
|
"secret-scanner": new SecretScanner(),
|
|
6659
7421
|
"billing-auditor": new BillingAuditor(),
|
|
6660
7422
|
"index-detector": new IndexDetector(),
|
|
6661
|
-
"dependency-triage": new DependencyTriage()
|
|
7423
|
+
"dependency-triage": new DependencyTriage(),
|
|
7424
|
+
"route-auth-analyzer": new RouteAuthAnalyzer()
|
|
6662
7425
|
};
|
|
6663
7426
|
}
|
|
6664
7427
|
rootDir;
|
|
@@ -6666,23 +7429,204 @@ var ClearRecordEngine = class {
|
|
|
6666
7429
|
synthesizer;
|
|
6667
7430
|
enrichmentService;
|
|
6668
7431
|
executiveAuditor;
|
|
7432
|
+
rlsAnalyzer;
|
|
6669
7433
|
analyzers;
|
|
6670
7434
|
async run() {
|
|
6671
7435
|
const manifest = await this.crawler.crawl();
|
|
6672
7436
|
const allFindings = [];
|
|
7437
|
+
const contentCache = /* @__PURE__ */ new Map();
|
|
7438
|
+
const readCached = async (filePath) => {
|
|
7439
|
+
const existing = contentCache.get(filePath);
|
|
7440
|
+
if (existing !== void 0) return existing;
|
|
7441
|
+
const text = await fs.readFile(filePath, "utf8");
|
|
7442
|
+
contentCache.set(filePath, text);
|
|
7443
|
+
return text;
|
|
7444
|
+
};
|
|
7445
|
+
let middlewareProtectsApi = false;
|
|
7446
|
+
let sawSupabaseMarker = false;
|
|
7447
|
+
let sawNonSupabaseOrm = false;
|
|
7448
|
+
const clientModuleRelPaths = /* @__PURE__ */ new Set();
|
|
7449
|
+
const moduleImportEdges = /* @__PURE__ */ new Map();
|
|
7450
|
+
const serverServiceRoleModules = /* @__PURE__ */ new Map();
|
|
7451
|
+
const uniqueProjectFiles = new Set(Object.values(manifest.files).flat());
|
|
7452
|
+
for (const filePath of uniqueProjectFiles) {
|
|
7453
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
7454
|
+
const relPath = path5.relative(this.rootDir, filePath).replace(/\\/g, "/");
|
|
7455
|
+
const lowerRel = `/${relPath.toLowerCase()}`;
|
|
7456
|
+
const baseName = path5.basename(normalized);
|
|
7457
|
+
if (lowerRel.includes("/supabase/")) {
|
|
7458
|
+
sawSupabaseMarker = true;
|
|
7459
|
+
}
|
|
7460
|
+
if (lowerRel.includes("/prisma/") || lowerRel.includes("/drizzle/") || baseName.endsWith(".prisma")) {
|
|
7461
|
+
sawNonSupabaseOrm = true;
|
|
7462
|
+
}
|
|
7463
|
+
let content = "";
|
|
7464
|
+
try {
|
|
7465
|
+
content = await readCached(filePath);
|
|
7466
|
+
} catch {
|
|
7467
|
+
continue;
|
|
7468
|
+
}
|
|
7469
|
+
if (/@supabase\/(?:supabase-js|ssr|auth-helpers)|NEXT_PUBLIC_SUPABASE_URL|SUPABASE_SERVICE_ROLE_KEY|\bauth\.uid\s*\(|\bENABLE\s+ROW\s+LEVEL\s+SECURITY\b|\bTO\s+(?:authenticated|service_role)\b/i.test(
|
|
7470
|
+
content
|
|
7471
|
+
)) {
|
|
7472
|
+
sawSupabaseMarker = true;
|
|
7473
|
+
}
|
|
7474
|
+
if (baseName === "package.json") {
|
|
7475
|
+
try {
|
|
7476
|
+
const pkg = JSON.parse(content);
|
|
7477
|
+
const allDeps = {
|
|
7478
|
+
...pkg?.dependencies && typeof pkg.dependencies === "object" ? pkg.dependencies : {},
|
|
7479
|
+
...pkg?.devDependencies && typeof pkg.devDependencies === "object" ? pkg.devDependencies : {}
|
|
7480
|
+
};
|
|
7481
|
+
for (const dep of Object.keys(allDeps)) {
|
|
7482
|
+
if (/^@supabase\/|^supabase$/i.test(dep)) sawSupabaseMarker = true;
|
|
7483
|
+
if (/^@prisma\/client$|^prisma$|^drizzle-orm$|^mysql2$|^@planetscale\/database$|^typeorm$|^knex$|^kysely$/i.test(
|
|
7484
|
+
dep
|
|
7485
|
+
)) {
|
|
7486
|
+
sawNonSupabaseOrm = true;
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
7489
|
+
} catch {
|
|
7490
|
+
}
|
|
7491
|
+
}
|
|
7492
|
+
if (baseName.endsWith(".sql")) {
|
|
7493
|
+
if (/CREATE\s+TABLE\s+`/i.test(content) || /ENGINE\s*=\s*InnoDB/i.test(content)) {
|
|
7494
|
+
sawNonSupabaseOrm = true;
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
if (/(?:^|\/)(?:src\/)?(?:middleware|proxy)\.(?:ts|js|mjs)$/i.test(normalized)) {
|
|
7498
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
7499
|
+
const enforcesAuth = /\b(?:withAuth|authMiddleware|clerkMiddleware|updateSession|getServerSession|getToken)\b/.test(
|
|
7500
|
+
codeOnly
|
|
7501
|
+
) || codeOnly.includes("auth.getUser") || codeOnly.includes("auth.getSession") || codeOnly.includes("cookies.get") && (codeOnly.includes("401") || codeOnly.includes("redirect"));
|
|
7502
|
+
const excludesAllApi = /\(\?\![^)]*\bapi\b/i.test(codeOnly) && !/['"]\/api\/:path\*['"]/i.test(codeOnly);
|
|
7503
|
+
if (enforcesAuth && !excludesAllApi) {
|
|
7504
|
+
middlewareProtectsApi = true;
|
|
7505
|
+
}
|
|
7506
|
+
}
|
|
7507
|
+
if (/\.(?:ts|tsx|js|jsx|mjs|cjs)$/i.test(baseName)) {
|
|
7508
|
+
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, (b) => b.replace(/[^\r\n]/g, " ")).replace(/\/\/.*$/gm, "");
|
|
7509
|
+
const isClientFile = /^\s*['"]use client['"]/m.test(codeOnly);
|
|
7510
|
+
const isTopLevelUseServer = /^\s*['"]use server['"]/m.test(codeOnly);
|
|
7511
|
+
const hasServerOnlyGuard = isTopLevelUseServer || codeOnly.includes("'server-only'") || codeOnly.includes('"server-only"') || /\bcreateEnv\s*\(\s*\{[\s\S]*?\bserver\s*:/.test(codeOnly);
|
|
7512
|
+
const modKey = stripCodeExt(relPath);
|
|
7513
|
+
if (isClientFile) {
|
|
7514
|
+
clientModuleRelPaths.add(modKey);
|
|
7515
|
+
}
|
|
7516
|
+
if (!isTopLevelUseServer) {
|
|
7517
|
+
const edges = moduleImportEdges.get(modKey) || /* @__PURE__ */ new Set();
|
|
7518
|
+
const importSpecRegex = /(?:import|export)\s+(?!type\b)(?:[^'"]*?\s+from\s+)?['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
7519
|
+
let impMatch;
|
|
7520
|
+
while ((impMatch = importSpecRegex.exec(codeOnly)) !== null) {
|
|
7521
|
+
const spec = impMatch[1] || impMatch[2];
|
|
7522
|
+
if (!spec) continue;
|
|
7523
|
+
if (spec.startsWith("@/") || spec.startsWith("~/")) {
|
|
7524
|
+
const sub = stripCodeExt(spec.slice(2));
|
|
7525
|
+
edges.add(sub);
|
|
7526
|
+
edges.add(`src/${sub}`);
|
|
7527
|
+
} else if (spec.startsWith("./") || spec.startsWith("../")) {
|
|
7528
|
+
const baseDir = path5.posix.dirname(relPath);
|
|
7529
|
+
const resolved = stripCodeExt(path5.posix.normalize(path5.posix.join(baseDir, spec)));
|
|
7530
|
+
edges.add(resolved);
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7533
|
+
moduleImportEdges.set(modKey, edges);
|
|
7534
|
+
}
|
|
7535
|
+
if (!isClientFile && !hasServerOnlyGuard) {
|
|
7536
|
+
const refMatch = codeOnly.match(
|
|
7537
|
+
/(?:process\.env|import\.meta\.env)(?:\.SUPABASE_SERVICE_ROLE_KEY|\[\s*['"]SUPABASE_SERVICE_ROLE_KEY['"]\s*\])|\bgetEnvVar\s*\(\s*['"]SUPABASE_SERVICE_ROLE_KEY['"]/i
|
|
7538
|
+
);
|
|
7539
|
+
if (refMatch && refMatch.index !== void 0) {
|
|
7540
|
+
const line = codeOnly.slice(0, refMatch.index).split(/\r?\n/).length;
|
|
7541
|
+
serverServiceRoleModules.set(modKey, { filePath, line });
|
|
7542
|
+
}
|
|
7543
|
+
}
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
const isNonSupabaseOrmOnly = !sawSupabaseMarker && sawNonSupabaseOrm;
|
|
7547
|
+
const sqlInputs = [];
|
|
7548
|
+
for (const sqlPath of (manifest.files["rls-analyzer"] || []).slice().sort()) {
|
|
7549
|
+
const lowerSql = sqlPath.replace(/\\/g, "/").toLowerCase();
|
|
7550
|
+
if (lowerSql.includes("/prisma/migrations/") || lowerSql.includes("/drizzle/")) {
|
|
7551
|
+
continue;
|
|
7552
|
+
}
|
|
7553
|
+
try {
|
|
7554
|
+
const content = await readCached(sqlPath);
|
|
7555
|
+
sqlInputs.push({ filePath: sqlPath, content });
|
|
7556
|
+
} catch (err) {
|
|
7557
|
+
console.error(`Error reading SQL ${sqlPath}:`, err);
|
|
7558
|
+
}
|
|
7559
|
+
}
|
|
7560
|
+
if (sqlInputs.length > 0) {
|
|
7561
|
+
allFindings.push(
|
|
7562
|
+
...this.rlsAnalyzer.analyzeMigrationSuite(sqlInputs, { isNonSupabaseOrmOnly })
|
|
7563
|
+
);
|
|
7564
|
+
}
|
|
6673
7565
|
for (const [moduleId, files] of Object.entries(manifest.files)) {
|
|
7566
|
+
if (moduleId === "rls-analyzer") continue;
|
|
6674
7567
|
const analyzer = this.analyzers[moduleId];
|
|
6675
7568
|
if (!analyzer) continue;
|
|
6676
7569
|
for (const filePath of files) {
|
|
6677
7570
|
try {
|
|
6678
|
-
const content = await
|
|
6679
|
-
const findings = await analyzer.analyze(filePath, content);
|
|
7571
|
+
const content = await readCached(filePath);
|
|
7572
|
+
const findings = moduleId === "route-auth-analyzer" ? await analyzer.analyze(filePath, content, { middlewareProtectsApi }) : await analyzer.analyze(filePath, content);
|
|
6680
7573
|
allFindings.push(...findings);
|
|
6681
7574
|
} catch (err) {
|
|
6682
7575
|
console.error(`Error analyzing ${filePath}:`, err);
|
|
6683
7576
|
}
|
|
6684
7577
|
}
|
|
6685
7578
|
}
|
|
7579
|
+
if (clientModuleRelPaths.size > 0 && serverServiceRoleModules.size > 0) {
|
|
7580
|
+
const reachableFromClient = new Set(clientModuleRelPaths);
|
|
7581
|
+
const queue = Array.from(clientModuleRelPaths);
|
|
7582
|
+
while (queue.length > 0) {
|
|
7583
|
+
const cur = queue.shift();
|
|
7584
|
+
if (!cur) continue;
|
|
7585
|
+
const targets = moduleImportEdges.get(cur);
|
|
7586
|
+
if (!targets) continue;
|
|
7587
|
+
for (const nextMod of targets) {
|
|
7588
|
+
if (!reachableFromClient.has(nextMod)) {
|
|
7589
|
+
reachableFromClient.add(nextMod);
|
|
7590
|
+
queue.push(nextMod);
|
|
7591
|
+
}
|
|
7592
|
+
}
|
|
7593
|
+
}
|
|
7594
|
+
for (const [modKey, info] of serverServiceRoleModules.entries()) {
|
|
7595
|
+
if (reachableFromClient.has(modKey)) {
|
|
7596
|
+
const alreadyFlagged = allFindings.some(
|
|
7597
|
+
(f) => f.id === "CR-SEC-02" && f.location.filePath === info.filePath
|
|
7598
|
+
);
|
|
7599
|
+
if (!alreadyFlagged) {
|
|
7600
|
+
allFindings.push({
|
|
7601
|
+
id: "CR-SEC-02",
|
|
7602
|
+
moduleId: "secret-scanner",
|
|
7603
|
+
title: "Supabase Service Role Helper Imported Into Client Component Graph",
|
|
7604
|
+
severity: "CRITICAL",
|
|
7605
|
+
cvssScore: 9.8,
|
|
7606
|
+
location: {
|
|
7607
|
+
filePath: info.filePath,
|
|
7608
|
+
startLine: info.line,
|
|
7609
|
+
endLine: info.line,
|
|
7610
|
+
startCol: 1,
|
|
7611
|
+
endCol: 100,
|
|
7612
|
+
snippet: 'process.env.SUPABASE_SERVICE_ROLE_KEY (reachable from "use client")'
|
|
7613
|
+
},
|
|
7614
|
+
analysis: {
|
|
7615
|
+
description: 'Module referencing SUPABASE_SERVICE_ROLE_KEY lacks a "server-only" guard and is imported into a "use client" component dependency graph.',
|
|
7616
|
+
aiContrast: "Single-file scanners miss cross-file client imports that pull server admin modules into browser bundles.",
|
|
7617
|
+
empiricalProof: 'Next.js client bundle includes module referencing SUPABASE_SERVICE_ROLE_KEY without import "server-only".'
|
|
7618
|
+
},
|
|
7619
|
+
remediation: {
|
|
7620
|
+
summary: 'Add import "server-only" and move privileged Supabase calls behind an authenticated server route handler.',
|
|
7621
|
+
fixScript: "import 'server-only';",
|
|
7622
|
+
prTitle: `Security: Isolate ${path5.basename(info.filePath)} from client bundle`
|
|
7623
|
+
},
|
|
7624
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
7625
|
+
});
|
|
7626
|
+
}
|
|
7627
|
+
}
|
|
7628
|
+
}
|
|
7629
|
+
}
|
|
6686
7630
|
const enrichmentResult = this.enrichmentService.enrich(allFindings);
|
|
6687
7631
|
const auditorMemo = this.executiveAuditor.generateMemo(enrichmentResult);
|
|
6688
7632
|
return {
|
|
@@ -6845,11 +7789,11 @@ var CertificateGenerator = class {
|
|
|
6845
7789
|
};
|
|
6846
7790
|
|
|
6847
7791
|
// src/local-cli.ts
|
|
6848
|
-
var CLI_VERSION = "1.
|
|
7792
|
+
var CLI_VERSION = "1.3.0";
|
|
6849
7793
|
function parseCliArgs(args) {
|
|
6850
7794
|
const options = {
|
|
6851
7795
|
targetDir: process.cwd(),
|
|
6852
|
-
reportPath:
|
|
7796
|
+
reportPath: path6.join(process.cwd(), "clear-record-audit.md"),
|
|
6853
7797
|
saveReport: true,
|
|
6854
7798
|
certificate: false,
|
|
6855
7799
|
json: false,
|
|
@@ -6875,19 +7819,19 @@ function parseCliArgs(args) {
|
|
|
6875
7819
|
const nextArg = args[i + 1];
|
|
6876
7820
|
if (nextArg) {
|
|
6877
7821
|
i += 1;
|
|
6878
|
-
options.targetDir =
|
|
7822
|
+
options.targetDir = path6.resolve(nextArg);
|
|
6879
7823
|
}
|
|
6880
7824
|
} else if (arg === "--output" || arg === "-o") {
|
|
6881
7825
|
const nextArg = args[i + 1];
|
|
6882
7826
|
if (nextArg) {
|
|
6883
7827
|
i += 1;
|
|
6884
|
-
options.reportPath =
|
|
7828
|
+
options.reportPath = path6.resolve(nextArg);
|
|
6885
7829
|
}
|
|
6886
7830
|
}
|
|
6887
7831
|
}
|
|
6888
7832
|
if (options.certificate) {
|
|
6889
|
-
options.certificatePath =
|
|
6890
|
-
|
|
7833
|
+
options.certificatePath = path6.join(
|
|
7834
|
+
path6.dirname(options.reportPath),
|
|
6891
7835
|
"clear-record-certificate.md"
|
|
6892
7836
|
);
|
|
6893
7837
|
}
|
|
@@ -6922,7 +7866,7 @@ async function executeCli(options) {
|
|
|
6922
7866
|
let certificate;
|
|
6923
7867
|
const certGen = new CertificateGenerator();
|
|
6924
7868
|
if (options.certificate) {
|
|
6925
|
-
const repoBase =
|
|
7869
|
+
const repoBase = path6.basename(options.targetDir);
|
|
6926
7870
|
certificate = certGen.generate(result.auditorMemo, {
|
|
6927
7871
|
repositoryName: repoBase
|
|
6928
7872
|
});
|