@clearrecord/check 1.2.0 → 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/bin/check.js +962 -300
- package/bin/thin-client.js +2 -2
- package/package.json +1 -1
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;
|
|
@@ -5820,14 +5834,19 @@ var Crawler = class {
|
|
|
5820
5834
|
"dependency-triage": [],
|
|
5821
5835
|
"route-auth-analyzer": []
|
|
5822
5836
|
};
|
|
5823
|
-
const allFiles = await (0, import_fast_glob.default)(
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
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
|
+
);
|
|
5828
5846
|
for (const filePath of allFiles) {
|
|
5829
|
-
const ext = import_path.default.extname(filePath);
|
|
5847
|
+
const ext = import_path.default.extname(filePath).toLowerCase();
|
|
5830
5848
|
const fileName = import_path.default.basename(filePath);
|
|
5849
|
+
const lowerFileName = fileName.toLowerCase();
|
|
5831
5850
|
const normalized = filePath.replace(/\\/g, "/").toLowerCase();
|
|
5832
5851
|
if (ext === ".sql") {
|
|
5833
5852
|
manifest["rls-analyzer"].push(filePath);
|
|
@@ -5836,8 +5855,13 @@ var Crawler = class {
|
|
|
5836
5855
|
if (ext === ".prisma") {
|
|
5837
5856
|
manifest["index-detector"].push(filePath);
|
|
5838
5857
|
}
|
|
5839
|
-
if ([".ts", ".tsx", ".js", ".jsx", ".mjs"].includes(ext)) {
|
|
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)) {
|
|
5840
5862
|
manifest["secret-scanner"].push(filePath);
|
|
5863
|
+
}
|
|
5864
|
+
if (lowerFileName === "config.toml" && normalized.includes("supabase")) {
|
|
5841
5865
|
manifest["route-auth-analyzer"].push(filePath);
|
|
5842
5866
|
}
|
|
5843
5867
|
if (normalized.includes("webhook")) {
|
|
@@ -5919,123 +5943,212 @@ ${f.remediation.fixScript}
|
|
|
5919
5943
|
};
|
|
5920
5944
|
|
|
5921
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
|
+
}
|
|
5922
5976
|
var RlsAnalyzer = class {
|
|
5923
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
|
+
}
|
|
5924
5984
|
const findings = [];
|
|
5925
|
-
const
|
|
5926
|
-
const
|
|
5927
|
-
const
|
|
5928
|
-
const
|
|
5929
|
-
const
|
|
5930
|
-
const
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
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
|
+
}
|
|
5945
6008
|
}
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
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)) {
|
|
5949
6057
|
findings.push({
|
|
5950
6058
|
id: "CR-ARCH-02",
|
|
5951
6059
|
moduleId: "rls-analyzer",
|
|
5952
6060
|
title: "Anonymous Table Dump",
|
|
5953
6061
|
severity: "CRITICAL",
|
|
5954
|
-
cvssScore: 9.
|
|
6062
|
+
cvssScore: 9.5,
|
|
5955
6063
|
location: {
|
|
5956
|
-
filePath,
|
|
5957
|
-
startLine:
|
|
5958
|
-
endLine:
|
|
6064
|
+
filePath: info.filePath,
|
|
6065
|
+
startLine: info.line,
|
|
6066
|
+
endLine: info.line,
|
|
5959
6067
|
startCol: 1,
|
|
5960
6068
|
endCol: 100,
|
|
5961
|
-
snippet: `CREATE TABLE public.${
|
|
6069
|
+
snippet: `CREATE TABLE public.${info.rawName}`
|
|
5962
6070
|
},
|
|
5963
6071
|
analysis: {
|
|
5964
|
-
description: `The '${
|
|
5965
|
-
aiContrast: "Generic LLMs often assume RLS is handled globally
|
|
5966
|
-
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]'`
|
|
5967
6075
|
},
|
|
5968
6076
|
remediation: {
|
|
5969
6077
|
summary: "Enable RLS and restrict access to authenticated users.",
|
|
5970
|
-
fixScript: `ALTER TABLE public.${
|
|
5971
|
-
CREATE POLICY "Users can read own" ON public.${
|
|
5972
|
-
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`
|
|
5973
6081
|
},
|
|
5974
6082
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
5975
6083
|
});
|
|
5976
|
-
}
|
|
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) {
|
|
5977
6089
|
findings.push({
|
|
5978
6090
|
id: "CR-ARCH-03",
|
|
5979
6091
|
moduleId: "rls-analyzer",
|
|
5980
6092
|
title: "RLS Enabled Without Policy (CVE-2025-48757 Zero-Policy Trap)",
|
|
5981
6093
|
severity: "HIGH",
|
|
5982
|
-
cvssScore: 8.
|
|
6094
|
+
cvssScore: 8.8,
|
|
5983
6095
|
location: {
|
|
5984
|
-
filePath,
|
|
5985
|
-
startLine:
|
|
5986
|
-
endLine:
|
|
6096
|
+
filePath: info.filePath,
|
|
6097
|
+
startLine: info.line,
|
|
6098
|
+
endLine: info.line,
|
|
5987
6099
|
startCol: 1,
|
|
5988
6100
|
endCol: 100,
|
|
5989
|
-
snippet: `ALTER TABLE public.${
|
|
6101
|
+
snippet: `ALTER TABLE public.${info.rawName} ENABLE ROW LEVEL SECURITY (0 policies)`
|
|
5990
6102
|
},
|
|
5991
6103
|
analysis: {
|
|
5992
|
-
description: `The '${
|
|
5993
|
-
aiContrast: "Many scanners stop once ENABLE ROW LEVEL SECURITY appears, missing incomplete
|
|
5994
|
-
empiricalProof: `SELECT tablename, policyname FROM pg_policies WHERE tablename = '${
|
|
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}';`
|
|
5995
6107
|
},
|
|
5996
6108
|
remediation: {
|
|
5997
6109
|
summary: "Define explicit authenticated tenant policies on the RLS-enabled table.",
|
|
5998
|
-
fixScript: `CREATE POLICY "Authenticated Read" ON public.${
|
|
5999
|
-
prTitle: `Security: Add explicit RLS policies to ${
|
|
6000
|
-
},
|
|
6001
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6002
|
-
});
|
|
6003
|
-
} else if (publicPolicies.has(table)) {
|
|
6004
|
-
const policyLine = publicPolicies.get(table) || createLine;
|
|
6005
|
-
findings.push({
|
|
6006
|
-
id: "CR-ARCH-03",
|
|
6007
|
-
moduleId: "rls-analyzer",
|
|
6008
|
-
title: "Publicly Accessible Data",
|
|
6009
|
-
severity: "CRITICAL",
|
|
6010
|
-
cvssScore: 8.5,
|
|
6011
|
-
location: {
|
|
6012
|
-
filePath,
|
|
6013
|
-
startLine: policyLine,
|
|
6014
|
-
endLine: policyLine,
|
|
6015
|
-
startCol: 1,
|
|
6016
|
-
endCol: 100,
|
|
6017
|
-
snippet: `CREATE POLICY ... TO public`
|
|
6018
|
-
},
|
|
6019
|
-
analysis: {
|
|
6020
|
-
description: `The '${table}' table has a SELECT policy that explicitly allows 'public' access.`,
|
|
6021
|
-
aiContrast: "Agents see a policy exists and assume it is secure. They fail to check the target role (public vs authenticated).",
|
|
6022
|
-
empiricalProof: `curl -X GET 'https://[PROJECT].supabase.co/rest/v1/${table}?select=*' -H 'apikey: [ANON_KEY]'`
|
|
6023
|
-
},
|
|
6024
|
-
remediation: {
|
|
6025
|
-
summary: "Restrict the policy to authenticated users only.",
|
|
6026
|
-
fixScript: `DROP POLICY "Public Read" ON public.${table};
|
|
6027
|
-
CREATE POLICY "Authenticated Read" ON public.${table} FOR SELECT TO authenticated USING (auth.uid() = id);`,
|
|
6028
|
-
prTitle: `Security: Restrict ${table} access to authenticated users`
|
|
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}`
|
|
6029
6112
|
},
|
|
6030
6113
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6031
6114
|
});
|
|
6032
6115
|
}
|
|
6033
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
|
+
}
|
|
6034
6146
|
return findings;
|
|
6035
6147
|
}
|
|
6036
6148
|
};
|
|
6037
6149
|
|
|
6038
6150
|
// src/analyzers/secret-scanner.ts
|
|
6151
|
+
var import_path2 = __toESM(require("path"));
|
|
6039
6152
|
var SecretScanner = class {
|
|
6040
6153
|
secretPatterns = [
|
|
6041
6154
|
{
|
|
@@ -6051,7 +6164,7 @@ var SecretScanner = class {
|
|
|
6051
6164
|
{
|
|
6052
6165
|
id: "CR-SEC-02",
|
|
6053
6166
|
title: "Supabase Service Role Leak",
|
|
6054
|
-
regex: /(?:sb_admin_[a-zA-Z0-9]+|sb_secret_[a-zA-Z0-9_-]{16,}|SUPABASE_SERVICE_ROLE_KEY\s*[:=]\s*['"][^'"]{
|
|
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,
|
|
6055
6168
|
severity: "CRITICAL",
|
|
6056
6169
|
cvssScore: 9.8,
|
|
6057
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.",
|
|
@@ -6081,7 +6194,7 @@ var SecretScanner = class {
|
|
|
6081
6194
|
{
|
|
6082
6195
|
id: "CR-SEC-05",
|
|
6083
6196
|
title: "RSA / PEM Private Key Leak",
|
|
6084
|
-
regex: /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/g,
|
|
6197
|
+
regex: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/g,
|
|
6085
6198
|
severity: "CRITICAL",
|
|
6086
6199
|
cvssScore: 9.5,
|
|
6087
6200
|
aiContrast: "Private cryptographic keys inside source files allow token forgery or MITM compromise.",
|
|
@@ -6091,37 +6204,40 @@ var SecretScanner = class {
|
|
|
6091
6204
|
{
|
|
6092
6205
|
id: "CR-SEC-06",
|
|
6093
6206
|
title: "Client-Exposed Secret Env Prefix (NEXT_PUBLIC_ / VITE_)",
|
|
6094
|
-
regex: /(?:NEXT_PUBLIC_|VITE_)[A-Z0-9_]*(?:SERVICE_ROLE|SECRET_KEY|WEBHOOK_SECRET|PRIVATE_KEY|ADMIN_KEY)
|
|
6207
|
+
regex: /(?:NEXT_PUBLIC_|VITE_)[A-Z0-9_]*(?:SERVICE_ROLE|SECRET_KEY|SECRET|WEBHOOK_SECRET|PRIVATE_KEY|PRIVATE|ADMIN_KEY)[A-Z0-9_]*/g,
|
|
6095
6208
|
severity: "CRITICAL",
|
|
6096
6209
|
cvssScore: 9.3,
|
|
6097
6210
|
aiContrast: "Frameworks inline NEXT_PUBLIC_* and VITE_* variables verbatim into browser bundles.",
|
|
6098
6211
|
empiricalProof: "Any visitor can inspect compiled browser JS chunks to read the credential.",
|
|
6099
6212
|
remediation: "Remove the NEXT_PUBLIC_ / VITE_ prefix so the key stays strictly on the server."
|
|
6100
|
-
},
|
|
6101
|
-
{
|
|
6102
|
-
id: "CR-SEC-07",
|
|
6103
|
-
title: "Browser-Exposed AI SDK (dangerouslyAllowBrowser)",
|
|
6104
|
-
regex: /dangerouslyAllowBrowser\s*:\s*true/g,
|
|
6105
|
-
severity: "CRITICAL",
|
|
6106
|
-
cvssScore: 9,
|
|
6107
|
-
aiContrast: "Shipping dangerouslyAllowBrowser: true exposes your OpenAI/Anthropic billing key to every visitor.",
|
|
6108
|
-
empiricalProof: "Browser network tab exposes Authorization: Bearer sk-... on client LLM calls.",
|
|
6109
|
-
remediation: "Move AI SDK calls into a Next.js App Router API Route (/api/ai) and remove dangerouslyAllowBrowser."
|
|
6110
6213
|
}
|
|
6111
6214
|
];
|
|
6112
6215
|
async analyze(filePath, content) {
|
|
6113
6216
|
const findings = [];
|
|
6114
6217
|
const normalized = filePath.replace(/\\/g, "/");
|
|
6115
|
-
|
|
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)) {
|
|
6116
6221
|
return [];
|
|
6117
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);
|
|
6118
6230
|
for (const pattern of this.secretPatterns) {
|
|
6231
|
+
if (pattern.id === "CR-SEC-01" && content.includes("authDomain") && content.includes("projectId")) {
|
|
6232
|
+
continue;
|
|
6233
|
+
}
|
|
6119
6234
|
const matches = content.matchAll(pattern.regex);
|
|
6120
6235
|
for (const match of matches) {
|
|
6121
6236
|
const secret = match[0];
|
|
6122
6237
|
if (secret.toUpperCase().includes("EXAMPLE")) {
|
|
6123
6238
|
continue;
|
|
6124
6239
|
}
|
|
6240
|
+
const line = this.getLineNumber(content, match.index ?? 0);
|
|
6125
6241
|
findings.push({
|
|
6126
6242
|
id: pattern.id,
|
|
6127
6243
|
moduleId: "secret-scanner",
|
|
@@ -6130,8 +6246,8 @@ var SecretScanner = class {
|
|
|
6130
6246
|
cvssScore: pattern.cvssScore,
|
|
6131
6247
|
location: {
|
|
6132
6248
|
filePath,
|
|
6133
|
-
startLine:
|
|
6134
|
-
endLine: this.getLineNumber(content, match.index + secret.length),
|
|
6249
|
+
startLine: line,
|
|
6250
|
+
endLine: this.getLineNumber(content, (match.index ?? 0) + secret.length),
|
|
6135
6251
|
startCol: 1,
|
|
6136
6252
|
endCol: 100,
|
|
6137
6253
|
snippet: secret
|
|
@@ -6143,13 +6259,115 @@ var SecretScanner = class {
|
|
|
6143
6259
|
},
|
|
6144
6260
|
remediation: {
|
|
6145
6261
|
summary: pattern.remediation,
|
|
6146
|
-
fixScript: "// Remove hardcoded secret and
|
|
6262
|
+
fixScript: "// Remove hardcoded secret and load from server-only environment variable",
|
|
6147
6263
|
prTitle: `Security: Remove leaked secret from ${filePath}`
|
|
6148
6264
|
},
|
|
6149
6265
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6150
6266
|
});
|
|
6151
6267
|
}
|
|
6152
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
|
+
}
|
|
6153
6371
|
return findings;
|
|
6154
6372
|
}
|
|
6155
6373
|
getLineNumber(content, index) {
|
|
@@ -6158,12 +6376,24 @@ var SecretScanner = class {
|
|
|
6158
6376
|
};
|
|
6159
6377
|
|
|
6160
6378
|
// src/analyzers/billing-auditor.ts
|
|
6379
|
+
var import_path3 = __toESM(require("path"));
|
|
6161
6380
|
var BillingAuditor = class {
|
|
6162
6381
|
async analyze(filePath, content) {
|
|
6163
6382
|
const findings = [];
|
|
6164
|
-
const
|
|
6165
|
-
|
|
6166
|
-
|
|
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 [];
|
|
6393
|
+
}
|
|
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");
|
|
6167
6397
|
if (!hasLemonVerify) {
|
|
6168
6398
|
findings.push({
|
|
6169
6399
|
id: "CR-BIL-02",
|
|
@@ -6194,8 +6424,9 @@ var BillingAuditor = class {
|
|
|
6194
6424
|
}
|
|
6195
6425
|
return findings;
|
|
6196
6426
|
}
|
|
6197
|
-
|
|
6198
|
-
|
|
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");
|
|
6199
6430
|
if (!hasPaddleVerify) {
|
|
6200
6431
|
findings.push({
|
|
6201
6432
|
id: "CR-BIL-03",
|
|
@@ -6226,66 +6457,76 @@ var BillingAuditor = class {
|
|
|
6226
6457
|
}
|
|
6227
6458
|
return findings;
|
|
6228
6459
|
}
|
|
6229
|
-
const
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
location: {
|
|
6239
|
-
filePath,
|
|
6240
|
-
startLine: 1,
|
|
6241
|
-
endLine: 1,
|
|
6242
|
-
startCol: 1,
|
|
6243
|
-
endCol: 100,
|
|
6244
|
-
snippet: "Logic found updating subscription without signature verification."
|
|
6245
|
-
},
|
|
6246
|
-
analysis: {
|
|
6247
|
-
description: "The Stripe webhook handler processes payment events without verifying the Stripe-Signature header.",
|
|
6248
|
-
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.",
|
|
6249
|
-
empiricalProof: `curl -X POST https://[PROJECT].com/api/webhooks/stripe -d '{"type": "checkout.session.completed", "data": {"object": {"customer": "attacker_id"}}} '`
|
|
6250
|
-
},
|
|
6251
|
-
remediation: {
|
|
6252
|
-
summary: "Use stripe.webhooks.constructEvent() to verify the webhook signature.",
|
|
6253
|
-
fixScript: "const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);",
|
|
6254
|
-
prTitle: "Security: Add Stripe signature verification"
|
|
6255
|
-
},
|
|
6256
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6257
|
-
});
|
|
6258
|
-
}
|
|
6259
|
-
if (hasConstructEvent) {
|
|
6260
|
-
const secretMatch = content.match(/constructEvent\s*\(\s*[^,]+,\s*[^,]+,\s*['"]([^'"]*)['"]/);
|
|
6261
|
-
if (secretMatch && (secretMatch[1] === "" || secretMatch[1].toLowerCase().includes("placeholder"))) {
|
|
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) {
|
|
6262
6469
|
findings.push({
|
|
6263
|
-
id: "CR-BIL-
|
|
6470
|
+
id: "CR-BIL-01",
|
|
6264
6471
|
moduleId: "billing-auditor",
|
|
6265
|
-
title: "
|
|
6266
|
-
severity: "
|
|
6267
|
-
cvssScore:
|
|
6472
|
+
title: "Unsigned Stripe Webhook",
|
|
6473
|
+
severity: "CRITICAL",
|
|
6474
|
+
cvssScore: 9.5,
|
|
6268
6475
|
location: {
|
|
6269
6476
|
filePath,
|
|
6270
6477
|
startLine: 1,
|
|
6271
6478
|
endLine: 1,
|
|
6272
6479
|
startCol: 1,
|
|
6273
6480
|
endCol: 100,
|
|
6274
|
-
snippet:
|
|
6481
|
+
snippet: "Stripe webhook handler parses POST payload without signature verification."
|
|
6275
6482
|
},
|
|
6276
6483
|
analysis: {
|
|
6277
|
-
description: "The Stripe webhook
|
|
6278
|
-
aiContrast:
|
|
6279
|
-
empiricalProof:
|
|
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"}}}'`
|
|
6280
6487
|
},
|
|
6281
6488
|
remediation: {
|
|
6282
|
-
summary: "
|
|
6283
|
-
fixScript: "stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);",
|
|
6284
|
-
prTitle: "Security:
|
|
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"
|
|
6285
6492
|
},
|
|
6286
6493
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6287
6494
|
});
|
|
6288
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
|
+
}
|
|
6289
6530
|
}
|
|
6290
6531
|
return findings;
|
|
6291
6532
|
}
|
|
@@ -6298,62 +6539,85 @@ var IndexDetector = class {
|
|
|
6298
6539
|
if (filePath.endsWith(".prisma")) {
|
|
6299
6540
|
const modelBlocks = content.split(/^model\s+(\w+)\s*\{/m);
|
|
6300
6541
|
for (let i = 1; i < modelBlocks.length; i += 2) {
|
|
6301
|
-
const modelName = modelBlocks[i];
|
|
6542
|
+
const modelName = modelBlocks[i] || "Model";
|
|
6302
6543
|
const body = (modelBlocks[i + 1] || "").split(/\n\}/)[0] || "";
|
|
6303
|
-
const
|
|
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
|
+
);
|
|
6304
6557
|
for (const match of relationMatches) {
|
|
6305
|
-
const
|
|
6306
|
-
const
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
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
|
+
}
|
|
6336
6595
|
}
|
|
6337
6596
|
}
|
|
6338
6597
|
}
|
|
6339
6598
|
return findings;
|
|
6340
6599
|
}
|
|
6341
6600
|
const indices = /* @__PURE__ */ new Set();
|
|
6342
|
-
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;
|
|
6343
6602
|
let indexMatch;
|
|
6344
6603
|
while ((indexMatch = indexRegex.exec(content)) !== null) {
|
|
6345
|
-
|
|
6604
|
+
const tbl = indexMatch[1];
|
|
6605
|
+
const col = indexMatch[2];
|
|
6606
|
+
if (tbl && col) {
|
|
6607
|
+
indices.add(`${tbl}.${col}`);
|
|
6608
|
+
}
|
|
6346
6609
|
}
|
|
6347
6610
|
const tableBlocks = content.split(/CREATE\s+TABLE/i);
|
|
6348
6611
|
for (let i = 1; i < tableBlocks.length; i++) {
|
|
6349
|
-
const block = tableBlocks[i];
|
|
6350
|
-
const tableNameMatch = block.match(/^\s*(?:public\.)?(\w+)
|
|
6351
|
-
|
|
6352
|
-
|
|
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;
|
|
6353
6616
|
const fkRegex = /(\w+)\s+uuid\s+REFERENCES/gi;
|
|
6354
6617
|
let fkMatch;
|
|
6355
6618
|
while ((fkMatch = fkRegex.exec(block)) !== null) {
|
|
6356
6619
|
const columnName = fkMatch[1];
|
|
6620
|
+
if (!columnName) continue;
|
|
6357
6621
|
const key = `${tableName}.${columnName}`;
|
|
6358
6622
|
if (!indices.has(key)) {
|
|
6359
6623
|
findings.push({
|
|
@@ -6392,26 +6656,51 @@ var IndexDetector = class {
|
|
|
6392
6656
|
// src/analyzers/dependency-triage.ts
|
|
6393
6657
|
var DependencyTriage = class {
|
|
6394
6658
|
safeVersions = {
|
|
6395
|
-
|
|
6396
|
-
|
|
6659
|
+
next: "14.0.0",
|
|
6660
|
+
react: "18.0.0"
|
|
6397
6661
|
};
|
|
6398
6662
|
async analyze(filePath, content) {
|
|
6399
6663
|
const findings = [];
|
|
6400
6664
|
let pkg;
|
|
6401
6665
|
try {
|
|
6402
6666
|
pkg = JSON.parse(content);
|
|
6403
|
-
} catch
|
|
6667
|
+
} catch {
|
|
6404
6668
|
return [];
|
|
6405
6669
|
}
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
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) {
|
|
6415
6704
|
findings.push({
|
|
6416
6705
|
id: "CR-DEBT-01",
|
|
6417
6706
|
moduleId: "dependency-triage",
|
|
@@ -6427,12 +6716,12 @@ var DependencyTriage = class {
|
|
|
6427
6716
|
snippet: `"${lib}": "${version}"`
|
|
6428
6717
|
},
|
|
6429
6718
|
analysis: {
|
|
6430
|
-
description: `The project is using ${lib} v${version}, but v${
|
|
6431
|
-
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.",
|
|
6432
6721
|
empiricalProof: `Check the changelog for ${lib} v${safeMajor}.0.0 to see the critical architectural shifts missed.`
|
|
6433
6722
|
},
|
|
6434
6723
|
remediation: {
|
|
6435
|
-
summary: `Upgrade ${lib} to v${
|
|
6724
|
+
summary: `Upgrade ${lib} to v${safeVer} or higher.`
|
|
6436
6725
|
},
|
|
6437
6726
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6438
6727
|
});
|
|
@@ -6444,40 +6733,92 @@ var DependencyTriage = class {
|
|
|
6444
6733
|
};
|
|
6445
6734
|
|
|
6446
6735
|
// src/analyzers/route-auth-analyzer.ts
|
|
6736
|
+
var import_path4 = __toESM(require("path"));
|
|
6447
6737
|
var RouteAuthAnalyzer = class {
|
|
6448
6738
|
async analyze(filePath, content, options) {
|
|
6449
6739
|
const findings = [];
|
|
6450
6740
|
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
6451
6741
|
const lowerPath = normalizedPath.toLowerCase();
|
|
6452
|
-
|
|
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)) {
|
|
6453
6745
|
return [];
|
|
6454
6746
|
}
|
|
6455
|
-
|
|
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
|
+
}
|
|
6456
6788
|
const isAppRouterEndpoint = baseName === "route.ts" || baseName === "route.js";
|
|
6457
6789
|
const isPagesRouterEndpoint = /\/pages\/api\/.+\.(?:ts|js|mjs)$/i.test(normalizedPath) && (content.includes("export default") || content.includes("module.exports"));
|
|
6458
|
-
|
|
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) {
|
|
6459
6794
|
return [];
|
|
6460
6795
|
}
|
|
6461
|
-
const codeOnly = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
6462
|
-
const isPublicAuthOrWebhookPath = /\/(?:\(auth\)\/)?(?:auth\/)?(?:callback|confirm|login|signin|signup|register|logout|signout|reset-password|forgot-password|verify|magic-link)\b/i.test(
|
|
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(
|
|
6463
6798
|
normalizedPath
|
|
6464
|
-
) ||
|
|
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(");
|
|
6465
6802
|
if (isPublicAuthOrWebhookPath) {
|
|
6466
6803
|
return [];
|
|
6467
6804
|
}
|
|
6468
|
-
if (options?.middlewareProtectsApi) {
|
|
6805
|
+
if ((isAppRouterEndpoint || isPagesRouterEndpoint) && options?.middlewareProtectsApi) {
|
|
6469
6806
|
return [];
|
|
6470
6807
|
}
|
|
6471
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);
|
|
6472
6809
|
if (isAppRouterEndpoint && !hasMutatingAppMethod) {
|
|
6473
6810
|
return [];
|
|
6474
6811
|
}
|
|
6475
|
-
const hasAuth = codeOnly.includes("auth()") || codeOnly.includes("auth.getUser") || codeOnly.includes("auth.getSession") || codeOnly.includes("getServerSession") || codeOnly.includes("getSession") || codeOnly.includes("requireUser") || codeOnly.includes("currentUser") || codeOnly.includes("protectedProcedure") || codeOnly.includes("constructEvent") || codeOnly.includes("createHmac") || codeOnly.includes("unmarshal") || /headers(?:\(\))?\.get\s*\(\s*['"](?:authorization|x-api-key|stripe-signature|x-signature|paddle-signature)['"]\s*\)/i.test(
|
|
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(
|
|
6476
6813
|
codeOnly
|
|
6477
|
-
) || /\b(?:verify|authenticate|validate|require|checkAuth|withAuth|ensureAuth|requireSession)[A-Za-z0-9_]*\s*\(/.test(
|
|
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(
|
|
6478
6815
|
codeOnly
|
|
6479
6816
|
);
|
|
6480
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;
|
|
6481
6822
|
findings.push({
|
|
6482
6823
|
id: "CR-ARCH-01",
|
|
6483
6824
|
moduleId: "route-auth-analyzer",
|
|
@@ -6486,8 +6827,8 @@ var RouteAuthAnalyzer = class {
|
|
|
6486
6827
|
cvssScore: 9.2,
|
|
6487
6828
|
location: {
|
|
6488
6829
|
filePath,
|
|
6489
|
-
startLine
|
|
6490
|
-
endLine:
|
|
6830
|
+
startLine,
|
|
6831
|
+
endLine: startLine,
|
|
6491
6832
|
startCol: 1,
|
|
6492
6833
|
endCol: 100,
|
|
6493
6834
|
snippet: "Mutating route handler lacks session verification or API signature check."
|
|
@@ -6511,6 +6852,23 @@ var RouteAuthAnalyzer = class {
|
|
|
6511
6852
|
|
|
6512
6853
|
// src/auditor/risk-matrix.ts
|
|
6513
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
|
+
},
|
|
6514
6872
|
"CR-ARCH-02": {
|
|
6515
6873
|
findingId: "CR-ARCH-02",
|
|
6516
6874
|
moduleId: "rls-analyzer",
|
|
@@ -6534,15 +6892,49 @@ var RISK_MATRIX = {
|
|
|
6534
6892
|
technicalTitle: "Publicly Accessible Data",
|
|
6535
6893
|
impact: {
|
|
6536
6894
|
category: "DATA_BREACH_LIABILITY",
|
|
6537
|
-
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.",
|
|
6538
6896
|
worstCaseScenario: "Automated web scrapers extract complete application state; proprietary data sets and user lists leaked and weaponized by competitors.",
|
|
6539
|
-
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."
|
|
6540
6898
|
},
|
|
6541
6899
|
valuation: {
|
|
6542
6900
|
dealSeverity: "DEAL_KILLER",
|
|
6543
6901
|
multipleImpact: "-1.5x ARR Discount & 30-day Diligence Freeze",
|
|
6544
6902
|
mnaCategory: "Access Control & Tenant Isolation",
|
|
6545
|
-
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."
|
|
6546
6938
|
}
|
|
6547
6939
|
},
|
|
6548
6940
|
"CR-SEC-02": {
|
|
@@ -6579,6 +6971,74 @@ var RISK_MATRIX = {
|
|
|
6579
6971
|
executiveVerdict: "Immediate financial deal killer. Live payment keys in source control contaminate financial statements and expose the business to direct capital loss."
|
|
6580
6972
|
}
|
|
6581
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
|
+
},
|
|
6582
7042
|
"CR-BIL-01": {
|
|
6583
7043
|
findingId: "CR-BIL-01",
|
|
6584
7044
|
moduleId: "billing-auditor",
|
|
@@ -6602,9 +7062,9 @@ var RISK_MATRIX = {
|
|
|
6602
7062
|
technicalTitle: "Missing Webhook Secret",
|
|
6603
7063
|
impact: {
|
|
6604
7064
|
category: "FINANCIAL_REVENUE_FRAUD",
|
|
6605
|
-
summary: "
|
|
6606
|
-
worstCaseScenario: "
|
|
6607
|
-
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."
|
|
6608
7068
|
},
|
|
6609
7069
|
valuation: {
|
|
6610
7070
|
dealSeverity: "ESCROW_HOLDBACK",
|
|
@@ -6613,13 +7073,30 @@ var RISK_MATRIX = {
|
|
|
6613
7073
|
executiveVerdict: "Operational due diligence flag. Causes transaction delay while buyer demands proof of revenue reconciliation and webhook delivery logs."
|
|
6614
7074
|
}
|
|
6615
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
|
+
},
|
|
6616
7093
|
"CR-PERF-01": {
|
|
6617
7094
|
findingId: "CR-PERF-01",
|
|
6618
7095
|
moduleId: "index-detector",
|
|
6619
7096
|
technicalTitle: "Missing Foreign Key Index",
|
|
6620
7097
|
impact: {
|
|
6621
7098
|
category: "INFRASTRUCTURE_COLLAPSE",
|
|
6622
|
-
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.",
|
|
6623
7100
|
worstCaseScenario: "As tenant data reaches 50k+ rows, database CPU saturates at 100%, cascading query timeouts crash the API, and customer churn accelerates.",
|
|
6624
7101
|
buyerObjection: "Database architecture will not scale post-acquisition without refactoring. Buyer discounts purchase price to cover necessary engineering re-architecture."
|
|
6625
7102
|
},
|
|
@@ -6630,6 +7107,23 @@ var RISK_MATRIX = {
|
|
|
6630
7107
|
executiveVerdict: "Classic post-LOI re-trade weapon. Acquirers leverage predictable latency spikes to negotiate a haircut on the agreed multiple."
|
|
6631
7108
|
}
|
|
6632
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
|
+
},
|
|
6633
7127
|
"CR-DEBT-01": {
|
|
6634
7128
|
findingId: "CR-DEBT-01",
|
|
6635
7129
|
moduleId: "dependency-triage",
|
|
@@ -6910,6 +7404,9 @@ var ExecutiveAuditor = class {
|
|
|
6910
7404
|
};
|
|
6911
7405
|
|
|
6912
7406
|
// src/engine.ts
|
|
7407
|
+
function stripCodeExt(relPath) {
|
|
7408
|
+
return relPath.replace(/\.(?:tsx|ts|jsx|js|mjs|cjs)$/i, "").replace(/\/index$/i, "");
|
|
7409
|
+
}
|
|
6913
7410
|
var ClearRecordEngine = class {
|
|
6914
7411
|
constructor(rootDir) {
|
|
6915
7412
|
this.rootDir = rootDir;
|
|
@@ -6917,8 +7414,9 @@ var ClearRecordEngine = class {
|
|
|
6917
7414
|
this.synthesizer = new ReportSynthesizer();
|
|
6918
7415
|
this.enrichmentService = new EnrichmentService();
|
|
6919
7416
|
this.executiveAuditor = new ExecutiveAuditor();
|
|
7417
|
+
this.rlsAnalyzer = new RlsAnalyzer();
|
|
6920
7418
|
this.analyzers = {
|
|
6921
|
-
"rls-analyzer":
|
|
7419
|
+
"rls-analyzer": this.rlsAnalyzer,
|
|
6922
7420
|
"secret-scanner": new SecretScanner(),
|
|
6923
7421
|
"billing-auditor": new BillingAuditor(),
|
|
6924
7422
|
"index-detector": new IndexDetector(),
|
|
@@ -6931,33 +7429,146 @@ var ClearRecordEngine = class {
|
|
|
6931
7429
|
synthesizer;
|
|
6932
7430
|
enrichmentService;
|
|
6933
7431
|
executiveAuditor;
|
|
7432
|
+
rlsAnalyzer;
|
|
6934
7433
|
analyzers;
|
|
6935
7434
|
async run() {
|
|
6936
7435
|
const manifest = await this.crawler.crawl();
|
|
6937
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
|
+
};
|
|
6938
7445
|
let middlewareProtectsApi = false;
|
|
6939
|
-
|
|
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) {
|
|
6940
7453
|
const normalized = filePath.replace(/\\/g, "/");
|
|
6941
|
-
|
|
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") {
|
|
6942
7475
|
try {
|
|
6943
|
-
const
|
|
6944
|
-
const
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
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
|
+
}
|
|
6950
7488
|
}
|
|
6951
7489
|
} catch {
|
|
6952
7490
|
}
|
|
6953
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
|
+
);
|
|
6954
7564
|
}
|
|
6955
7565
|
for (const [moduleId, files] of Object.entries(manifest.files)) {
|
|
7566
|
+
if (moduleId === "rls-analyzer") continue;
|
|
6956
7567
|
const analyzer = this.analyzers[moduleId];
|
|
6957
7568
|
if (!analyzer) continue;
|
|
6958
7569
|
for (const filePath of files) {
|
|
6959
7570
|
try {
|
|
6960
|
-
const content = await
|
|
7571
|
+
const content = await readCached(filePath);
|
|
6961
7572
|
const findings = moduleId === "route-auth-analyzer" ? await analyzer.analyze(filePath, content, { middlewareProtectsApi }) : await analyzer.analyze(filePath, content);
|
|
6962
7573
|
allFindings.push(...findings);
|
|
6963
7574
|
} catch (err) {
|
|
@@ -6965,6 +7576,57 @@ var ClearRecordEngine = class {
|
|
|
6965
7576
|
}
|
|
6966
7577
|
}
|
|
6967
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
|
+
}
|
|
6968
7630
|
const enrichmentResult = this.enrichmentService.enrich(allFindings);
|
|
6969
7631
|
const auditorMemo = this.executiveAuditor.generateMemo(enrichmentResult);
|
|
6970
7632
|
return {
|
|
@@ -7127,11 +7789,11 @@ var CertificateGenerator = class {
|
|
|
7127
7789
|
};
|
|
7128
7790
|
|
|
7129
7791
|
// src/local-cli.ts
|
|
7130
|
-
var CLI_VERSION = "1.
|
|
7792
|
+
var CLI_VERSION = "1.3.0";
|
|
7131
7793
|
function parseCliArgs(args) {
|
|
7132
7794
|
const options = {
|
|
7133
7795
|
targetDir: process.cwd(),
|
|
7134
|
-
reportPath:
|
|
7796
|
+
reportPath: path6.join(process.cwd(), "clear-record-audit.md"),
|
|
7135
7797
|
saveReport: true,
|
|
7136
7798
|
certificate: false,
|
|
7137
7799
|
json: false,
|
|
@@ -7157,19 +7819,19 @@ function parseCliArgs(args) {
|
|
|
7157
7819
|
const nextArg = args[i + 1];
|
|
7158
7820
|
if (nextArg) {
|
|
7159
7821
|
i += 1;
|
|
7160
|
-
options.targetDir =
|
|
7822
|
+
options.targetDir = path6.resolve(nextArg);
|
|
7161
7823
|
}
|
|
7162
7824
|
} else if (arg === "--output" || arg === "-o") {
|
|
7163
7825
|
const nextArg = args[i + 1];
|
|
7164
7826
|
if (nextArg) {
|
|
7165
7827
|
i += 1;
|
|
7166
|
-
options.reportPath =
|
|
7828
|
+
options.reportPath = path6.resolve(nextArg);
|
|
7167
7829
|
}
|
|
7168
7830
|
}
|
|
7169
7831
|
}
|
|
7170
7832
|
if (options.certificate) {
|
|
7171
|
-
options.certificatePath =
|
|
7172
|
-
|
|
7833
|
+
options.certificatePath = path6.join(
|
|
7834
|
+
path6.dirname(options.reportPath),
|
|
7173
7835
|
"clear-record-certificate.md"
|
|
7174
7836
|
);
|
|
7175
7837
|
}
|
|
@@ -7204,7 +7866,7 @@ async function executeCli(options) {
|
|
|
7204
7866
|
let certificate;
|
|
7205
7867
|
const certGen = new CertificateGenerator();
|
|
7206
7868
|
if (options.certificate) {
|
|
7207
|
-
const repoBase =
|
|
7869
|
+
const repoBase = path6.basename(options.targetDir);
|
|
7208
7870
|
certificate = certGen.generate(result.auditorMemo, {
|
|
7209
7871
|
repositoryName: repoBase
|
|
7210
7872
|
});
|