@nahisaho/katashiro-security 2.0.2 → 2.0.3
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/package.json +11 -11
- package/LICENSE +0 -21
- package/dist/action-logger.d.ts +0 -114
- package/dist/action-logger.d.ts.map +0 -1
- package/dist/action-logger.js +0 -358
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -24
- package/dist/security-analyzer.d.ts +0 -71
- package/dist/security-analyzer.d.ts.map +0 -1
- package/dist/security-analyzer.js +0 -256
- package/dist/types.d.ts +0 -208
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -130
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nahisaho/katashiro-security",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "KATASHIRO Security - Security analysis and action auditing",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,9 +11,16 @@
|
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"clean": "rm -rf dist"
|
|
20
|
+
},
|
|
14
21
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
22
|
+
"@nahisaho/katashiro-core": "workspace:*",
|
|
23
|
+
"micromatch": "^4.0.8"
|
|
17
24
|
},
|
|
18
25
|
"devDependencies": {
|
|
19
26
|
"@types/micromatch": "^4.0.9",
|
|
@@ -34,12 +41,5 @@
|
|
|
34
41
|
"type": "git",
|
|
35
42
|
"url": "https://github.com/nahisaho/KATASHIRO.git",
|
|
36
43
|
"directory": "katashiro/packages/security"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "tsc -p tsconfig.json",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:watch": "vitest",
|
|
42
|
-
"typecheck": "tsc --noEmit",
|
|
43
|
-
"clean": "rm -rf dist"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 nahisaho
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/action-logger.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ActionLogger - 監査ログ記録クラス
|
|
3
|
-
*
|
|
4
|
-
* @requirement REQ-012-05
|
|
5
|
-
* @design すべてのアクションをタイムスタンプ付きで記録
|
|
6
|
-
*/
|
|
7
|
-
import { Action, SecurityAnalysis, Observation, AuditLogEntry, AuditLogFilter, UserConfirmation, RiskLevel } from './types';
|
|
8
|
-
/**
|
|
9
|
-
* ログストレージインターフェース
|
|
10
|
-
*/
|
|
11
|
-
export interface LogStorage {
|
|
12
|
-
/** ログエントリを追加 */
|
|
13
|
-
append(entry: AuditLogEntry): Promise<void>;
|
|
14
|
-
/** ログを検索 */
|
|
15
|
-
query(filter: AuditLogFilter): Promise<AuditLogEntry[]>;
|
|
16
|
-
/** ログをクリア */
|
|
17
|
-
clear(): Promise<void>;
|
|
18
|
-
/** ログ件数を取得 */
|
|
19
|
-
count(): Promise<number>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* インメモリログストレージ
|
|
23
|
-
*/
|
|
24
|
-
export declare class InMemoryLogStorage implements LogStorage {
|
|
25
|
-
private logs;
|
|
26
|
-
private maxEntries;
|
|
27
|
-
constructor(maxEntries?: number);
|
|
28
|
-
append(entry: AuditLogEntry): Promise<void>;
|
|
29
|
-
query(filter: AuditLogFilter): Promise<AuditLogEntry[]>;
|
|
30
|
-
clear(): Promise<void>;
|
|
31
|
-
count(): Promise<number>;
|
|
32
|
-
/**
|
|
33
|
-
* 全ログを取得(テスト用)
|
|
34
|
-
*/
|
|
35
|
-
getAllLogs(): AuditLogEntry[];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* ActionLoggerオプション
|
|
39
|
-
*/
|
|
40
|
-
export interface ActionLoggerOptions {
|
|
41
|
-
/** ログストレージ */
|
|
42
|
-
storage?: LogStorage;
|
|
43
|
-
/** 最小記録リスクレベル */
|
|
44
|
-
minLogLevel?: RiskLevel;
|
|
45
|
-
/** ID生成関数 */
|
|
46
|
-
generateId?: () => string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* アクションロガー
|
|
50
|
-
*/
|
|
51
|
-
export declare class ActionLogger {
|
|
52
|
-
private readonly storage;
|
|
53
|
-
private readonly minLogLevel;
|
|
54
|
-
private readonly generateId;
|
|
55
|
-
constructor(options?: ActionLoggerOptions);
|
|
56
|
-
/**
|
|
57
|
-
* アクションと分析結果を記録(REQ-012-05)
|
|
58
|
-
*/
|
|
59
|
-
logAction(action: Action, analysis: SecurityAnalysis, observation?: Observation, userConfirmation?: UserConfirmation): Promise<string>;
|
|
60
|
-
/**
|
|
61
|
-
* アクション開始を記録
|
|
62
|
-
*/
|
|
63
|
-
logActionStart(action: Action, analysis: SecurityAnalysis): Promise<string>;
|
|
64
|
-
/**
|
|
65
|
-
* アクション完了を記録(既存エントリを更新)
|
|
66
|
-
*/
|
|
67
|
-
logActionComplete(logId: string, observation: Observation, userConfirmation?: UserConfirmation): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* ログを検索
|
|
70
|
-
*/
|
|
71
|
-
queryLogs(filter: AuditLogFilter): Promise<AuditLogEntry[]>;
|
|
72
|
-
/**
|
|
73
|
-
* 最近のログを取得
|
|
74
|
-
*/
|
|
75
|
-
getRecentLogs(count?: number): Promise<AuditLogEntry[]>;
|
|
76
|
-
/**
|
|
77
|
-
* 高リスクログを取得
|
|
78
|
-
*/
|
|
79
|
-
getHighRiskLogs(count?: number): Promise<AuditLogEntry[]>;
|
|
80
|
-
/**
|
|
81
|
-
* ユーザーのログを取得
|
|
82
|
-
*/
|
|
83
|
-
getUserLogs(userId: string, count?: number): Promise<AuditLogEntry[]>;
|
|
84
|
-
/**
|
|
85
|
-
* ログをクリア
|
|
86
|
-
*/
|
|
87
|
-
clearLogs(): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* ログ件数を取得
|
|
90
|
-
*/
|
|
91
|
-
getLogCount(): Promise<number>;
|
|
92
|
-
/**
|
|
93
|
-
* サマリーを生成
|
|
94
|
-
*/
|
|
95
|
-
generateSummary(filter?: AuditLogFilter): Promise<AuditLogSummary>;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* 監査ログサマリー
|
|
99
|
-
*/
|
|
100
|
-
export interface AuditLogSummary {
|
|
101
|
-
/** 総アクション数 */
|
|
102
|
-
totalActions: number;
|
|
103
|
-
/** リスクレベル別件数 */
|
|
104
|
-
byRiskLevel: Record<RiskLevel, number>;
|
|
105
|
-
/** アクションタイプ別件数 */
|
|
106
|
-
byActionType: Record<string, number>;
|
|
107
|
-
/** 成功率 */
|
|
108
|
-
successRate: number;
|
|
109
|
-
/** ブロック数 */
|
|
110
|
-
blockedCount: number;
|
|
111
|
-
/** 確認数 */
|
|
112
|
-
confirmedCount: number;
|
|
113
|
-
}
|
|
114
|
-
//# sourceMappingURL=action-logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action-logger.d.ts","sourceRoot":"","sources":["../src/action-logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,SAAS,EAEV,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,gBAAgB;IAChB,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,YAAY;IACZ,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACxD,aAAa;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,cAAc;IACd,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,UAAU,CAAS;gBAEf,UAAU,GAAE,MAAc;IAIhC,MAAM,CAAC,KAAK,EAAE,aAAa,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,eAAe,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAInE;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAI/E;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC;;OAEG;IACG,eAAe,CAAC,MAAM,GAAE,cAAmB,GAAG,OAAO,CAAC,eAAe,CAAC;CA+C7E;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB;IAChB,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvC,kBAAkB;IAClB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,UAAU;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU;IACV,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
package/dist/action-logger.js
DELETED
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ActionLogger - 監査ログ記録クラス
|
|
4
|
-
*
|
|
5
|
-
* @requirement REQ-012-05
|
|
6
|
-
* @design すべてのアクションをタイムスタンプ付きで記録
|
|
7
|
-
*/
|
|
8
|
-
var __assign = (this && this.__assign) || function () {
|
|
9
|
-
__assign = Object.assign || function(t) {
|
|
10
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
-
s = arguments[i];
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
return __assign.apply(this, arguments);
|
|
18
|
-
};
|
|
19
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
29
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
30
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
-
function step(op) {
|
|
33
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
-
switch (op[0]) {
|
|
38
|
-
case 0: case 1: t = op; break;
|
|
39
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
-
default:
|
|
43
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
-
if (t[2]) _.ops.pop();
|
|
48
|
-
_.trys.pop(); continue;
|
|
49
|
-
}
|
|
50
|
-
op = body.call(thisArg, _);
|
|
51
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
56
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
57
|
-
if (ar || !(i in from)) {
|
|
58
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
59
|
-
ar[i] = from[i];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.ActionLogger = exports.InMemoryLogStorage = void 0;
|
|
66
|
-
var types_1 = require("./types");
|
|
67
|
-
/**
|
|
68
|
-
* インメモリログストレージ
|
|
69
|
-
*/
|
|
70
|
-
var InMemoryLogStorage = /** @class */ (function () {
|
|
71
|
-
function InMemoryLogStorage(maxEntries) {
|
|
72
|
-
if (maxEntries === void 0) { maxEntries = 10000; }
|
|
73
|
-
this.logs = [];
|
|
74
|
-
this.maxEntries = maxEntries;
|
|
75
|
-
}
|
|
76
|
-
InMemoryLogStorage.prototype.append = function (entry) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
return __generator(this, function (_a) {
|
|
79
|
-
this.logs.push(entry);
|
|
80
|
-
// 最大件数を超えたら古いログを削除
|
|
81
|
-
if (this.logs.length > this.maxEntries) {
|
|
82
|
-
this.logs = this.logs.slice(-this.maxEntries);
|
|
83
|
-
}
|
|
84
|
-
return [2 /*return*/];
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
InMemoryLogStorage.prototype.query = function (filter) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var results, minOrder_1, keyword_1, offset, limit;
|
|
91
|
-
var _a, _b;
|
|
92
|
-
return __generator(this, function (_c) {
|
|
93
|
-
results = __spreadArray([], this.logs, true);
|
|
94
|
-
// 時間範囲フィルター
|
|
95
|
-
if (filter.startTime) {
|
|
96
|
-
results = results.filter(function (e) { return e.timestamp >= filter.startTime; });
|
|
97
|
-
}
|
|
98
|
-
if (filter.endTime) {
|
|
99
|
-
results = results.filter(function (e) { return e.timestamp <= filter.endTime; });
|
|
100
|
-
}
|
|
101
|
-
// アクションタイプフィルター
|
|
102
|
-
if (filter.actionTypes && filter.actionTypes.length > 0) {
|
|
103
|
-
results = results.filter(function (e) { return filter.actionTypes.includes(e.action.type); });
|
|
104
|
-
}
|
|
105
|
-
// リスクレベルフィルター
|
|
106
|
-
if (filter.minRiskLevel) {
|
|
107
|
-
minOrder_1 = types_1.RISK_LEVEL_ORDER[filter.minRiskLevel];
|
|
108
|
-
results = results.filter(function (e) { return types_1.RISK_LEVEL_ORDER[e.analysis.riskLevel] >= minOrder_1; });
|
|
109
|
-
}
|
|
110
|
-
// 成功/失敗フィルター
|
|
111
|
-
if (filter.success !== undefined) {
|
|
112
|
-
results = results.filter(function (e) { var _a; return ((_a = e.observation) === null || _a === void 0 ? void 0 : _a.success) === filter.success; });
|
|
113
|
-
}
|
|
114
|
-
// ユーザーIDフィルター
|
|
115
|
-
if (filter.userId) {
|
|
116
|
-
results = results.filter(function (e) { var _a; return ((_a = e.action.context) === null || _a === void 0 ? void 0 : _a.userId) === filter.userId; });
|
|
117
|
-
}
|
|
118
|
-
// キーワード検索
|
|
119
|
-
if (filter.keyword) {
|
|
120
|
-
keyword_1 = filter.keyword.toLowerCase();
|
|
121
|
-
results = results.filter(function (e) {
|
|
122
|
-
var _a;
|
|
123
|
-
var searchText = __spreadArray(__spreadArray([
|
|
124
|
-
e.action.name,
|
|
125
|
-
e.action.target
|
|
126
|
-
], e.analysis.reasons, true), [
|
|
127
|
-
(_a = e.observation) === null || _a === void 0 ? void 0 : _a.error,
|
|
128
|
-
], false).filter(Boolean)
|
|
129
|
-
.join(' ')
|
|
130
|
-
.toLowerCase();
|
|
131
|
-
return searchText.includes(keyword_1);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
// ソート(新しい順)
|
|
135
|
-
results.sort(function (a, b) { return b.timestamp.localeCompare(a.timestamp); });
|
|
136
|
-
offset = (_a = filter.offset) !== null && _a !== void 0 ? _a : 0;
|
|
137
|
-
limit = (_b = filter.limit) !== null && _b !== void 0 ? _b : 100;
|
|
138
|
-
return [2 /*return*/, results.slice(offset, offset + limit)];
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
InMemoryLogStorage.prototype.clear = function () {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
-
return __generator(this, function (_a) {
|
|
145
|
-
this.logs = [];
|
|
146
|
-
return [2 /*return*/];
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
InMemoryLogStorage.prototype.count = function () {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
return __generator(this, function (_a) {
|
|
153
|
-
return [2 /*return*/, this.logs.length];
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
* 全ログを取得(テスト用)
|
|
159
|
-
*/
|
|
160
|
-
InMemoryLogStorage.prototype.getAllLogs = function () {
|
|
161
|
-
return __spreadArray([], this.logs, true);
|
|
162
|
-
};
|
|
163
|
-
return InMemoryLogStorage;
|
|
164
|
-
}());
|
|
165
|
-
exports.InMemoryLogStorage = InMemoryLogStorage;
|
|
166
|
-
/**
|
|
167
|
-
* アクションロガー
|
|
168
|
-
*/
|
|
169
|
-
var ActionLogger = /** @class */ (function () {
|
|
170
|
-
function ActionLogger(options) {
|
|
171
|
-
if (options === void 0) { options = {}; }
|
|
172
|
-
var _a, _b, _c;
|
|
173
|
-
this.storage = (_a = options.storage) !== null && _a !== void 0 ? _a : new InMemoryLogStorage();
|
|
174
|
-
this.minLogLevel = (_b = options.minLogLevel) !== null && _b !== void 0 ? _b : 'low';
|
|
175
|
-
this.generateId =
|
|
176
|
-
(_c = options.generateId) !== null && _c !== void 0 ? _c : (function () { return "log-".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2, 8)); });
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* アクションと分析結果を記録(REQ-012-05)
|
|
180
|
-
*/
|
|
181
|
-
ActionLogger.prototype.logAction = function (action, analysis, observation, userConfirmation) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var entry;
|
|
184
|
-
return __generator(this, function (_a) {
|
|
185
|
-
switch (_a.label) {
|
|
186
|
-
case 0:
|
|
187
|
-
// 最小リスクレベル未満はスキップ
|
|
188
|
-
if (types_1.RISK_LEVEL_ORDER[analysis.riskLevel] < types_1.RISK_LEVEL_ORDER[this.minLogLevel]) {
|
|
189
|
-
return [2 /*return*/, ''];
|
|
190
|
-
}
|
|
191
|
-
entry = {
|
|
192
|
-
id: this.generateId(),
|
|
193
|
-
timestamp: new Date().toISOString(),
|
|
194
|
-
action: action,
|
|
195
|
-
analysis: analysis,
|
|
196
|
-
observation: observation,
|
|
197
|
-
userConfirmation: userConfirmation,
|
|
198
|
-
};
|
|
199
|
-
return [4 /*yield*/, this.storage.append(entry)];
|
|
200
|
-
case 1:
|
|
201
|
-
_a.sent();
|
|
202
|
-
return [2 /*return*/, entry.id];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* アクション開始を記録
|
|
209
|
-
*/
|
|
210
|
-
ActionLogger.prototype.logActionStart = function (action, analysis) {
|
|
211
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
-
return __generator(this, function (_a) {
|
|
213
|
-
return [2 /*return*/, this.logAction(action, analysis)];
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* アクション完了を記録(既存エントリを更新)
|
|
219
|
-
*/
|
|
220
|
-
ActionLogger.prototype.logActionComplete = function (logId, observation, userConfirmation) {
|
|
221
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
-
var logs, entry;
|
|
223
|
-
return __generator(this, function (_a) {
|
|
224
|
-
switch (_a.label) {
|
|
225
|
-
case 0: return [4 /*yield*/, this.storage.query({ limit: 1000 })];
|
|
226
|
-
case 1:
|
|
227
|
-
logs = _a.sent();
|
|
228
|
-
entry = logs.find(function (e) { return e.id === logId; });
|
|
229
|
-
if (entry) {
|
|
230
|
-
entry.observation = observation;
|
|
231
|
-
if (userConfirmation) {
|
|
232
|
-
entry.userConfirmation = userConfirmation;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return [2 /*return*/];
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* ログを検索
|
|
242
|
-
*/
|
|
243
|
-
ActionLogger.prototype.queryLogs = function (filter) {
|
|
244
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
-
return __generator(this, function (_a) {
|
|
246
|
-
return [2 /*return*/, this.storage.query(filter)];
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
};
|
|
250
|
-
/**
|
|
251
|
-
* 最近のログを取得
|
|
252
|
-
*/
|
|
253
|
-
ActionLogger.prototype.getRecentLogs = function () {
|
|
254
|
-
return __awaiter(this, arguments, void 0, function (count) {
|
|
255
|
-
if (count === void 0) { count = 10; }
|
|
256
|
-
return __generator(this, function (_a) {
|
|
257
|
-
return [2 /*return*/, this.storage.query({ limit: count })];
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
/**
|
|
262
|
-
* 高リスクログを取得
|
|
263
|
-
*/
|
|
264
|
-
ActionLogger.prototype.getHighRiskLogs = function () {
|
|
265
|
-
return __awaiter(this, arguments, void 0, function (count) {
|
|
266
|
-
if (count === void 0) { count = 10; }
|
|
267
|
-
return __generator(this, function (_a) {
|
|
268
|
-
return [2 /*return*/, this.storage.query({ minRiskLevel: 'high', limit: count })];
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* ユーザーのログを取得
|
|
274
|
-
*/
|
|
275
|
-
ActionLogger.prototype.getUserLogs = function (userId_1) {
|
|
276
|
-
return __awaiter(this, arguments, void 0, function (userId, count) {
|
|
277
|
-
if (count === void 0) { count = 10; }
|
|
278
|
-
return __generator(this, function (_a) {
|
|
279
|
-
return [2 /*return*/, this.storage.query({ userId: userId, limit: count })];
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* ログをクリア
|
|
285
|
-
*/
|
|
286
|
-
ActionLogger.prototype.clearLogs = function () {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
-
return __generator(this, function (_a) {
|
|
289
|
-
return [2 /*return*/, this.storage.clear()];
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
/**
|
|
294
|
-
* ログ件数を取得
|
|
295
|
-
*/
|
|
296
|
-
ActionLogger.prototype.getLogCount = function () {
|
|
297
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
298
|
-
return __generator(this, function (_a) {
|
|
299
|
-
return [2 /*return*/, this.storage.count()];
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* サマリーを生成
|
|
305
|
-
*/
|
|
306
|
-
ActionLogger.prototype.generateSummary = function () {
|
|
307
|
-
return __awaiter(this, arguments, void 0, function (filter) {
|
|
308
|
-
var logs, summary, successCount, totalWithObservation, _i, logs_1, log;
|
|
309
|
-
var _a, _b;
|
|
310
|
-
if (filter === void 0) { filter = {}; }
|
|
311
|
-
return __generator(this, function (_c) {
|
|
312
|
-
switch (_c.label) {
|
|
313
|
-
case 0: return [4 /*yield*/, this.storage.query(__assign(__assign({}, filter), { limit: 10000 }))];
|
|
314
|
-
case 1:
|
|
315
|
-
logs = _c.sent();
|
|
316
|
-
summary = {
|
|
317
|
-
totalActions: logs.length,
|
|
318
|
-
byRiskLevel: { low: 0, medium: 0, high: 0, critical: 0 },
|
|
319
|
-
byActionType: {},
|
|
320
|
-
successRate: 0,
|
|
321
|
-
blockedCount: 0,
|
|
322
|
-
confirmedCount: 0,
|
|
323
|
-
};
|
|
324
|
-
successCount = 0;
|
|
325
|
-
totalWithObservation = 0;
|
|
326
|
-
for (_i = 0, logs_1 = logs; _i < logs_1.length; _i++) {
|
|
327
|
-
log = logs_1[_i];
|
|
328
|
-
// リスクレベル別
|
|
329
|
-
summary.byRiskLevel[log.analysis.riskLevel]++;
|
|
330
|
-
// アクションタイプ別
|
|
331
|
-
summary.byActionType[log.action.type] =
|
|
332
|
-
((_a = summary.byActionType[log.action.type]) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
333
|
-
// 成功率計算
|
|
334
|
-
if (log.observation) {
|
|
335
|
-
totalWithObservation++;
|
|
336
|
-
if (log.observation.success) {
|
|
337
|
-
successCount++;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
// ブロック数
|
|
341
|
-
if (!log.analysis.allowed) {
|
|
342
|
-
summary.blockedCount++;
|
|
343
|
-
}
|
|
344
|
-
// 確認数
|
|
345
|
-
if ((_b = log.userConfirmation) === null || _b === void 0 ? void 0 : _b.confirmed) {
|
|
346
|
-
summary.confirmedCount++;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
summary.successRate =
|
|
350
|
-
totalWithObservation > 0 ? successCount / totalWithObservation : 0;
|
|
351
|
-
return [2 /*return*/, summary];
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
};
|
|
356
|
-
return ActionLogger;
|
|
357
|
-
}());
|
|
358
|
-
exports.ActionLogger = ActionLogger;
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @nahisaho/katashiro-security
|
|
3
|
-
*
|
|
4
|
-
* Security analysis and audit logging for KATASHIRO
|
|
5
|
-
* @requirement REQ-012
|
|
6
|
-
*/
|
|
7
|
-
export { RiskLevel, RISK_LEVEL_ORDER, compareRiskLevels, isRiskLevelAtLeast, ActionType, Action, ActionContext, Observation, PatternRule, SecurityPolicy, RiskRule, RiskRuleMatch, SecurityAnalysis, AuditLogEntry, UserConfirmation, AuditLogFilter, DEFAULT_SECURITY_POLICY, BUILTIN_RISK_RULES, SecurityErrorCode, SecurityError, } from './types';
|
|
8
|
-
export { SecurityAnalyzer, SecurityAnalyzerOptions } from './security-analyzer';
|
|
9
|
-
export { LogStorage, InMemoryLogStorage, ActionLogger, ActionLoggerOptions, AuditLogSummary, } from './action-logger';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,MAAM,EACN,aAAa,EACb,WAAW,EACX,WAAW,EACX,cAAc,EACd,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAGhF,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @nahisaho/katashiro-security
|
|
4
|
-
*
|
|
5
|
-
* Security analysis and audit logging for KATASHIRO
|
|
6
|
-
* @requirement REQ-012
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ActionLogger = exports.InMemoryLogStorage = exports.SecurityAnalyzer = exports.SecurityError = exports.BUILTIN_RISK_RULES = exports.DEFAULT_SECURITY_POLICY = exports.isRiskLevelAtLeast = exports.compareRiskLevels = exports.RISK_LEVEL_ORDER = void 0;
|
|
10
|
-
// Types
|
|
11
|
-
var types_1 = require("./types");
|
|
12
|
-
Object.defineProperty(exports, "RISK_LEVEL_ORDER", { enumerable: true, get: function () { return types_1.RISK_LEVEL_ORDER; } });
|
|
13
|
-
Object.defineProperty(exports, "compareRiskLevels", { enumerable: true, get: function () { return types_1.compareRiskLevels; } });
|
|
14
|
-
Object.defineProperty(exports, "isRiskLevelAtLeast", { enumerable: true, get: function () { return types_1.isRiskLevelAtLeast; } });
|
|
15
|
-
Object.defineProperty(exports, "DEFAULT_SECURITY_POLICY", { enumerable: true, get: function () { return types_1.DEFAULT_SECURITY_POLICY; } });
|
|
16
|
-
Object.defineProperty(exports, "BUILTIN_RISK_RULES", { enumerable: true, get: function () { return types_1.BUILTIN_RISK_RULES; } });
|
|
17
|
-
Object.defineProperty(exports, "SecurityError", { enumerable: true, get: function () { return types_1.SecurityError; } });
|
|
18
|
-
// SecurityAnalyzer
|
|
19
|
-
var security_analyzer_1 = require("./security-analyzer");
|
|
20
|
-
Object.defineProperty(exports, "SecurityAnalyzer", { enumerable: true, get: function () { return security_analyzer_1.SecurityAnalyzer; } });
|
|
21
|
-
// ActionLogger
|
|
22
|
-
var action_logger_1 = require("./action-logger");
|
|
23
|
-
Object.defineProperty(exports, "InMemoryLogStorage", { enumerable: true, get: function () { return action_logger_1.InMemoryLogStorage; } });
|
|
24
|
-
Object.defineProperty(exports, "ActionLogger", { enumerable: true, get: function () { return action_logger_1.ActionLogger; } });
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SecurityAnalyzer - セキュリティ分析クラス
|
|
3
|
-
*
|
|
4
|
-
* @requirement REQ-012
|
|
5
|
-
* @design REQ-012-01 リスクレベル評価
|
|
6
|
-
* @design REQ-012-02 確認プロンプト判定
|
|
7
|
-
* @design REQ-012-03 拒否パターンブロック
|
|
8
|
-
* @design REQ-012-04 許可パターン判定
|
|
9
|
-
* @design REQ-012-06 ファイル削除=高リスク
|
|
10
|
-
*/
|
|
11
|
-
import { Action, SecurityPolicy, SecurityAnalysis, RiskRule } from './types';
|
|
12
|
-
/**
|
|
13
|
-
* SecurityAnalyzerオプション
|
|
14
|
-
*/
|
|
15
|
-
export interface SecurityAnalyzerOptions {
|
|
16
|
-
/** カスタムポリシー */
|
|
17
|
-
policy?: Partial<SecurityPolicy>;
|
|
18
|
-
/** ビルトインルールを使用するか */
|
|
19
|
-
useBuiltinRules?: boolean;
|
|
20
|
-
/** 追加のリスクルール */
|
|
21
|
-
additionalRules?: RiskRule[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* セキュリティ分析器
|
|
25
|
-
*/
|
|
26
|
-
export declare class SecurityAnalyzer {
|
|
27
|
-
private readonly policy;
|
|
28
|
-
private readonly riskRules;
|
|
29
|
-
constructor(options?: SecurityAnalyzerOptions);
|
|
30
|
-
/**
|
|
31
|
-
* アクションを分析(REQ-012-01)
|
|
32
|
-
*/
|
|
33
|
-
analyze(action: Action): SecurityAnalysis;
|
|
34
|
-
/**
|
|
35
|
-
* アクションの実行を検証(確認が不要な場合のみ許可)
|
|
36
|
-
*/
|
|
37
|
-
validateAction(action: Action): void;
|
|
38
|
-
/**
|
|
39
|
-
* 確認付きでアクションを検証
|
|
40
|
-
*/
|
|
41
|
-
validateActionWithConfirmation(action: Action, confirmed: boolean): void;
|
|
42
|
-
/**
|
|
43
|
-
* 拒否パターンをチェック(REQ-012-03)
|
|
44
|
-
*/
|
|
45
|
-
private checkDenyPatterns;
|
|
46
|
-
/**
|
|
47
|
-
* 許可パターンをチェック(REQ-012-04)
|
|
48
|
-
*/
|
|
49
|
-
private checkAllowPatterns;
|
|
50
|
-
/**
|
|
51
|
-
* リスクレベルを評価
|
|
52
|
-
*/
|
|
53
|
-
private evaluateRiskLevel;
|
|
54
|
-
/**
|
|
55
|
-
* ルールがアクションにマッチするかチェック
|
|
56
|
-
*/
|
|
57
|
-
private matchesRule;
|
|
58
|
-
/**
|
|
59
|
-
* 現在のポリシーを取得
|
|
60
|
-
*/
|
|
61
|
-
getPolicy(): SecurityPolicy;
|
|
62
|
-
/**
|
|
63
|
-
* リスクルールを取得
|
|
64
|
-
*/
|
|
65
|
-
getRiskRules(): RiskRule[];
|
|
66
|
-
/**
|
|
67
|
-
* ポリシーを更新
|
|
68
|
-
*/
|
|
69
|
-
updatePolicy(update: Partial<SecurityPolicy>): void;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=security-analyzer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"security-analyzer.d.ts","sourceRoot":"","sources":["../src/security-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACL,MAAM,EACN,cAAc,EACd,gBAAgB,EAEhB,QAAQ,EAOT,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,eAAe;IACf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACjC,qBAAqB;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB;IAChB,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;gBAE3B,OAAO,GAAE,uBAA4B;IA4BjD;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB;IA8DzC;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAgBpC;;OAEG;IACH,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI;IAgBxE;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;IACH,OAAO,CAAC,WAAW;IA8BnB;;OAEG;IACH,SAAS,IAAI,cAAc;IAI3B;;OAEG;IACH,YAAY,IAAI,QAAQ,EAAE;IAI1B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;CAiBpD"}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SecurityAnalyzer - セキュリティ分析クラス
|
|
4
|
-
*
|
|
5
|
-
* @requirement REQ-012
|
|
6
|
-
* @design REQ-012-01 リスクレベル評価
|
|
7
|
-
* @design REQ-012-02 確認プロンプト判定
|
|
8
|
-
* @design REQ-012-03 拒否パターンブロック
|
|
9
|
-
* @design REQ-012-04 許可パターン判定
|
|
10
|
-
* @design REQ-012-06 ファイル削除=高リスク
|
|
11
|
-
*/
|
|
12
|
-
var __assign = (this && this.__assign) || function () {
|
|
13
|
-
__assign = Object.assign || function(t) {
|
|
14
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
15
|
-
s = arguments[i];
|
|
16
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
17
|
-
t[p] = s[p];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
|
-
return __assign.apply(this, arguments);
|
|
22
|
-
};
|
|
23
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
24
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
25
|
-
if (ar || !(i in from)) {
|
|
26
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
27
|
-
ar[i] = from[i];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
31
|
-
};
|
|
32
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
-
};
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SecurityAnalyzer = void 0;
|
|
37
|
-
var micromatch_1 = __importDefault(require("micromatch"));
|
|
38
|
-
var types_1 = require("./types");
|
|
39
|
-
/**
|
|
40
|
-
* セキュリティ分析器
|
|
41
|
-
*/
|
|
42
|
-
var SecurityAnalyzer = /** @class */ (function () {
|
|
43
|
-
function SecurityAnalyzer(options) {
|
|
44
|
-
if (options === void 0) { options = {}; }
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
46
|
-
// ポリシーをマージ
|
|
47
|
-
this.policy = __assign(__assign(__assign({}, types_1.DEFAULT_SECURITY_POLICY), options.policy), { allowPatterns: __spreadArray([], ((_b = (_a = options.policy) === null || _a === void 0 ? void 0 : _a.allowPatterns) !== null && _b !== void 0 ? _b : types_1.DEFAULT_SECURITY_POLICY.allowPatterns), true), denyPatterns: __spreadArray([], ((_d = (_c = options.policy) === null || _c === void 0 ? void 0 : _c.denyPatterns) !== null && _d !== void 0 ? _d : types_1.DEFAULT_SECURITY_POLICY.denyPatterns), true), requireConfirmation: (_f = (_e = options.policy) === null || _e === void 0 ? void 0 : _e.requireConfirmation) !== null && _f !== void 0 ? _f : types_1.DEFAULT_SECURITY_POLICY.requireConfirmation, customRiskRules: __spreadArray(__spreadArray([], ((_g = types_1.DEFAULT_SECURITY_POLICY.customRiskRules) !== null && _g !== void 0 ? _g : []), true), ((_j = (_h = options.policy) === null || _h === void 0 ? void 0 : _h.customRiskRules) !== null && _j !== void 0 ? _j : []), true) });
|
|
48
|
-
// リスクルールを構築
|
|
49
|
-
var builtinRules = options.useBuiltinRules !== false ? types_1.BUILTIN_RISK_RULES : [];
|
|
50
|
-
this.riskRules = __spreadArray(__spreadArray(__spreadArray([], builtinRules, true), ((_k = this.policy.customRiskRules) !== null && _k !== void 0 ? _k : []), true), ((_l = options.additionalRules) !== null && _l !== void 0 ? _l : []), true);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* アクションを分析(REQ-012-01)
|
|
54
|
-
*/
|
|
55
|
-
SecurityAnalyzer.prototype.analyze = function (action) {
|
|
56
|
-
var _a;
|
|
57
|
-
var matchedRules = [];
|
|
58
|
-
var reasons = [];
|
|
59
|
-
// 1. 拒否パターンチェック(REQ-012-03)
|
|
60
|
-
var denyMatch = this.checkDenyPatterns(action);
|
|
61
|
-
if (denyMatch) {
|
|
62
|
-
return {
|
|
63
|
-
riskLevel: 'critical',
|
|
64
|
-
reasons: ["Action blocked by deny pattern: ".concat(denyMatch.pattern)],
|
|
65
|
-
requiresConfirmation: false,
|
|
66
|
-
allowed: false,
|
|
67
|
-
blockReason: (_a = denyMatch.description) !== null && _a !== void 0 ? _a : "Matches deny pattern: ".concat(denyMatch.pattern),
|
|
68
|
-
matchedRules: ['deny_pattern'],
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
// 2. リスクレベル評価
|
|
72
|
-
var riskLevel = this.evaluateRiskLevel(action, matchedRules, reasons);
|
|
73
|
-
// 3. 許可パターンチェック(REQ-012-04)
|
|
74
|
-
// 注意: 高リスクアクション(削除など)は許可パターンでリスクを下げない
|
|
75
|
-
var allowMatch = this.checkAllowPatterns(action);
|
|
76
|
-
var highRiskActionTypes = ['file_delete', 'directory_delete', 'command_execute'];
|
|
77
|
-
if (allowMatch && !highRiskActionTypes.includes(action.type)) {
|
|
78
|
-
// 許可パターンにマッチした場合、リスクレベルを下げる
|
|
79
|
-
if (riskLevel !== 'critical') {
|
|
80
|
-
riskLevel = 'low';
|
|
81
|
-
reasons.push("Matched allow pattern: ".concat(allowMatch.pattern));
|
|
82
|
-
matchedRules.push('allow_pattern');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// 4. 最大リスクレベルチェック
|
|
86
|
-
if ((0, types_1.isRiskLevelAtLeast)(riskLevel, this.policy.maxRiskLevel)) {
|
|
87
|
-
if (types_1.RISK_LEVEL_ORDER[riskLevel] > types_1.RISK_LEVEL_ORDER[this.policy.maxRiskLevel]) {
|
|
88
|
-
return {
|
|
89
|
-
riskLevel: riskLevel,
|
|
90
|
-
reasons: reasons,
|
|
91
|
-
requiresConfirmation: false,
|
|
92
|
-
allowed: false,
|
|
93
|
-
blockReason: "Risk level ".concat(riskLevel, " exceeds maximum allowed ").concat(this.policy.maxRiskLevel),
|
|
94
|
-
matchedRules: matchedRules,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// 5. 確認が必要か判定(REQ-012-02)
|
|
99
|
-
var requiresConfirmation = this.policy.requireConfirmation.includes(riskLevel);
|
|
100
|
-
if (requiresConfirmation) {
|
|
101
|
-
reasons.push("Risk level ".concat(riskLevel, " requires confirmation"));
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
riskLevel: riskLevel,
|
|
105
|
-
reasons: reasons,
|
|
106
|
-
requiresConfirmation: requiresConfirmation,
|
|
107
|
-
allowed: true,
|
|
108
|
-
matchedRules: matchedRules,
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* アクションの実行を検証(確認が不要な場合のみ許可)
|
|
113
|
-
*/
|
|
114
|
-
SecurityAnalyzer.prototype.validateAction = function (action) {
|
|
115
|
-
var _a;
|
|
116
|
-
var analysis = this.analyze(action);
|
|
117
|
-
if (!analysis.allowed) {
|
|
118
|
-
throw new types_1.SecurityError('ACTION_BLOCKED', (_a = analysis.blockReason) !== null && _a !== void 0 ? _a : 'Action blocked', analysis);
|
|
119
|
-
}
|
|
120
|
-
if (analysis.requiresConfirmation) {
|
|
121
|
-
throw new types_1.SecurityError('CONFIRMATION_REQUIRED', "Action requires confirmation: ".concat(analysis.reasons.join(', ')), analysis);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* 確認付きでアクションを検証
|
|
126
|
-
*/
|
|
127
|
-
SecurityAnalyzer.prototype.validateActionWithConfirmation = function (action, confirmed) {
|
|
128
|
-
var _a;
|
|
129
|
-
var analysis = this.analyze(action);
|
|
130
|
-
if (!analysis.allowed) {
|
|
131
|
-
throw new types_1.SecurityError('ACTION_BLOCKED', (_a = analysis.blockReason) !== null && _a !== void 0 ? _a : 'Action blocked', analysis);
|
|
132
|
-
}
|
|
133
|
-
if (analysis.requiresConfirmation && !confirmed) {
|
|
134
|
-
throw new types_1.SecurityError('CONFIRMATION_DENIED', 'User did not confirm the action', analysis);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* 拒否パターンをチェック(REQ-012-03)
|
|
139
|
-
*/
|
|
140
|
-
SecurityAnalyzer.prototype.checkDenyPatterns = function (action) {
|
|
141
|
-
if (!action.target)
|
|
142
|
-
return null;
|
|
143
|
-
for (var _i = 0, _a = this.policy.denyPatterns; _i < _a.length; _i++) {
|
|
144
|
-
var rule = _a[_i];
|
|
145
|
-
// アクションタイプフィルター
|
|
146
|
-
if (rule.actionTypes && !rule.actionTypes.includes(action.type)) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
// パターンマッチ
|
|
150
|
-
if (micromatch_1.default.isMatch(action.target, rule.pattern)) {
|
|
151
|
-
return rule;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* 許可パターンをチェック(REQ-012-04)
|
|
158
|
-
*/
|
|
159
|
-
SecurityAnalyzer.prototype.checkAllowPatterns = function (action) {
|
|
160
|
-
if (!action.target)
|
|
161
|
-
return null;
|
|
162
|
-
for (var _i = 0, _a = this.policy.allowPatterns; _i < _a.length; _i++) {
|
|
163
|
-
var rule = _a[_i];
|
|
164
|
-
// アクションタイプフィルター
|
|
165
|
-
if (rule.actionTypes && !rule.actionTypes.includes(action.type)) {
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
// パターンマッチ
|
|
169
|
-
if (micromatch_1.default.isMatch(action.target, rule.pattern)) {
|
|
170
|
-
return rule;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return null;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* リスクレベルを評価
|
|
177
|
-
*/
|
|
178
|
-
SecurityAnalyzer.prototype.evaluateRiskLevel = function (action, matchedRules, reasons) {
|
|
179
|
-
var maxRiskLevel = 'low';
|
|
180
|
-
for (var _i = 0, _a = this.riskRules; _i < _a.length; _i++) {
|
|
181
|
-
var rule = _a[_i];
|
|
182
|
-
if (this.matchesRule(action, rule)) {
|
|
183
|
-
matchedRules.push(rule.name);
|
|
184
|
-
reasons.push(rule.description);
|
|
185
|
-
// より高いリスクレベルを採用
|
|
186
|
-
if (types_1.RISK_LEVEL_ORDER[rule.riskLevel] > types_1.RISK_LEVEL_ORDER[maxRiskLevel]) {
|
|
187
|
-
maxRiskLevel = rule.riskLevel;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return maxRiskLevel;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* ルールがアクションにマッチするかチェック
|
|
195
|
-
*/
|
|
196
|
-
SecurityAnalyzer.prototype.matchesRule = function (action, rule) {
|
|
197
|
-
var match = rule.match;
|
|
198
|
-
// アクションタイプチェック
|
|
199
|
-
if (match.actionTypes && !match.actionTypes.includes(action.type)) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
// ターゲットパターンチェック
|
|
203
|
-
if (match.targetPatterns && action.target) {
|
|
204
|
-
var matchesTarget = match.targetPatterns.some(function (pattern) {
|
|
205
|
-
return micromatch_1.default.isMatch(action.target, pattern);
|
|
206
|
-
});
|
|
207
|
-
if (!matchesTarget) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// パラメータ条件チェック
|
|
212
|
-
if (match.paramConditions && action.params) {
|
|
213
|
-
for (var _i = 0, _a = Object.entries(match.paramConditions); _i < _a.length; _i++) {
|
|
214
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
215
|
-
if (action.params[key] !== value) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* 現在のポリシーを取得
|
|
224
|
-
*/
|
|
225
|
-
SecurityAnalyzer.prototype.getPolicy = function () {
|
|
226
|
-
return __assign({}, this.policy);
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* リスクルールを取得
|
|
230
|
-
*/
|
|
231
|
-
SecurityAnalyzer.prototype.getRiskRules = function () {
|
|
232
|
-
return __spreadArray([], this.riskRules, true);
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* ポリシーを更新
|
|
236
|
-
*/
|
|
237
|
-
SecurityAnalyzer.prototype.updatePolicy = function (update) {
|
|
238
|
-
if (update.allowPatterns) {
|
|
239
|
-
this.policy.allowPatterns = update.allowPatterns;
|
|
240
|
-
}
|
|
241
|
-
if (update.denyPatterns) {
|
|
242
|
-
this.policy.denyPatterns = update.denyPatterns;
|
|
243
|
-
}
|
|
244
|
-
if (update.requireConfirmation) {
|
|
245
|
-
this.policy.requireConfirmation = update.requireConfirmation;
|
|
246
|
-
}
|
|
247
|
-
if (update.maxRiskLevel) {
|
|
248
|
-
this.policy.maxRiskLevel = update.maxRiskLevel;
|
|
249
|
-
}
|
|
250
|
-
if (update.customRiskRules) {
|
|
251
|
-
this.policy.customRiskRules = update.customRiskRules;
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
return SecurityAnalyzer;
|
|
255
|
-
}());
|
|
256
|
-
exports.SecurityAnalyzer = SecurityAnalyzer;
|
package/dist/types.d.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security 型定義
|
|
3
|
-
*
|
|
4
|
-
* @requirement REQ-012
|
|
5
|
-
* @design REQ-012-01〜REQ-012-06
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* リスクレベル
|
|
9
|
-
*/
|
|
10
|
-
export type RiskLevel = 'low' | 'medium' | 'high' | 'critical';
|
|
11
|
-
/**
|
|
12
|
-
* リスクレベルの数値マッピング
|
|
13
|
-
*/
|
|
14
|
-
export declare const RISK_LEVEL_ORDER: Record<RiskLevel, number>;
|
|
15
|
-
/**
|
|
16
|
-
* リスクレベル比較
|
|
17
|
-
*/
|
|
18
|
-
export declare function compareRiskLevels(a: RiskLevel, b: RiskLevel): number;
|
|
19
|
-
/**
|
|
20
|
-
* リスクレベルが閾値以上かチェック
|
|
21
|
-
*/
|
|
22
|
-
export declare function isRiskLevelAtLeast(level: RiskLevel, threshold: RiskLevel): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* アクションタイプ
|
|
25
|
-
*/
|
|
26
|
-
export type ActionType = 'file_read' | 'file_write' | 'file_delete' | 'file_move' | 'file_copy' | 'directory_create' | 'directory_delete' | 'command_execute' | 'network_request' | 'browser_navigate' | 'browser_click' | 'browser_type' | 'code_execute' | 'search' | 'analyze' | 'custom';
|
|
27
|
-
/**
|
|
28
|
-
* アクション
|
|
29
|
-
*/
|
|
30
|
-
export interface Action {
|
|
31
|
-
/** アクションタイプ */
|
|
32
|
-
type: ActionType;
|
|
33
|
-
/** アクション名 */
|
|
34
|
-
name: string;
|
|
35
|
-
/** ターゲット(ファイルパス、URL等) */
|
|
36
|
-
target?: string;
|
|
37
|
-
/** パラメータ */
|
|
38
|
-
params?: Record<string, unknown>;
|
|
39
|
-
/** コンテキスト情報 */
|
|
40
|
-
context?: ActionContext;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* アクションコンテキスト
|
|
44
|
-
*/
|
|
45
|
-
export interface ActionContext {
|
|
46
|
-
/** ユーザーID */
|
|
47
|
-
userId?: string;
|
|
48
|
-
/** セッションID */
|
|
49
|
-
sessionId?: string;
|
|
50
|
-
/** ソースツール名 */
|
|
51
|
-
sourceTool?: string;
|
|
52
|
-
/** 親タスクID */
|
|
53
|
-
parentTaskId?: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* オブザベーション(アクション実行結果)
|
|
57
|
-
*/
|
|
58
|
-
export interface Observation {
|
|
59
|
-
/** 成功フラグ */
|
|
60
|
-
success: boolean;
|
|
61
|
-
/** 結果データ */
|
|
62
|
-
data?: unknown;
|
|
63
|
-
/** エラーメッセージ */
|
|
64
|
-
error?: string;
|
|
65
|
-
/** 実行時間(ミリ秒) */
|
|
66
|
-
duration: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* パターンルール
|
|
70
|
-
*/
|
|
71
|
-
export interface PatternRule {
|
|
72
|
-
/** パターン(glob形式) */
|
|
73
|
-
pattern: string;
|
|
74
|
-
/** 説明 */
|
|
75
|
-
description?: string;
|
|
76
|
-
/** 適用するアクションタイプ */
|
|
77
|
-
actionTypes?: ActionType[];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* セキュリティポリシー(REQ-012)
|
|
81
|
-
*/
|
|
82
|
-
export interface SecurityPolicy {
|
|
83
|
-
/** 許可パターン(REQ-012-04) */
|
|
84
|
-
allowPatterns: PatternRule[];
|
|
85
|
-
/** 拒否パターン(REQ-012-03) */
|
|
86
|
-
denyPatterns: PatternRule[];
|
|
87
|
-
/** 確認が必要なリスクレベル(REQ-012-02) */
|
|
88
|
-
requireConfirmation: RiskLevel[];
|
|
89
|
-
/** 最大許容リスクレベル */
|
|
90
|
-
maxRiskLevel: RiskLevel;
|
|
91
|
-
/** カスタムリスクルール */
|
|
92
|
-
customRiskRules?: RiskRule[];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* リスクルール
|
|
96
|
-
*/
|
|
97
|
-
export interface RiskRule {
|
|
98
|
-
/** ルール名 */
|
|
99
|
-
name: string;
|
|
100
|
-
/** 説明 */
|
|
101
|
-
description: string;
|
|
102
|
-
/** マッチ条件 */
|
|
103
|
-
match: RiskRuleMatch;
|
|
104
|
-
/** 適用するリスクレベル */
|
|
105
|
-
riskLevel: RiskLevel;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* リスクルールのマッチ条件
|
|
109
|
-
*/
|
|
110
|
-
export interface RiskRuleMatch {
|
|
111
|
-
/** アクションタイプ */
|
|
112
|
-
actionTypes?: ActionType[];
|
|
113
|
-
/** ターゲットパターン(glob) */
|
|
114
|
-
targetPatterns?: string[];
|
|
115
|
-
/** パラメータ条件 */
|
|
116
|
-
paramConditions?: Record<string, unknown>;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* セキュリティ分析結果(REQ-012-01)
|
|
120
|
-
*/
|
|
121
|
-
export interface SecurityAnalysis {
|
|
122
|
-
/** リスクレベル */
|
|
123
|
-
riskLevel: RiskLevel;
|
|
124
|
-
/** リスク理由 */
|
|
125
|
-
reasons: string[];
|
|
126
|
-
/** 確認が必要か(REQ-012-02) */
|
|
127
|
-
requiresConfirmation: boolean;
|
|
128
|
-
/** 許可されるか */
|
|
129
|
-
allowed: boolean;
|
|
130
|
-
/** ブロック理由(許可されない場合) */
|
|
131
|
-
blockReason?: string;
|
|
132
|
-
/** マッチしたルール */
|
|
133
|
-
matchedRules: string[];
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* 監査ログエントリ(REQ-012-05)
|
|
137
|
-
*/
|
|
138
|
-
export interface AuditLogEntry {
|
|
139
|
-
/** エントリID */
|
|
140
|
-
id: string;
|
|
141
|
-
/** タイムスタンプ */
|
|
142
|
-
timestamp: string;
|
|
143
|
-
/** アクション */
|
|
144
|
-
action: Action;
|
|
145
|
-
/** セキュリティ分析結果 */
|
|
146
|
-
analysis: SecurityAnalysis;
|
|
147
|
-
/** 実行結果(実行された場合) */
|
|
148
|
-
observation?: Observation;
|
|
149
|
-
/** ユーザー確認の結果(確認が必要だった場合) */
|
|
150
|
-
userConfirmation?: UserConfirmation;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* ユーザー確認
|
|
154
|
-
*/
|
|
155
|
-
export interface UserConfirmation {
|
|
156
|
-
/** 確認されたか */
|
|
157
|
-
confirmed: boolean;
|
|
158
|
-
/** 確認時刻 */
|
|
159
|
-
confirmedAt?: string;
|
|
160
|
-
/** 確認者 */
|
|
161
|
-
confirmedBy?: string;
|
|
162
|
-
/** コメント */
|
|
163
|
-
comment?: string;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 監査ログフィルター
|
|
167
|
-
*/
|
|
168
|
-
export interface AuditLogFilter {
|
|
169
|
-
/** 開始日時 */
|
|
170
|
-
startTime?: string;
|
|
171
|
-
/** 終了日時 */
|
|
172
|
-
endTime?: string;
|
|
173
|
-
/** アクションタイプ */
|
|
174
|
-
actionTypes?: ActionType[];
|
|
175
|
-
/** リスクレベル(以上) */
|
|
176
|
-
minRiskLevel?: RiskLevel;
|
|
177
|
-
/** 成功/失敗 */
|
|
178
|
-
success?: boolean;
|
|
179
|
-
/** ユーザーID */
|
|
180
|
-
userId?: string;
|
|
181
|
-
/** 検索キーワード */
|
|
182
|
-
keyword?: string;
|
|
183
|
-
/** 最大件数 */
|
|
184
|
-
limit?: number;
|
|
185
|
-
/** オフセット */
|
|
186
|
-
offset?: number;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* デフォルトセキュリティポリシー
|
|
190
|
-
*/
|
|
191
|
-
export declare const DEFAULT_SECURITY_POLICY: SecurityPolicy;
|
|
192
|
-
/**
|
|
193
|
-
* ビルトインリスクルール
|
|
194
|
-
*/
|
|
195
|
-
export declare const BUILTIN_RISK_RULES: RiskRule[];
|
|
196
|
-
/**
|
|
197
|
-
* セキュリティエラーコード
|
|
198
|
-
*/
|
|
199
|
-
export type SecurityErrorCode = 'ACTION_BLOCKED' | 'RISK_TOO_HIGH' | 'CONFIRMATION_REQUIRED' | 'CONFIRMATION_DENIED' | 'POLICY_VIOLATION';
|
|
200
|
-
/**
|
|
201
|
-
* セキュリティエラー
|
|
202
|
-
*/
|
|
203
|
-
export declare class SecurityError extends Error {
|
|
204
|
-
readonly code: SecurityErrorCode;
|
|
205
|
-
readonly analysis?: SecurityAnalysis;
|
|
206
|
-
constructor(code: SecurityErrorCode, message: string, analysis?: SecurityAnalysis);
|
|
207
|
-
}
|
|
208
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAKtD,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAA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SAAQ,KAAK;aAEpB,IAAI,EAAE,iBAAiB;aAEvB,QAAQ,CAAC,EAAE,gBAAgB;gBAF3B,IAAI,EAAE,iBAAiB,EACvC,OAAO,EAAE,MAAM,EACC,QAAQ,CAAC,EAAE,gBAAgB;CAK9C"}
|
package/dist/types.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Security 型定義
|
|
4
|
-
*
|
|
5
|
-
* @requirement REQ-012
|
|
6
|
-
* @design REQ-012-01〜REQ-012-06
|
|
7
|
-
*/
|
|
8
|
-
var __extends = (this && this.__extends) || (function () {
|
|
9
|
-
var extendStatics = function (d, b) {
|
|
10
|
-
extendStatics = Object.setPrototypeOf ||
|
|
11
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
12
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
13
|
-
return extendStatics(d, b);
|
|
14
|
-
};
|
|
15
|
-
return function (d, b) {
|
|
16
|
-
if (typeof b !== "function" && b !== null)
|
|
17
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
18
|
-
extendStatics(d, b);
|
|
19
|
-
function __() { this.constructor = d; }
|
|
20
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
-
};
|
|
22
|
-
})();
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.SecurityError = exports.BUILTIN_RISK_RULES = exports.DEFAULT_SECURITY_POLICY = exports.RISK_LEVEL_ORDER = void 0;
|
|
25
|
-
exports.compareRiskLevels = compareRiskLevels;
|
|
26
|
-
exports.isRiskLevelAtLeast = isRiskLevelAtLeast;
|
|
27
|
-
/**
|
|
28
|
-
* リスクレベルの数値マッピング
|
|
29
|
-
*/
|
|
30
|
-
exports.RISK_LEVEL_ORDER = {
|
|
31
|
-
low: 1,
|
|
32
|
-
medium: 2,
|
|
33
|
-
high: 3,
|
|
34
|
-
critical: 4,
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* リスクレベル比較
|
|
38
|
-
*/
|
|
39
|
-
function compareRiskLevels(a, b) {
|
|
40
|
-
return exports.RISK_LEVEL_ORDER[a] - exports.RISK_LEVEL_ORDER[b];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* リスクレベルが閾値以上かチェック
|
|
44
|
-
*/
|
|
45
|
-
function isRiskLevelAtLeast(level, threshold) {
|
|
46
|
-
return exports.RISK_LEVEL_ORDER[level] >= exports.RISK_LEVEL_ORDER[threshold];
|
|
47
|
-
}
|
|
48
|
-
// ============================================================================
|
|
49
|
-
// デフォルト設定
|
|
50
|
-
// ============================================================================
|
|
51
|
-
/**
|
|
52
|
-
* デフォルトセキュリティポリシー
|
|
53
|
-
*/
|
|
54
|
-
exports.DEFAULT_SECURITY_POLICY = {
|
|
55
|
-
allowPatterns: [
|
|
56
|
-
{ pattern: '**/*.md', description: 'Markdown files are safe' },
|
|
57
|
-
{ pattern: '**/*.txt', description: 'Text files are safe' },
|
|
58
|
-
{ pattern: '**/*.json', description: 'JSON files are generally safe' },
|
|
59
|
-
],
|
|
60
|
-
denyPatterns: [
|
|
61
|
-
{ pattern: '/etc/**', description: 'System configuration files' },
|
|
62
|
-
{ pattern: '/usr/**', description: 'System binaries' },
|
|
63
|
-
{ pattern: '**/node_modules/**', description: 'Dependencies should not be modified' },
|
|
64
|
-
{ pattern: '**/.git/**', description: 'Git internal files' },
|
|
65
|
-
{ pattern: '**/.env*', description: 'Environment files with secrets' },
|
|
66
|
-
{ pattern: '**/*password*', description: 'Files with password in name' },
|
|
67
|
-
{ pattern: '**/*secret*', description: 'Files with secret in name' },
|
|
68
|
-
{ pattern: '**/*.key', description: 'Key files' },
|
|
69
|
-
{ pattern: '**/*.pem', description: 'Certificate files' },
|
|
70
|
-
],
|
|
71
|
-
requireConfirmation: ['high', 'critical'],
|
|
72
|
-
maxRiskLevel: 'critical',
|
|
73
|
-
customRiskRules: [],
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* ビルトインリスクルール
|
|
77
|
-
*/
|
|
78
|
-
exports.BUILTIN_RISK_RULES = [
|
|
79
|
-
{
|
|
80
|
-
name: 'file_delete_high_risk',
|
|
81
|
-
description: 'File deletion is high risk (REQ-012-06)',
|
|
82
|
-
match: { actionTypes: ['file_delete', 'directory_delete'] },
|
|
83
|
-
riskLevel: 'high',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: 'command_execute_high_risk',
|
|
87
|
-
description: 'Command execution is high risk',
|
|
88
|
-
match: { actionTypes: ['command_execute'] },
|
|
89
|
-
riskLevel: 'high',
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'code_execute_medium_risk',
|
|
93
|
-
description: 'Code execution is medium risk',
|
|
94
|
-
match: { actionTypes: ['code_execute'] },
|
|
95
|
-
riskLevel: 'medium',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: 'network_request_medium_risk',
|
|
99
|
-
description: 'Network requests are medium risk',
|
|
100
|
-
match: { actionTypes: ['network_request'] },
|
|
101
|
-
riskLevel: 'medium',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: 'file_write_low_risk',
|
|
105
|
-
description: 'File write is low risk by default',
|
|
106
|
-
match: { actionTypes: ['file_write'] },
|
|
107
|
-
riskLevel: 'low',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'file_read_low_risk',
|
|
111
|
-
description: 'File read is low risk',
|
|
112
|
-
match: { actionTypes: ['file_read', 'search', 'analyze'] },
|
|
113
|
-
riskLevel: 'low',
|
|
114
|
-
},
|
|
115
|
-
];
|
|
116
|
-
/**
|
|
117
|
-
* セキュリティエラー
|
|
118
|
-
*/
|
|
119
|
-
var SecurityError = /** @class */ (function (_super) {
|
|
120
|
-
__extends(SecurityError, _super);
|
|
121
|
-
function SecurityError(code, message, analysis) {
|
|
122
|
-
var _this = _super.call(this, message) || this;
|
|
123
|
-
_this.code = code;
|
|
124
|
-
_this.analysis = analysis;
|
|
125
|
-
_this.name = 'SecurityError';
|
|
126
|
-
return _this;
|
|
127
|
-
}
|
|
128
|
-
return SecurityError;
|
|
129
|
-
}(Error));
|
|
130
|
-
exports.SecurityError = SecurityError;
|