@sanctuary-framework/mcp-server 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +2377 -494
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2377 -494
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2379 -494
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +325 -42
- package/dist/index.d.ts +325 -42
- package/dist/index.js +2378 -495
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -4042,550 +4042,1380 @@ function generateDashboardHTML(options) {
|
|
|
4042
4042
|
<meta charset="utf-8">
|
|
4043
4043
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
4044
4044
|
<title>Sanctuary \u2014 Principal Dashboard</title>
|
|
4045
|
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
|
|
4045
4046
|
<style>
|
|
4046
4047
|
:root {
|
|
4047
|
-
--bg: #
|
|
4048
|
-
--
|
|
4049
|
-
--
|
|
4050
|
-
--
|
|
4051
|
-
--text: #
|
|
4052
|
-
--
|
|
4053
|
-
--
|
|
4054
|
-
--
|
|
4055
|
-
--
|
|
4056
|
-
--
|
|
4057
|
-
--
|
|
4058
|
-
--
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4048
|
+
--bg: #0d1117;
|
|
4049
|
+
--surface: #161b22;
|
|
4050
|
+
--border: #30363d;
|
|
4051
|
+
--text-primary: #e6edf3;
|
|
4052
|
+
--text-secondary: #8b949e;
|
|
4053
|
+
--green: #3fb950;
|
|
4054
|
+
--amber: #d29922;
|
|
4055
|
+
--red: #f85149;
|
|
4056
|
+
--blue: #58a6ff;
|
|
4057
|
+
--mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
|
|
4058
|
+
--sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
4059
|
+
--radius: 6px;
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
* {
|
|
4063
|
+
box-sizing: border-box;
|
|
4064
|
+
margin: 0;
|
|
4065
|
+
padding: 0;
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
html, body {
|
|
4069
|
+
width: 100%;
|
|
4070
|
+
height: 100%;
|
|
4071
|
+
overflow: hidden;
|
|
4072
|
+
}
|
|
4073
|
+
|
|
4069
4074
|
body {
|
|
4070
|
-
font-family: var(--
|
|
4075
|
+
font-family: var(--sans);
|
|
4071
4076
|
background: var(--bg);
|
|
4072
|
-
color: var(--text);
|
|
4073
|
-
|
|
4074
|
-
|
|
4077
|
+
color: var(--text-primary);
|
|
4078
|
+
display: flex;
|
|
4079
|
+
flex-direction: column;
|
|
4075
4080
|
}
|
|
4076
4081
|
|
|
4077
|
-
/*
|
|
4078
|
-
.container { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
|
|
4082
|
+
/* \u2500\u2500 Top Status Bar (fixed) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4079
4083
|
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
+
.status-bar {
|
|
4085
|
+
position: fixed;
|
|
4086
|
+
top: 0;
|
|
4087
|
+
left: 0;
|
|
4088
|
+
right: 0;
|
|
4089
|
+
height: 56px;
|
|
4090
|
+
background: var(--surface);
|
|
4091
|
+
border-bottom: 1px solid var(--border);
|
|
4092
|
+
display: flex;
|
|
4093
|
+
align-items: center;
|
|
4094
|
+
padding: 0 20px;
|
|
4095
|
+
gap: 24px;
|
|
4096
|
+
z-index: 1000;
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
.status-bar-left {
|
|
4100
|
+
display: flex;
|
|
4101
|
+
align-items: center;
|
|
4102
|
+
gap: 12px;
|
|
4103
|
+
flex: 0 0 auto;
|
|
4084
4104
|
}
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4105
|
+
|
|
4106
|
+
.sanctuary-logo {
|
|
4107
|
+
font-weight: 700;
|
|
4108
|
+
font-size: 16px;
|
|
4109
|
+
letter-spacing: -0.5px;
|
|
4110
|
+
color: var(--text-primary);
|
|
4111
|
+
}
|
|
4112
|
+
|
|
4113
|
+
.sanctuary-logo span {
|
|
4114
|
+
color: var(--blue);
|
|
4092
4115
|
}
|
|
4116
|
+
|
|
4117
|
+
.version {
|
|
4118
|
+
font-size: 11px;
|
|
4119
|
+
color: var(--text-secondary);
|
|
4120
|
+
font-family: var(--mono);
|
|
4121
|
+
}
|
|
4122
|
+
|
|
4123
|
+
.status-bar-center {
|
|
4124
|
+
flex: 1;
|
|
4125
|
+
display: flex;
|
|
4126
|
+
align-items: center;
|
|
4127
|
+
justify-content: center;
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
.sovereignty-badge {
|
|
4131
|
+
display: flex;
|
|
4132
|
+
align-items: center;
|
|
4133
|
+
gap: 8px;
|
|
4134
|
+
padding: 6px 12px;
|
|
4135
|
+
background: rgba(88, 166, 255, 0.1);
|
|
4136
|
+
border: 1px solid var(--blue);
|
|
4137
|
+
border-radius: 20px;
|
|
4138
|
+
font-size: 13px;
|
|
4139
|
+
font-weight: 600;
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
.sovereignty-score {
|
|
4143
|
+
display: flex;
|
|
4144
|
+
align-items: center;
|
|
4145
|
+
justify-content: center;
|
|
4146
|
+
width: 28px;
|
|
4147
|
+
height: 28px;
|
|
4148
|
+
border-radius: 50%;
|
|
4149
|
+
font-family: var(--mono);
|
|
4150
|
+
font-weight: 700;
|
|
4151
|
+
font-size: 12px;
|
|
4152
|
+
background: var(--blue);
|
|
4153
|
+
color: var(--bg);
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
.sovereignty-score.high {
|
|
4157
|
+
background: var(--green);
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
.sovereignty-score.medium {
|
|
4161
|
+
background: var(--amber);
|
|
4162
|
+
}
|
|
4163
|
+
|
|
4164
|
+
.sovereignty-score.low {
|
|
4165
|
+
background: var(--red);
|
|
4166
|
+
}
|
|
4167
|
+
|
|
4168
|
+
.status-bar-right {
|
|
4169
|
+
display: flex;
|
|
4170
|
+
align-items: center;
|
|
4171
|
+
gap: 16px;
|
|
4172
|
+
flex: 0 0 auto;
|
|
4173
|
+
}
|
|
4174
|
+
|
|
4175
|
+
.protections-indicator {
|
|
4176
|
+
display: flex;
|
|
4177
|
+
align-items: center;
|
|
4178
|
+
gap: 6px;
|
|
4179
|
+
font-size: 12px;
|
|
4180
|
+
color: var(--text-secondary);
|
|
4181
|
+
font-family: var(--mono);
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
.protections-indicator .count {
|
|
4185
|
+
color: var(--text-primary);
|
|
4186
|
+
font-weight: 600;
|
|
4187
|
+
}
|
|
4188
|
+
|
|
4189
|
+
.uptime {
|
|
4190
|
+
display: flex;
|
|
4191
|
+
align-items: center;
|
|
4192
|
+
gap: 6px;
|
|
4193
|
+
font-size: 12px;
|
|
4194
|
+
color: var(--text-secondary);
|
|
4195
|
+
font-family: var(--mono);
|
|
4196
|
+
}
|
|
4197
|
+
|
|
4093
4198
|
.status-dot {
|
|
4094
|
-
width: 8px;
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
/* Tabs */
|
|
4101
|
-
.tabs {
|
|
4102
|
-
display: flex; gap: 2px; margin-bottom: 20px;
|
|
4103
|
-
background: var(--bg-surface); border-radius: var(--radius);
|
|
4104
|
-
padding: 3px; border: 1px solid var(--border);
|
|
4105
|
-
}
|
|
4106
|
-
.tab {
|
|
4107
|
-
flex: 1; padding: 8px 12px; text-align: center;
|
|
4108
|
-
font-size: 13px; font-weight: 500; cursor: pointer;
|
|
4109
|
-
border-radius: 6px; border: none; color: var(--text-muted);
|
|
4110
|
-
background: transparent; transition: all 0.15s;
|
|
4111
|
-
}
|
|
4112
|
-
.tab:hover { color: var(--text); }
|
|
4113
|
-
.tab.active { background: var(--bg-elevated); color: var(--text); }
|
|
4114
|
-
.tab .count {
|
|
4115
|
-
display: inline-flex; align-items: center; justify-content: center;
|
|
4116
|
-
min-width: 18px; height: 18px; padding: 0 5px;
|
|
4117
|
-
font-size: 11px; font-weight: 600; border-radius: 9px;
|
|
4118
|
-
margin-left: 6px;
|
|
4119
|
-
}
|
|
4120
|
-
.tab .count.alert { background: var(--deny); color: white; }
|
|
4121
|
-
.tab .count.muted { background: var(--border); color: var(--text-muted); }
|
|
4122
|
-
|
|
4123
|
-
/* Tab Content */
|
|
4124
|
-
.tab-content { display: none; }
|
|
4125
|
-
.tab-content.active { display: block; }
|
|
4126
|
-
|
|
4127
|
-
/* Pending Requests */
|
|
4128
|
-
.pending-empty {
|
|
4129
|
-
text-align: center; padding: 60px 20px; color: var(--text-muted);
|
|
4130
|
-
}
|
|
4131
|
-
.pending-empty .icon { font-size: 32px; margin-bottom: 12px; }
|
|
4132
|
-
.pending-empty p { font-size: 14px; }
|
|
4133
|
-
|
|
4134
|
-
.request-card {
|
|
4135
|
-
background: var(--bg-surface); border: 1px solid var(--border);
|
|
4136
|
-
border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
|
|
4137
|
-
animation: slideIn 0.2s ease-out;
|
|
4138
|
-
}
|
|
4139
|
-
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
|
|
4140
|
-
.request-card.tier1 { border-left: 3px solid var(--tier1); }
|
|
4141
|
-
.request-card.tier2 { border-left: 3px solid var(--tier2); }
|
|
4142
|
-
.request-header {
|
|
4143
|
-
display: flex; align-items: center; justify-content: space-between;
|
|
4144
|
-
margin-bottom: 10px;
|
|
4145
|
-
}
|
|
4146
|
-
.request-op {
|
|
4147
|
-
font-family: var(--mono); font-size: 14px; font-weight: 600;
|
|
4148
|
-
}
|
|
4149
|
-
.tier-badge {
|
|
4150
|
-
font-size: 11px; font-weight: 600; padding: 2px 8px;
|
|
4151
|
-
border-radius: 4px; text-transform: uppercase;
|
|
4152
|
-
}
|
|
4153
|
-
.tier-badge.tier1 { background: rgba(248,113,113,0.15); color: var(--tier1); }
|
|
4154
|
-
.tier-badge.tier2 { background: rgba(251,191,36,0.15); color: var(--tier2); }
|
|
4155
|
-
.request-reason {
|
|
4156
|
-
font-size: 13px; color: var(--text-muted); margin-bottom: 12px;
|
|
4157
|
-
}
|
|
4158
|
-
.request-context {
|
|
4159
|
-
font-family: var(--mono); font-size: 12px; color: var(--text-muted);
|
|
4160
|
-
background: var(--bg); border-radius: 4px; padding: 8px 10px;
|
|
4161
|
-
margin-bottom: 14px; white-space: pre-wrap; word-break: break-all;
|
|
4162
|
-
max-height: 120px; overflow-y: auto;
|
|
4163
|
-
}
|
|
4164
|
-
.request-actions {
|
|
4165
|
-
display: flex; align-items: center; gap: 10px;
|
|
4199
|
+
width: 8px;
|
|
4200
|
+
height: 8px;
|
|
4201
|
+
border-radius: 50%;
|
|
4202
|
+
background: var(--green);
|
|
4203
|
+
animation: pulse 2s ease-in-out infinite;
|
|
4166
4204
|
}
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4205
|
+
|
|
4206
|
+
.status-dot.disconnected {
|
|
4207
|
+
background: var(--red);
|
|
4208
|
+
animation: none;
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
@keyframes pulse {
|
|
4212
|
+
0%, 100% { opacity: 1; }
|
|
4213
|
+
50% { opacity: 0.5; }
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
.pending-badge {
|
|
4217
|
+
display: inline-flex;
|
|
4218
|
+
align-items: center;
|
|
4219
|
+
justify-content: center;
|
|
4220
|
+
min-width: 24px;
|
|
4221
|
+
height: 24px;
|
|
4222
|
+
padding: 0 6px;
|
|
4223
|
+
background: var(--red);
|
|
4224
|
+
color: white;
|
|
4225
|
+
border-radius: 12px;
|
|
4226
|
+
font-size: 11px;
|
|
4227
|
+
font-weight: 700;
|
|
4228
|
+
animation: pulse 1s ease-in-out infinite;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
.pending-badge.hidden {
|
|
4232
|
+
display: none;
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
/* \u2500\u2500 Main Layout \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4236
|
+
|
|
4237
|
+
.main-container {
|
|
4238
|
+
flex: 1;
|
|
4239
|
+
display: flex;
|
|
4240
|
+
margin-top: 56px;
|
|
4241
|
+
overflow: hidden;
|
|
4171
4242
|
}
|
|
4172
|
-
|
|
4173
|
-
.
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4243
|
+
|
|
4244
|
+
.activity-feed {
|
|
4245
|
+
flex: 3;
|
|
4246
|
+
display: flex;
|
|
4247
|
+
flex-direction: column;
|
|
4248
|
+
border-right: 1px solid var(--border);
|
|
4249
|
+
overflow: hidden;
|
|
4250
|
+
}
|
|
4251
|
+
|
|
4252
|
+
.feed-header {
|
|
4253
|
+
padding: 16px 20px;
|
|
4254
|
+
border-bottom: 1px solid var(--border);
|
|
4255
|
+
display: flex;
|
|
4256
|
+
align-items: center;
|
|
4257
|
+
gap: 8px;
|
|
4258
|
+
font-size: 12px;
|
|
4259
|
+
font-weight: 600;
|
|
4260
|
+
text-transform: uppercase;
|
|
4261
|
+
letter-spacing: 0.5px;
|
|
4262
|
+
color: var(--text-secondary);
|
|
4263
|
+
}
|
|
4264
|
+
|
|
4265
|
+
.feed-header-dot {
|
|
4266
|
+
width: 6px;
|
|
4267
|
+
height: 6px;
|
|
4268
|
+
border-radius: 50%;
|
|
4269
|
+
background: var(--green);
|
|
4270
|
+
}
|
|
4271
|
+
|
|
4272
|
+
.activity-list {
|
|
4273
|
+
flex: 1;
|
|
4274
|
+
overflow-y: auto;
|
|
4275
|
+
overflow-x: hidden;
|
|
4276
|
+
}
|
|
4277
|
+
|
|
4278
|
+
.activity-item {
|
|
4279
|
+
padding: 12px 20px;
|
|
4280
|
+
border-bottom: 1px solid rgba(48, 54, 61, 0.5);
|
|
4281
|
+
font-size: 13px;
|
|
4178
4282
|
font-family: var(--mono);
|
|
4283
|
+
cursor: pointer;
|
|
4284
|
+
transition: background 0.15s;
|
|
4285
|
+
display: flex;
|
|
4286
|
+
align-items: flex-start;
|
|
4287
|
+
gap: 10px;
|
|
4288
|
+
}
|
|
4289
|
+
|
|
4290
|
+
.activity-item:hover {
|
|
4291
|
+
background: rgba(88, 166, 255, 0.05);
|
|
4292
|
+
}
|
|
4293
|
+
|
|
4294
|
+
.activity-item-icon {
|
|
4295
|
+
flex: 0 0 auto;
|
|
4296
|
+
width: 16px;
|
|
4297
|
+
text-align: center;
|
|
4298
|
+
font-size: 12px;
|
|
4299
|
+
color: var(--text-secondary);
|
|
4300
|
+
margin-top: 1px;
|
|
4301
|
+
}
|
|
4302
|
+
|
|
4303
|
+
.activity-item-content {
|
|
4304
|
+
flex: 1;
|
|
4305
|
+
min-width: 0;
|
|
4306
|
+
}
|
|
4307
|
+
|
|
4308
|
+
.activity-time {
|
|
4309
|
+
color: var(--text-secondary);
|
|
4310
|
+
font-size: 11px;
|
|
4311
|
+
margin-bottom: 2px;
|
|
4312
|
+
}
|
|
4313
|
+
|
|
4314
|
+
.activity-main {
|
|
4315
|
+
display: flex;
|
|
4316
|
+
gap: 8px;
|
|
4317
|
+
align-items: baseline;
|
|
4318
|
+
margin-bottom: 4px;
|
|
4319
|
+
}
|
|
4320
|
+
|
|
4321
|
+
.activity-tier {
|
|
4322
|
+
display: inline-flex;
|
|
4323
|
+
align-items: center;
|
|
4324
|
+
justify-content: center;
|
|
4325
|
+
width: 24px;
|
|
4326
|
+
height: 16px;
|
|
4327
|
+
font-size: 10px;
|
|
4328
|
+
font-weight: 700;
|
|
4329
|
+
border-radius: 3px;
|
|
4330
|
+
text-transform: uppercase;
|
|
4331
|
+
flex: 0 0 auto;
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4334
|
+
.activity-tier.t1 {
|
|
4335
|
+
background: rgba(248, 81, 73, 0.2);
|
|
4336
|
+
color: var(--red);
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
.activity-tier.t2 {
|
|
4340
|
+
background: rgba(210, 153, 34, 0.2);
|
|
4341
|
+
color: var(--amber);
|
|
4342
|
+
}
|
|
4343
|
+
|
|
4344
|
+
.activity-tier.t3 {
|
|
4345
|
+
background: rgba(63, 185, 80, 0.2);
|
|
4346
|
+
color: var(--green);
|
|
4347
|
+
}
|
|
4348
|
+
|
|
4349
|
+
.activity-tool {
|
|
4350
|
+
color: var(--text-primary);
|
|
4351
|
+
font-weight: 600;
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
.activity-outcome {
|
|
4355
|
+
color: var(--green);
|
|
4356
|
+
}
|
|
4357
|
+
|
|
4358
|
+
.activity-outcome.denied {
|
|
4359
|
+
color: var(--red);
|
|
4360
|
+
}
|
|
4361
|
+
|
|
4362
|
+
.activity-detail {
|
|
4363
|
+
font-size: 12px;
|
|
4364
|
+
color: var(--text-secondary);
|
|
4365
|
+
margin-left: 0;
|
|
4366
|
+
}
|
|
4367
|
+
|
|
4368
|
+
.activity-item.expanded .activity-detail {
|
|
4369
|
+
display: block;
|
|
4370
|
+
margin-top: 8px;
|
|
4371
|
+
padding: 10px;
|
|
4372
|
+
background: rgba(88, 166, 255, 0.08);
|
|
4373
|
+
border-left: 2px solid var(--blue);
|
|
4374
|
+
border-radius: 4px;
|
|
4179
4375
|
}
|
|
4180
|
-
.countdown.urgent { color: var(--deny); font-weight: 600; }
|
|
4181
4376
|
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4377
|
+
.activity-empty {
|
|
4378
|
+
display: flex;
|
|
4379
|
+
flex-direction: column;
|
|
4380
|
+
align-items: center;
|
|
4381
|
+
justify-content: center;
|
|
4382
|
+
height: 100%;
|
|
4383
|
+
color: var(--text-secondary);
|
|
4384
|
+
}
|
|
4385
|
+
|
|
4386
|
+
.activity-empty-icon {
|
|
4387
|
+
font-size: 32px;
|
|
4388
|
+
margin-bottom: 12px;
|
|
4389
|
+
}
|
|
4390
|
+
|
|
4391
|
+
.activity-empty-text {
|
|
4392
|
+
font-size: 14px;
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4395
|
+
/* \u2500\u2500 Protection Status Sidebar (40%) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4396
|
+
|
|
4397
|
+
.protection-sidebar {
|
|
4398
|
+
flex: 2;
|
|
4399
|
+
display: flex;
|
|
4400
|
+
flex-direction: column;
|
|
4401
|
+
background: rgba(22, 27, 34, 0.5);
|
|
4402
|
+
overflow: hidden;
|
|
4403
|
+
}
|
|
4404
|
+
|
|
4405
|
+
.sidebar-header {
|
|
4406
|
+
padding: 16px 20px;
|
|
4188
4407
|
border-bottom: 1px solid var(--border);
|
|
4408
|
+
font-size: 12px;
|
|
4409
|
+
font-weight: 600;
|
|
4410
|
+
text-transform: uppercase;
|
|
4411
|
+
letter-spacing: 0.5px;
|
|
4412
|
+
color: var(--text-secondary);
|
|
4413
|
+
display: flex;
|
|
4414
|
+
align-items: center;
|
|
4415
|
+
gap: 8px;
|
|
4416
|
+
}
|
|
4417
|
+
|
|
4418
|
+
.sidebar-content {
|
|
4419
|
+
flex: 1;
|
|
4420
|
+
overflow-y: auto;
|
|
4421
|
+
padding: 16px 16px;
|
|
4422
|
+
display: grid;
|
|
4423
|
+
grid-template-columns: 1fr 1fr;
|
|
4424
|
+
gap: 12px;
|
|
4425
|
+
}
|
|
4426
|
+
|
|
4427
|
+
.protection-card {
|
|
4428
|
+
background: var(--surface);
|
|
4429
|
+
border: 1px solid var(--border);
|
|
4430
|
+
border-radius: var(--radius);
|
|
4431
|
+
padding: 14px;
|
|
4432
|
+
display: flex;
|
|
4433
|
+
flex-direction: column;
|
|
4434
|
+
gap: 8px;
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4437
|
+
.protection-card-icon {
|
|
4438
|
+
font-size: 14px;
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
.protection-card-label {
|
|
4442
|
+
font-size: 11px;
|
|
4443
|
+
font-weight: 600;
|
|
4444
|
+
text-transform: uppercase;
|
|
4445
|
+
letter-spacing: 0.5px;
|
|
4446
|
+
color: var(--text-secondary);
|
|
4447
|
+
}
|
|
4448
|
+
|
|
4449
|
+
.protection-card-status {
|
|
4450
|
+
display: flex;
|
|
4451
|
+
align-items: center;
|
|
4452
|
+
gap: 6px;
|
|
4453
|
+
font-size: 12px;
|
|
4454
|
+
font-weight: 600;
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
.protection-card-status.active {
|
|
4458
|
+
color: var(--green);
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
.protection-card-status.inactive {
|
|
4462
|
+
color: var(--text-secondary);
|
|
4189
4463
|
}
|
|
4190
|
-
|
|
4191
|
-
|
|
4464
|
+
|
|
4465
|
+
.protection-card-stat {
|
|
4466
|
+
font-size: 11px;
|
|
4467
|
+
color: var(--text-secondary);
|
|
4468
|
+
font-family: var(--mono);
|
|
4469
|
+
margin-top: 4px;
|
|
4470
|
+
}
|
|
4471
|
+
|
|
4472
|
+
/* \u2500\u2500 Pending Approvals Overlay \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4473
|
+
|
|
4474
|
+
.pending-overlay {
|
|
4475
|
+
position: fixed;
|
|
4476
|
+
top: 56px;
|
|
4477
|
+
right: 0;
|
|
4478
|
+
bottom: 0;
|
|
4479
|
+
width: 0;
|
|
4480
|
+
background: var(--surface);
|
|
4481
|
+
border-left: 1px solid var(--border);
|
|
4482
|
+
z-index: 999;
|
|
4483
|
+
overflow-y: auto;
|
|
4484
|
+
transition: width 0.3s ease-out;
|
|
4485
|
+
display: flex;
|
|
4486
|
+
flex-direction: column;
|
|
4487
|
+
}
|
|
4488
|
+
|
|
4489
|
+
.pending-overlay.active {
|
|
4490
|
+
width: 380px;
|
|
4491
|
+
}
|
|
4492
|
+
|
|
4493
|
+
@media (max-width: 1400px) {
|
|
4494
|
+
.pending-overlay.active {
|
|
4495
|
+
width: 100%;
|
|
4496
|
+
right: auto;
|
|
4497
|
+
left: 0;
|
|
4498
|
+
}
|
|
4499
|
+
}
|
|
4500
|
+
|
|
4501
|
+
.pending-overlay-header {
|
|
4502
|
+
padding: 16px 20px;
|
|
4192
4503
|
border-bottom: 1px solid var(--border);
|
|
4504
|
+
display: flex;
|
|
4505
|
+
align-items: center;
|
|
4506
|
+
justify-content: space-between;
|
|
4507
|
+
flex: 0 0 auto;
|
|
4508
|
+
}
|
|
4509
|
+
|
|
4510
|
+
.pending-overlay-title {
|
|
4511
|
+
font-size: 13px;
|
|
4512
|
+
font-weight: 600;
|
|
4513
|
+
text-transform: uppercase;
|
|
4514
|
+
letter-spacing: 0.5px;
|
|
4515
|
+
color: var(--text-primary);
|
|
4516
|
+
}
|
|
4517
|
+
|
|
4518
|
+
.pending-overlay-close {
|
|
4519
|
+
background: none;
|
|
4520
|
+
border: none;
|
|
4521
|
+
color: var(--text-secondary);
|
|
4522
|
+
cursor: pointer;
|
|
4523
|
+
font-size: 18px;
|
|
4524
|
+
padding: 0;
|
|
4525
|
+
display: flex;
|
|
4526
|
+
align-items: center;
|
|
4527
|
+
justify-content: center;
|
|
4528
|
+
}
|
|
4529
|
+
|
|
4530
|
+
.pending-overlay-close:hover {
|
|
4531
|
+
color: var(--text-primary);
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
.pending-list {
|
|
4535
|
+
flex: 1;
|
|
4536
|
+
overflow-y: auto;
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4539
|
+
.pending-item {
|
|
4540
|
+
padding: 16px 20px;
|
|
4541
|
+
border-bottom: 1px solid rgba(48, 54, 61, 0.5);
|
|
4542
|
+
display: flex;
|
|
4543
|
+
flex-direction: column;
|
|
4544
|
+
gap: 10px;
|
|
4193
4545
|
}
|
|
4194
|
-
|
|
4195
|
-
.
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
font-size:
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
.
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
background: var(--
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
.
|
|
4231
|
-
font-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4546
|
+
|
|
4547
|
+
.pending-item-header {
|
|
4548
|
+
display: flex;
|
|
4549
|
+
align-items: center;
|
|
4550
|
+
gap: 8px;
|
|
4551
|
+
}
|
|
4552
|
+
|
|
4553
|
+
.pending-item-op {
|
|
4554
|
+
font-family: var(--mono);
|
|
4555
|
+
font-size: 12px;
|
|
4556
|
+
font-weight: 600;
|
|
4557
|
+
color: var(--text-primary);
|
|
4558
|
+
flex: 1;
|
|
4559
|
+
}
|
|
4560
|
+
|
|
4561
|
+
.pending-item-tier {
|
|
4562
|
+
display: inline-flex;
|
|
4563
|
+
align-items: center;
|
|
4564
|
+
justify-content: center;
|
|
4565
|
+
width: 28px;
|
|
4566
|
+
height: 20px;
|
|
4567
|
+
font-size: 9px;
|
|
4568
|
+
font-weight: 700;
|
|
4569
|
+
border-radius: 3px;
|
|
4570
|
+
text-transform: uppercase;
|
|
4571
|
+
color: white;
|
|
4572
|
+
}
|
|
4573
|
+
|
|
4574
|
+
.pending-item-tier.tier1 {
|
|
4575
|
+
background: var(--red);
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4578
|
+
.pending-item-tier.tier2 {
|
|
4579
|
+
background: var(--amber);
|
|
4580
|
+
}
|
|
4581
|
+
|
|
4582
|
+
.pending-item-reason {
|
|
4583
|
+
font-size: 12px;
|
|
4584
|
+
color: var(--text-secondary);
|
|
4585
|
+
}
|
|
4586
|
+
|
|
4587
|
+
.pending-item-timer {
|
|
4588
|
+
display: flex;
|
|
4589
|
+
align-items: center;
|
|
4590
|
+
gap: 6px;
|
|
4591
|
+
font-size: 11px;
|
|
4592
|
+
font-family: var(--mono);
|
|
4593
|
+
color: var(--text-secondary);
|
|
4594
|
+
}
|
|
4595
|
+
|
|
4596
|
+
.pending-item-timer-bar {
|
|
4597
|
+
flex: 1;
|
|
4598
|
+
height: 4px;
|
|
4599
|
+
background: rgba(48, 54, 61, 0.8);
|
|
4600
|
+
border-radius: 2px;
|
|
4601
|
+
overflow: hidden;
|
|
4602
|
+
}
|
|
4603
|
+
|
|
4604
|
+
.pending-item-timer-fill {
|
|
4605
|
+
height: 100%;
|
|
4606
|
+
background: var(--blue);
|
|
4607
|
+
transition: width 0.1s linear;
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4610
|
+
.pending-item-timer.urgent .pending-item-timer-fill {
|
|
4611
|
+
background: var(--red);
|
|
4612
|
+
}
|
|
4613
|
+
|
|
4614
|
+
.pending-item-actions {
|
|
4615
|
+
display: flex;
|
|
4616
|
+
gap: 8px;
|
|
4617
|
+
}
|
|
4618
|
+
|
|
4619
|
+
.btn {
|
|
4620
|
+
flex: 1;
|
|
4621
|
+
padding: 8px 12px;
|
|
4622
|
+
border: none;
|
|
4623
|
+
border-radius: var(--radius);
|
|
4624
|
+
font-size: 12px;
|
|
4625
|
+
font-weight: 600;
|
|
4626
|
+
cursor: pointer;
|
|
4627
|
+
transition: all 0.15s;
|
|
4628
|
+
font-family: var(--sans);
|
|
4629
|
+
}
|
|
4630
|
+
|
|
4631
|
+
.btn-approve {
|
|
4632
|
+
background: var(--green);
|
|
4633
|
+
color: var(--bg);
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4636
|
+
.btn-approve:hover {
|
|
4637
|
+
background: #4ecf5e;
|
|
4638
|
+
}
|
|
4639
|
+
|
|
4640
|
+
.btn-deny {
|
|
4641
|
+
background: var(--red);
|
|
4642
|
+
color: white;
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4645
|
+
.btn-deny:hover {
|
|
4646
|
+
background: #f9605e;
|
|
4647
|
+
}
|
|
4648
|
+
|
|
4649
|
+
/* \u2500\u2500 Threat Panel (collapsible footer) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4650
|
+
|
|
4651
|
+
.threat-panel {
|
|
4652
|
+
position: fixed;
|
|
4653
|
+
bottom: 0;
|
|
4654
|
+
left: 0;
|
|
4655
|
+
right: 0;
|
|
4656
|
+
background: var(--surface);
|
|
4237
4657
|
border-top: 1px solid var(--border);
|
|
4238
|
-
|
|
4658
|
+
max-height: 240px;
|
|
4659
|
+
z-index: 500;
|
|
4660
|
+
display: flex;
|
|
4661
|
+
flex-direction: column;
|
|
4662
|
+
transition: max-height 0.3s ease-out;
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
.threat-panel.collapsed {
|
|
4666
|
+
max-height: 40px;
|
|
4667
|
+
}
|
|
4668
|
+
|
|
4669
|
+
.threat-header {
|
|
4670
|
+
padding: 12px 20px;
|
|
4671
|
+
cursor: pointer;
|
|
4672
|
+
display: flex;
|
|
4673
|
+
align-items: center;
|
|
4674
|
+
gap: 8px;
|
|
4675
|
+
font-size: 12px;
|
|
4676
|
+
font-weight: 600;
|
|
4677
|
+
text-transform: uppercase;
|
|
4678
|
+
letter-spacing: 0.5px;
|
|
4679
|
+
color: var(--text-secondary);
|
|
4680
|
+
flex: 0 0 auto;
|
|
4681
|
+
}
|
|
4682
|
+
|
|
4683
|
+
.threat-header:hover {
|
|
4684
|
+
background: rgba(88, 166, 255, 0.05);
|
|
4685
|
+
}
|
|
4686
|
+
|
|
4687
|
+
.threat-icon {
|
|
4688
|
+
font-size: 14px;
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4691
|
+
.threat-content {
|
|
4692
|
+
flex: 1;
|
|
4693
|
+
overflow-y: auto;
|
|
4694
|
+
padding: 0 20px 12px;
|
|
4695
|
+
display: flex;
|
|
4696
|
+
flex-direction: column;
|
|
4697
|
+
gap: 10px;
|
|
4698
|
+
}
|
|
4699
|
+
|
|
4700
|
+
.threat-item {
|
|
4701
|
+
padding: 8px 10px;
|
|
4702
|
+
background: rgba(248, 81, 73, 0.1);
|
|
4703
|
+
border-left: 2px solid var(--red);
|
|
4704
|
+
border-radius: 4px;
|
|
4705
|
+
font-size: 11px;
|
|
4706
|
+
color: var(--text-secondary);
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
.threat-item-type {
|
|
4710
|
+
font-weight: 600;
|
|
4711
|
+
color: var(--red);
|
|
4712
|
+
font-family: var(--mono);
|
|
4713
|
+
}
|
|
4714
|
+
|
|
4715
|
+
.threat-empty {
|
|
4239
4716
|
text-align: center;
|
|
4717
|
+
padding: 20px 10px;
|
|
4718
|
+
color: var(--text-secondary);
|
|
4719
|
+
font-size: 12px;
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4722
|
+
/* \u2500\u2500 Scrollbars \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4723
|
+
|
|
4724
|
+
::-webkit-scrollbar {
|
|
4725
|
+
width: 6px;
|
|
4726
|
+
}
|
|
4727
|
+
|
|
4728
|
+
::-webkit-scrollbar-track {
|
|
4729
|
+
background: transparent;
|
|
4730
|
+
}
|
|
4731
|
+
|
|
4732
|
+
::-webkit-scrollbar-thumb {
|
|
4733
|
+
background: var(--border);
|
|
4734
|
+
border-radius: 3px;
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4737
|
+
::-webkit-scrollbar-thumb:hover {
|
|
4738
|
+
background: rgba(88, 166, 255, 0.3);
|
|
4739
|
+
}
|
|
4740
|
+
|
|
4741
|
+
/* \u2500\u2500 Responsive \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
4742
|
+
|
|
4743
|
+
@media (max-width: 1200px) {
|
|
4744
|
+
.protection-sidebar {
|
|
4745
|
+
display: none;
|
|
4746
|
+
}
|
|
4747
|
+
|
|
4748
|
+
.activity-feed {
|
|
4749
|
+
border-right: none;
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
|
|
4753
|
+
@media (max-width: 768px) {
|
|
4754
|
+
.status-bar {
|
|
4755
|
+
padding: 0 12px;
|
|
4756
|
+
gap: 12px;
|
|
4757
|
+
height: 48px;
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
.sanctuary-logo {
|
|
4761
|
+
font-size: 14px;
|
|
4762
|
+
}
|
|
4763
|
+
|
|
4764
|
+
.status-bar-center {
|
|
4765
|
+
display: none;
|
|
4766
|
+
}
|
|
4767
|
+
|
|
4768
|
+
.main-container {
|
|
4769
|
+
margin-top: 48px;
|
|
4770
|
+
}
|
|
4771
|
+
|
|
4772
|
+
.activity-item {
|
|
4773
|
+
padding: 10px 12px;
|
|
4774
|
+
}
|
|
4775
|
+
|
|
4776
|
+
.pending-overlay.active {
|
|
4777
|
+
width: 100%;
|
|
4778
|
+
}
|
|
4779
|
+
|
|
4780
|
+
.threat-panel {
|
|
4781
|
+
max-height: 200px;
|
|
4782
|
+
}
|
|
4240
4783
|
}
|
|
4241
4784
|
</style>
|
|
4242
4785
|
</head>
|
|
4243
4786
|
<body>
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4787
|
+
|
|
4788
|
+
<!-- Status Bar (fixed, top) -->
|
|
4789
|
+
<div class="status-bar">
|
|
4790
|
+
<div class="status-bar-left">
|
|
4791
|
+
<div class="sanctuary-logo"><span>\u25C6</span> SANCTUARY</div>
|
|
4792
|
+
<div class="version">v${options.serverVersion}</div>
|
|
4793
|
+
</div>
|
|
4794
|
+
<div class="status-bar-center">
|
|
4795
|
+
<div class="sovereignty-badge">
|
|
4796
|
+
<div class="sovereignty-score" id="sovereigntyScore">85</div>
|
|
4797
|
+
<span>Sovereignty Health</span>
|
|
4798
|
+
</div>
|
|
4799
|
+
</div>
|
|
4800
|
+
<div class="status-bar-right">
|
|
4801
|
+
<div class="protections-indicator">
|
|
4802
|
+
<span class="count" id="activeProtections">6</span>/6 protections
|
|
4803
|
+
</div>
|
|
4804
|
+
<div class="uptime">
|
|
4805
|
+
<span id="uptimeText">\u2014</span>
|
|
4250
4806
|
</div>
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
<div class="tabs">
|
|
4254
|
-
<button class="tab active" data-tab="pending">
|
|
4255
|
-
Pending<span class="count muted" id="pendingCount">0</span>
|
|
4256
|
-
</button>
|
|
4257
|
-
<button class="tab" data-tab="audit">
|
|
4258
|
-
Audit Log<span class="count muted" id="auditCount">0</span>
|
|
4259
|
-
</button>
|
|
4260
|
-
<button class="tab" data-tab="baseline">Baseline</button>
|
|
4261
|
-
<button class="tab" data-tab="policy">Policy</button>
|
|
4807
|
+
<div class="status-dot" id="statusDot"></div>
|
|
4808
|
+
<div class="pending-badge hidden" id="pendingBadge">0</div>
|
|
4262
4809
|
</div>
|
|
4810
|
+
</div>
|
|
4811
|
+
|
|
4812
|
+
<!-- Main Layout -->
|
|
4813
|
+
<div class="main-container">
|
|
4814
|
+
<!-- Activity Feed -->
|
|
4815
|
+
<div class="activity-feed">
|
|
4816
|
+
<div class="feed-header">
|
|
4817
|
+
<div class="feed-header-dot"></div>
|
|
4818
|
+
Live Activity
|
|
4819
|
+
</div>
|
|
4820
|
+
<div class="activity-list" id="activityList">
|
|
4821
|
+
<div class="activity-empty">
|
|
4822
|
+
<div class="activity-empty-icon">\u2192</div>
|
|
4823
|
+
<div class="activity-empty-text">Waiting for activity...</div>
|
|
4824
|
+
</div>
|
|
4825
|
+
</div>
|
|
4826
|
+
</div>
|
|
4827
|
+
|
|
4828
|
+
<!-- Protection Status Sidebar -->
|
|
4829
|
+
<div class="protection-sidebar" id="protectionSidebar">
|
|
4830
|
+
<div class="sidebar-header">
|
|
4831
|
+
<span>\u25C6</span> Protection Status
|
|
4832
|
+
</div>
|
|
4833
|
+
<div class="sidebar-content">
|
|
4834
|
+
<div class="protection-card">
|
|
4835
|
+
<div class="protection-card-icon">\u{1F510}</div>
|
|
4836
|
+
<div class="protection-card-label">Encryption</div>
|
|
4837
|
+
<div class="protection-card-status active" id="encryptionStatus">\u2713 Active</div>
|
|
4838
|
+
<div class="protection-card-stat" id="encryptionStat">Ed25519</div>
|
|
4839
|
+
</div>
|
|
4840
|
+
|
|
4841
|
+
<div class="protection-card">
|
|
4842
|
+
<div class="protection-card-icon">\u2713</div>
|
|
4843
|
+
<div class="protection-card-label">Approval Gate</div>
|
|
4844
|
+
<div class="protection-card-status active" id="approvalStatus">\u2713 Active</div>
|
|
4845
|
+
<div class="protection-card-stat" id="approvalStat">T1: 2 | T2: 3</div>
|
|
4846
|
+
</div>
|
|
4847
|
+
|
|
4848
|
+
<div class="protection-card">
|
|
4849
|
+
<div class="protection-card-icon">\u{1F3AF}</div>
|
|
4850
|
+
<div class="protection-card-label">Context Gating</div>
|
|
4851
|
+
<div class="protection-card-status active" id="contextStatus">\u2713 Active</div>
|
|
4852
|
+
<div class="protection-card-stat" id="contextStat">12 filtered</div>
|
|
4853
|
+
</div>
|
|
4854
|
+
|
|
4855
|
+
<div class="protection-card">
|
|
4856
|
+
<div class="protection-card-icon">\u26A0</div>
|
|
4857
|
+
<div class="protection-card-label">Injection Detection</div>
|
|
4858
|
+
<div class="protection-card-status active" id="injectionStatus">\u2713 Active</div>
|
|
4859
|
+
<div class="protection-card-stat" id="injectionStat">3 flags today</div>
|
|
4860
|
+
</div>
|
|
4861
|
+
|
|
4862
|
+
<div class="protection-card">
|
|
4863
|
+
<div class="protection-card-icon">\u{1F4CA}</div>
|
|
4864
|
+
<div class="protection-card-label">Behavioral Baseline</div>
|
|
4865
|
+
<div class="protection-card-status active" id="baselineStatus">\u2713 Active</div>
|
|
4866
|
+
<div class="protection-card-stat" id="baselineStat">0 anomalies</div>
|
|
4867
|
+
</div>
|
|
4868
|
+
|
|
4869
|
+
<div class="protection-card">
|
|
4870
|
+
<div class="protection-card-icon">\u{1F4CB}</div>
|
|
4871
|
+
<div class="protection-card-label">Audit Trail</div>
|
|
4872
|
+
<div class="protection-card-status active" id="auditStatus">\u2713 Active</div>
|
|
4873
|
+
<div class="protection-card-stat" id="auditStat">284 entries</div>
|
|
4874
|
+
</div>
|
|
4875
|
+
</div>
|
|
4876
|
+
</div>
|
|
4877
|
+
</div>
|
|
4878
|
+
|
|
4879
|
+
<!-- Pending Approvals Overlay -->
|
|
4880
|
+
<div class="pending-overlay" id="pendingOverlay">
|
|
4881
|
+
<div class="pending-overlay-header">
|
|
4882
|
+
<div class="pending-overlay-title">Pending Approvals</div>
|
|
4883
|
+
<button class="pending-overlay-close" onclick="closePendingOverlay()">\xD7</button>
|
|
4884
|
+
</div>
|
|
4885
|
+
<div class="pending-list" id="pendingList"></div>
|
|
4886
|
+
</div>
|
|
4887
|
+
|
|
4888
|
+
<!-- Threat Panel (collapsible footer) -->
|
|
4889
|
+
<div class="threat-panel collapsed" id="threatPanel">
|
|
4890
|
+
<div class="threat-header" onclick="toggleThreatPanel()">
|
|
4891
|
+
<span class="threat-icon">\u26A0</span>
|
|
4892
|
+
Recent Threats
|
|
4893
|
+
<span id="threatCount" style="margin-left: auto; color: var(--red); font-weight: 700;">0</span>
|
|
4894
|
+
</div>
|
|
4895
|
+
<div class="threat-content" id="threatContent">
|
|
4896
|
+
<div class="threat-empty">No threats detected</div>
|
|
4897
|
+
</div>
|
|
4898
|
+
</div>
|
|
4899
|
+
|
|
4900
|
+
<script>
|
|
4901
|
+
(function() {
|
|
4902
|
+
'use strict';
|
|
4903
|
+
|
|
4904
|
+
// \u2500\u2500 Configuration \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4905
|
+
|
|
4906
|
+
const TIMEOUT_SECONDS = ${options.timeoutSeconds};
|
|
4907
|
+
const AUTH_TOKEN = ${options.authToken ? JSON.stringify(options.authToken) : "null"};
|
|
4908
|
+
const MAX_ACTIVITY_ITEMS = 100;
|
|
4909
|
+
const MAX_THREAT_ITEMS = 20;
|
|
4910
|
+
|
|
4911
|
+
// \u2500\u2500 State \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4912
|
+
|
|
4913
|
+
let SESSION_ID = null;
|
|
4914
|
+
let evtSource = null;
|
|
4915
|
+
let startTime = Date.now();
|
|
4916
|
+
let activityCount = 0;
|
|
4917
|
+
let threatCount = 0;
|
|
4918
|
+
const pendingRequests = new Map();
|
|
4919
|
+
const activityItems = [];
|
|
4920
|
+
const threatItems = [];
|
|
4921
|
+
let sovereigntyScore = 85;
|
|
4922
|
+
|
|
4923
|
+
// \u2500\u2500 Auth Helpers (SEC-012) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4924
|
+
|
|
4925
|
+
function authHeaders() {
|
|
4926
|
+
const h = { 'Content-Type': 'application/json' };
|
|
4927
|
+
if (AUTH_TOKEN) h['Authorization'] = 'Bearer ' + AUTH_TOKEN;
|
|
4928
|
+
return h;
|
|
4929
|
+
}
|
|
4930
|
+
|
|
4931
|
+
function sessionQuery(url) {
|
|
4932
|
+
if (!SESSION_ID) return url;
|
|
4933
|
+
const sep = url.includes('?') ? '&' : '?';
|
|
4934
|
+
return url + sep + 'session=' + SESSION_ID;
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4937
|
+
async function exchangeSession() {
|
|
4938
|
+
if (!AUTH_TOKEN) return;
|
|
4939
|
+
try {
|
|
4940
|
+
const resp = await fetch('/auth/session', { method: 'POST', headers: authHeaders() });
|
|
4941
|
+
if (resp.ok) {
|
|
4942
|
+
const data = await resp.json();
|
|
4943
|
+
SESSION_ID = data.session_id;
|
|
4944
|
+
const refreshMs = (data.expires_in_seconds || 300) * 800;
|
|
4945
|
+
setTimeout(() => { exchangeSession(); reconnectSSE(); }, refreshMs);
|
|
4946
|
+
}
|
|
4947
|
+
} catch (e) {
|
|
4948
|
+
// Retry on next connect
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
|
|
4952
|
+
// \u2500\u2500 UI Utilities \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4953
|
+
|
|
4954
|
+
function esc(s) {
|
|
4955
|
+
const d = document.createElement('div');
|
|
4956
|
+
d.textContent = String(s || '');
|
|
4957
|
+
return d.innerHTML;
|
|
4958
|
+
}
|
|
4959
|
+
|
|
4960
|
+
function closePendingOverlay() {
|
|
4961
|
+
document.getElementById('pendingOverlay').classList.remove('active');
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
function toggleThreatPanel() {
|
|
4965
|
+
document.getElementById('threatPanel').classList.toggle('collapsed');
|
|
4966
|
+
}
|
|
4967
|
+
|
|
4968
|
+
function updateUptime() {
|
|
4969
|
+
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
|
4970
|
+
const hours = Math.floor(elapsed / 3600);
|
|
4971
|
+
const mins = Math.floor((elapsed % 3600) / 60);
|
|
4972
|
+
const secs = elapsed % 60;
|
|
4973
|
+
let uptimeStr = '';
|
|
4974
|
+
if (hours > 0) uptimeStr += hours + 'h ';
|
|
4975
|
+
if (mins > 0) uptimeStr += mins + 'm ';
|
|
4976
|
+
uptimeStr += secs + 's';
|
|
4977
|
+
document.getElementById('uptimeText').textContent = uptimeStr;
|
|
4978
|
+
}
|
|
4979
|
+
|
|
4980
|
+
// \u2500\u2500 Sovereignty Score \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4981
|
+
|
|
4982
|
+
function updateSovereigntyScore(score) {
|
|
4983
|
+
sovereigntyScore = Math.min(100, Math.max(0, score || 85));
|
|
4984
|
+
const badge = document.getElementById('sovereigntyScore');
|
|
4985
|
+
badge.textContent = sovereigntyScore;
|
|
4986
|
+
badge.className = 'sovereignty-score';
|
|
4987
|
+
if (sovereigntyScore >= 80) {
|
|
4988
|
+
badge.classList.add('high');
|
|
4989
|
+
} else if (sovereigntyScore >= 50) {
|
|
4990
|
+
badge.classList.add('medium');
|
|
4991
|
+
} else {
|
|
4992
|
+
badge.classList.add('low');
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
|
|
4996
|
+
// \u2500\u2500 Activity Feed \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4997
|
+
|
|
4998
|
+
function addActivityItem(data) {
|
|
4999
|
+
const {
|
|
5000
|
+
timestamp,
|
|
5001
|
+
tier,
|
|
5002
|
+
tool,
|
|
5003
|
+
outcome,
|
|
5004
|
+
detail,
|
|
5005
|
+
hasInjection,
|
|
5006
|
+
isContextGated
|
|
5007
|
+
} = data;
|
|
5008
|
+
|
|
5009
|
+
const item = {
|
|
5010
|
+
id: 'activity-' + activityCount++,
|
|
5011
|
+
timestamp: timestamp || new Date().toISOString(),
|
|
5012
|
+
tier: tier || 1,
|
|
5013
|
+
tool: tool || 'unknown_tool',
|
|
5014
|
+
outcome: outcome || 'executed',
|
|
5015
|
+
detail: detail || '',
|
|
5016
|
+
hasInjection: !!hasInjection,
|
|
5017
|
+
isContextGated: !!isContextGated
|
|
5018
|
+
};
|
|
5019
|
+
|
|
5020
|
+
activityItems.unshift(item);
|
|
5021
|
+
if (activityItems.length > MAX_ACTIVITY_ITEMS) {
|
|
5022
|
+
activityItems.pop();
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
renderActivityFeed();
|
|
5026
|
+
}
|
|
5027
|
+
|
|
5028
|
+
function renderActivityFeed() {
|
|
5029
|
+
const list = document.getElementById('activityList');
|
|
5030
|
+
|
|
5031
|
+
if (activityItems.length === 0) {
|
|
5032
|
+
list.innerHTML = '<div class="activity-empty"><div class="activity-empty-icon">\u2192</div><div class="activity-empty-text">Waiting for activity...</div></div>';
|
|
5033
|
+
return;
|
|
5034
|
+
}
|
|
5035
|
+
|
|
5036
|
+
list.innerHTML = '';
|
|
5037
|
+
for (const item of activityItems) {
|
|
5038
|
+
const tr = document.createElement('div');
|
|
5039
|
+
tr.className = 'activity-item';
|
|
5040
|
+
tr.id = item.id;
|
|
5041
|
+
|
|
5042
|
+
const time = new Date(item.timestamp);
|
|
5043
|
+
const timeStr = time.toLocaleTimeString();
|
|
5044
|
+
|
|
5045
|
+
const tierClass = 't' + item.tier;
|
|
5046
|
+
const outcomeClass = item.outcome === 'denied' ? 'outcome denied' : 'outcome';
|
|
5047
|
+
|
|
5048
|
+
let icon = '\u25CF';
|
|
5049
|
+
if (item.isContextGated) icon = '\u{1F3AF}';
|
|
5050
|
+
else if (item.hasInjection) icon = '\u26A0';
|
|
5051
|
+
else if (item.outcome === 'denied') icon = '\u2717';
|
|
5052
|
+
else icon = '\u2713';
|
|
5053
|
+
|
|
5054
|
+
tr.innerHTML =
|
|
5055
|
+
'<div class="activity-item-icon">' + esc(icon) + '</div>' +
|
|
5056
|
+
'<div class="activity-item-content">' +
|
|
5057
|
+
'<div class="activity-time">' + esc(timeStr) + '</div>' +
|
|
5058
|
+
'<div class="activity-main">' +
|
|
5059
|
+
'<span class="activity-tier ' + tierClass + '">T' + item.tier + '</span>' +
|
|
5060
|
+
'<span class="activity-tool">' + esc(item.tool) + '</span>' +
|
|
5061
|
+
'<span class="activity-outcome ' + (outcomeClass === 'outcome denied' ? 'denied' : '') + '">' + (item.outcome === 'denied' ? '\u2717 denied' : '\u2713 allowed') + '</span>' +
|
|
5062
|
+
'</div>' +
|
|
5063
|
+
'<div class="activity-detail">' + esc(item.detail) + '</div>' +
|
|
5064
|
+
'</div>' +
|
|
5065
|
+
'';
|
|
5066
|
+
|
|
5067
|
+
tr.addEventListener('click', () => {
|
|
5068
|
+
tr.classList.toggle('expanded');
|
|
5069
|
+
});
|
|
5070
|
+
|
|
5071
|
+
list.appendChild(tr);
|
|
5072
|
+
}
|
|
5073
|
+
}
|
|
5074
|
+
|
|
5075
|
+
// \u2500\u2500 Pending Approvals \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
5076
|
+
|
|
5077
|
+
function addPendingRequest(data) {
|
|
5078
|
+
const {
|
|
5079
|
+
request_id,
|
|
5080
|
+
operation,
|
|
5081
|
+
tier,
|
|
5082
|
+
reason,
|
|
5083
|
+
context,
|
|
5084
|
+
timestamp
|
|
5085
|
+
} = data;
|
|
5086
|
+
|
|
5087
|
+
const pending = {
|
|
5088
|
+
id: request_id,
|
|
5089
|
+
operation: operation || 'unknown',
|
|
5090
|
+
tier: tier || 1,
|
|
5091
|
+
reason: reason || '',
|
|
5092
|
+
context: context || {},
|
|
5093
|
+
timestamp: timestamp || new Date().toISOString(),
|
|
5094
|
+
remaining: TIMEOUT_SECONDS
|
|
5095
|
+
};
|
|
5096
|
+
|
|
5097
|
+
pendingRequests.set(request_id, pending);
|
|
5098
|
+
updatePendingUI();
|
|
5099
|
+
}
|
|
5100
|
+
|
|
5101
|
+
function removePendingRequest(id) {
|
|
5102
|
+
pendingRequests.delete(id);
|
|
5103
|
+
updatePendingUI();
|
|
5104
|
+
}
|
|
5105
|
+
|
|
5106
|
+
function updatePendingUI() {
|
|
5107
|
+
const count = pendingRequests.size;
|
|
5108
|
+
const badge = document.getElementById('pendingBadge');
|
|
5109
|
+
|
|
5110
|
+
if (count > 0) {
|
|
5111
|
+
badge.classList.remove('hidden');
|
|
5112
|
+
badge.textContent = count;
|
|
5113
|
+
document.getElementById('pendingOverlay').classList.add('active');
|
|
5114
|
+
} else {
|
|
5115
|
+
badge.classList.add('hidden');
|
|
5116
|
+
document.getElementById('pendingOverlay').classList.remove('active');
|
|
5117
|
+
}
|
|
5118
|
+
|
|
5119
|
+
renderPendingList();
|
|
5120
|
+
}
|
|
5121
|
+
|
|
5122
|
+
function renderPendingList() {
|
|
5123
|
+
const list = document.getElementById('pendingList');
|
|
5124
|
+
list.innerHTML = '';
|
|
5125
|
+
|
|
5126
|
+
for (const [id, req] of pendingRequests) {
|
|
5127
|
+
const item = document.createElement('div');
|
|
5128
|
+
item.className = 'pending-item';
|
|
5129
|
+
|
|
5130
|
+
const tier = req.tier || 1;
|
|
5131
|
+
const tierClass = 'tier' + tier;
|
|
5132
|
+
const pct = Math.max(0, Math.min(100, (req.remaining / TIMEOUT_SECONDS) * 100));
|
|
5133
|
+
const isUrgent = req.remaining <= 30;
|
|
5134
|
+
|
|
5135
|
+
item.innerHTML =
|
|
5136
|
+
'<div class="pending-item-header">' +
|
|
5137
|
+
'<div class="pending-item-op">' + esc(req.operation) + '</div>' +
|
|
5138
|
+
'<div class="pending-item-tier ' + tierClass + '">T' + tier + '</div>' +
|
|
5139
|
+
'</div>' +
|
|
5140
|
+
'<div class="pending-item-reason">' + esc(req.reason) + '</div>' +
|
|
5141
|
+
'<div class="pending-item-timer ' + (isUrgent ? 'urgent' : '') + '">' +
|
|
5142
|
+
'<div class="pending-item-timer-bar">' +
|
|
5143
|
+
'<div class="pending-item-timer-fill" style="width: ' + pct + '%"></div>' +
|
|
5144
|
+
'</div>' +
|
|
5145
|
+
'<span id="timer-' + id + '">' + req.remaining + 's</span>' +
|
|
5146
|
+
'</div>' +
|
|
5147
|
+
'<div class="pending-item-actions">' +
|
|
5148
|
+
'<button class="btn btn-approve" onclick="handleApprove('' + id + '')">Approve</button>' +
|
|
5149
|
+
'<button class="btn btn-deny" onclick="handleDeny('' + id + '')">Deny</button>' +
|
|
5150
|
+
'</div>' +
|
|
5151
|
+
'';
|
|
5152
|
+
|
|
5153
|
+
list.appendChild(item);
|
|
5154
|
+
}
|
|
5155
|
+
}
|
|
4263
5156
|
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
<p style="font-size:12px; margin-top:4px;">Requests will appear here in real time.</p>
|
|
4270
|
-
</div>
|
|
4271
|
-
<div id="pendingList"></div>
|
|
4272
|
-
</div>
|
|
5157
|
+
window.handleApprove = function(id) {
|
|
5158
|
+
fetch('/api/approve/' + id, { method: 'POST', headers: authHeaders() }).then(() => {
|
|
5159
|
+
removePendingRequest(id);
|
|
5160
|
+
}).catch(() => {});
|
|
5161
|
+
};
|
|
4273
5162
|
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
</thead>
|
|
4280
|
-
<tbody id="auditBody"></tbody>
|
|
4281
|
-
</table>
|
|
4282
|
-
</div>
|
|
5163
|
+
window.handleDeny = function(id) {
|
|
5164
|
+
fetch('/api/deny/' + id, { method: 'POST', headers: authHeaders() }).then(() => {
|
|
5165
|
+
removePendingRequest(id);
|
|
5166
|
+
}).catch(() => {});
|
|
5167
|
+
};
|
|
4283
5168
|
|
|
4284
|
-
|
|
4285
|
-
<div class="tab-content" id="tab-baseline">
|
|
4286
|
-
<div class="info-section">
|
|
4287
|
-
<h3>Session Info</h3>
|
|
4288
|
-
<div class="info-row"><span class="info-label">First session</span><span class="info-value" id="bFirstSession">\u2014</span></div>
|
|
4289
|
-
<div class="info-row"><span class="info-label">Started</span><span class="info-value" id="bStarted">\u2014</span></div>
|
|
4290
|
-
</div>
|
|
4291
|
-
<div class="info-section">
|
|
4292
|
-
<h3>Known Namespaces</h3>
|
|
4293
|
-
<div class="tag-list" id="bNamespaces"><span class="tag">\u2014</span></div>
|
|
4294
|
-
</div>
|
|
4295
|
-
<div class="info-section">
|
|
4296
|
-
<h3>Known Counterparties</h3>
|
|
4297
|
-
<div class="tag-list" id="bCounterparties"><span class="tag">\u2014</span></div>
|
|
4298
|
-
</div>
|
|
4299
|
-
<div class="info-section">
|
|
4300
|
-
<h3>Tool Call Counts</h3>
|
|
4301
|
-
<div id="bToolCalls"><span class="info-value">\u2014</span></div>
|
|
4302
|
-
</div>
|
|
4303
|
-
</div>
|
|
5169
|
+
// \u2500\u2500 Threats \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4304
5170
|
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
<h3>Tier 2 \u2014 Anomaly Detection</h3>
|
|
4313
|
-
<div id="pTier2"></div>
|
|
4314
|
-
</div>
|
|
4315
|
-
<div class="info-section">
|
|
4316
|
-
<h3>Tier 3 \u2014 Always Allowed</h3>
|
|
4317
|
-
<div class="info-row">
|
|
4318
|
-
<span class="info-label">Operations</span>
|
|
4319
|
-
<span class="info-value" id="pTier3Count">\u2014</span>
|
|
4320
|
-
</div>
|
|
4321
|
-
</div>
|
|
4322
|
-
<div class="info-section">
|
|
4323
|
-
<h3>Approval Channel</h3>
|
|
4324
|
-
<div id="pChannel"></div>
|
|
4325
|
-
</div>
|
|
4326
|
-
</div>
|
|
5171
|
+
function addThreat(data) {
|
|
5172
|
+
const {
|
|
5173
|
+
timestamp,
|
|
5174
|
+
severity,
|
|
5175
|
+
type,
|
|
5176
|
+
details
|
|
5177
|
+
} = data;
|
|
4327
5178
|
|
|
4328
|
-
|
|
4329
|
-
|
|
5179
|
+
const threat = {
|
|
5180
|
+
id: 'threat-' + threatCount++,
|
|
5181
|
+
timestamp: timestamp || new Date().toISOString(),
|
|
5182
|
+
severity: severity || 'medium',
|
|
5183
|
+
type: type || 'unknown',
|
|
5184
|
+
details: details || ''
|
|
5185
|
+
};
|
|
4330
5186
|
|
|
4331
|
-
|
|
4332
|
-
(
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
// The token is provided by the server at generation time (embedded for initial auth).
|
|
4336
|
-
const AUTH_TOKEN = ${options.authToken ? JSON.stringify(options.authToken) : "null"};
|
|
4337
|
-
let SESSION_ID = null; // Short-lived session for SSE and URL-based requests
|
|
4338
|
-
const pending = new Map();
|
|
4339
|
-
let auditCount = 0;
|
|
5187
|
+
threatItems.unshift(threat);
|
|
5188
|
+
if (threatItems.length > MAX_THREAT_ITEMS) {
|
|
5189
|
+
threatItems.pop();
|
|
5190
|
+
}
|
|
4340
5191
|
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
}
|
|
4347
|
-
function sessionQuery(url) {
|
|
4348
|
-
if (!SESSION_ID) return url;
|
|
4349
|
-
const sep = url.includes('?') ? '&' : '?';
|
|
4350
|
-
return url + sep + 'session=' + SESSION_ID;
|
|
5192
|
+
if (threatCount > 0) {
|
|
5193
|
+
document.getElementById('threatPanel').classList.remove('collapsed');
|
|
5194
|
+
}
|
|
5195
|
+
|
|
5196
|
+
renderThreats();
|
|
4351
5197
|
}
|
|
4352
5198
|
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
5199
|
+
function renderThreats() {
|
|
5200
|
+
const content = document.getElementById('threatContent');
|
|
5201
|
+
const badge = document.getElementById('threatCount');
|
|
5202
|
+
|
|
5203
|
+
if (threatItems.length === 0) {
|
|
5204
|
+
content.innerHTML = '<div class="threat-empty">No threats detected</div>';
|
|
5205
|
+
badge.textContent = '0';
|
|
5206
|
+
return;
|
|
5207
|
+
}
|
|
5208
|
+
|
|
5209
|
+
badge.textContent = threatItems.length;
|
|
5210
|
+
content.innerHTML = '';
|
|
5211
|
+
|
|
5212
|
+
for (const threat of threatItems) {
|
|
5213
|
+
const div = document.createElement('div');
|
|
5214
|
+
div.className = 'threat-item';
|
|
5215
|
+
const time = new Date(threat.timestamp).toLocaleTimeString();
|
|
5216
|
+
div.innerHTML =
|
|
5217
|
+
'<div style="margin-bottom: 3px;">' +
|
|
5218
|
+
'<span class="threat-item-type">' + esc(threat.type) + '</span>' +
|
|
5219
|
+
'<span style="font-size: 10px; color: var(--text-secondary); margin-left: 6px;">' + esc(time) + '</span>' +
|
|
5220
|
+
'</div>' +
|
|
5221
|
+
'<div>' + esc(threat.details) + '</div>' +
|
|
5222
|
+
'';
|
|
5223
|
+
content.appendChild(div);
|
|
5224
|
+
}
|
|
4366
5225
|
}
|
|
4367
5226
|
|
|
4368
|
-
//
|
|
4369
|
-
document.querySelectorAll('.tab').forEach(tab => {
|
|
4370
|
-
tab.addEventListener('click', () => {
|
|
4371
|
-
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
|
4372
|
-
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
|
4373
|
-
tab.classList.add('active');
|
|
4374
|
-
document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
|
|
4375
|
-
});
|
|
4376
|
-
});
|
|
5227
|
+
// \u2500\u2500 SSE Connection \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4377
5228
|
|
|
4378
|
-
// SSE Connection \u2014 SEC-012: uses short-lived session token in URL, not auth token
|
|
4379
|
-
let evtSource;
|
|
4380
5229
|
function reconnectSSE() {
|
|
4381
|
-
if (evtSource)
|
|
5230
|
+
if (evtSource) evtSource.close();
|
|
4382
5231
|
connect();
|
|
4383
5232
|
}
|
|
5233
|
+
|
|
4384
5234
|
function connect() {
|
|
4385
5235
|
evtSource = new EventSource(sessionQuery('/events'));
|
|
5236
|
+
|
|
4386
5237
|
evtSource.onopen = () => {
|
|
4387
5238
|
document.getElementById('statusDot').classList.remove('disconnected');
|
|
4388
|
-
document.getElementById('statusText').textContent = 'Connected';
|
|
4389
5239
|
};
|
|
5240
|
+
|
|
4390
5241
|
evtSource.onerror = () => {
|
|
4391
5242
|
document.getElementById('statusDot').classList.add('disconnected');
|
|
4392
|
-
document.getElementById('statusText').textContent = 'Reconnecting...';
|
|
4393
5243
|
};
|
|
5244
|
+
|
|
5245
|
+
evtSource.addEventListener('init', (e) => {
|
|
5246
|
+
const data = JSON.parse(e.data);
|
|
5247
|
+
if (data.baseline) {
|
|
5248
|
+
updateBaseline(data.baseline);
|
|
5249
|
+
}
|
|
5250
|
+
if (data.policy) {
|
|
5251
|
+
updatePolicy(data.policy);
|
|
5252
|
+
}
|
|
5253
|
+
if (data.pending) {
|
|
5254
|
+
data.pending.forEach(addPendingRequest);
|
|
5255
|
+
}
|
|
5256
|
+
});
|
|
5257
|
+
|
|
4394
5258
|
evtSource.addEventListener('pending-request', (e) => {
|
|
4395
5259
|
const data = JSON.parse(e.data);
|
|
4396
5260
|
addPendingRequest(data);
|
|
4397
5261
|
});
|
|
5262
|
+
|
|
4398
5263
|
evtSource.addEventListener('request-resolved', (e) => {
|
|
4399
5264
|
const data = JSON.parse(e.data);
|
|
4400
5265
|
removePendingRequest(data.request_id);
|
|
4401
5266
|
});
|
|
4402
|
-
|
|
5267
|
+
|
|
5268
|
+
evtSource.addEventListener('tool-call', (e) => {
|
|
4403
5269
|
const data = JSON.parse(e.data);
|
|
4404
|
-
|
|
5270
|
+
addActivityItem({
|
|
5271
|
+
timestamp: data.timestamp,
|
|
5272
|
+
tier: data.tier || 1,
|
|
5273
|
+
tool: data.tool || 'unknown',
|
|
5274
|
+
outcome: data.outcome || 'executed',
|
|
5275
|
+
detail: data.detail || ''
|
|
5276
|
+
});
|
|
4405
5277
|
});
|
|
4406
|
-
|
|
5278
|
+
|
|
5279
|
+
evtSource.addEventListener('context-gate-decision', (e) => {
|
|
4407
5280
|
const data = JSON.parse(e.data);
|
|
4408
|
-
|
|
5281
|
+
addActivityItem({
|
|
5282
|
+
timestamp: data.timestamp,
|
|
5283
|
+
tier: data.tier || 1,
|
|
5284
|
+
tool: data.tool || 'unknown',
|
|
5285
|
+
outcome: data.outcome || 'gated',
|
|
5286
|
+
detail: data.fields_filtered ? 'Filtered ' + data.fields_filtered + ' fields' : data.reason || '',
|
|
5287
|
+
isContextGated: true
|
|
5288
|
+
});
|
|
4409
5289
|
});
|
|
4410
|
-
|
|
5290
|
+
|
|
5291
|
+
evtSource.addEventListener('injection-alert', (e) => {
|
|
4411
5292
|
const data = JSON.parse(e.data);
|
|
4412
|
-
|
|
5293
|
+
addActivityItem({
|
|
5294
|
+
timestamp: data.timestamp,
|
|
5295
|
+
tier: data.tier || 2,
|
|
5296
|
+
tool: data.tool || 'unknown',
|
|
5297
|
+
outcome: data.allowed ? 'allowed' : 'denied',
|
|
5298
|
+
detail: data.signal || 'Injection detected',
|
|
5299
|
+
hasInjection: true
|
|
5300
|
+
});
|
|
5301
|
+
addThreat({
|
|
5302
|
+
timestamp: data.timestamp,
|
|
5303
|
+
severity: data.severity || 'medium',
|
|
5304
|
+
type: 'Injection Alert',
|
|
5305
|
+
details: data.signal || 'Suspicious pattern detected'
|
|
5306
|
+
});
|
|
4413
5307
|
});
|
|
4414
|
-
|
|
5308
|
+
|
|
5309
|
+
evtSource.addEventListener('protection-status', (e) => {
|
|
4415
5310
|
const data = JSON.parse(e.data);
|
|
4416
|
-
|
|
4417
|
-
if (data.policy) updatePolicy(data.policy);
|
|
4418
|
-
if (data.pending) data.pending.forEach(addPendingRequest);
|
|
4419
|
-
if (data.audit) data.audit.forEach(addAuditEntry);
|
|
5311
|
+
updateProtectionStatus(data);
|
|
4420
5312
|
});
|
|
4421
|
-
}
|
|
4422
|
-
|
|
4423
|
-
// Pending requests
|
|
4424
|
-
function addPendingRequest(req) {
|
|
4425
|
-
pending.set(req.request_id, { ...req, remaining: TIMEOUT });
|
|
4426
|
-
renderPending();
|
|
4427
|
-
updatePendingCount();
|
|
4428
|
-
flashTab('pending');
|
|
4429
|
-
}
|
|
4430
5313
|
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
}
|
|
5314
|
+
evtSource.addEventListener('audit-entry', (e) => {
|
|
5315
|
+
const data = JSON.parse(e.data);
|
|
5316
|
+
// Audit entries don't show in activity by default, but we could add them
|
|
5317
|
+
});
|
|
4436
5318
|
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
list.innerHTML = '';
|
|
4442
|
-
empty.style.display = 'block';
|
|
4443
|
-
return;
|
|
4444
|
-
}
|
|
4445
|
-
empty.style.display = 'none';
|
|
4446
|
-
list.innerHTML = '';
|
|
4447
|
-
for (const [id, req] of pending) {
|
|
4448
|
-
const card = document.createElement('div');
|
|
4449
|
-
card.className = 'request-card tier' + req.tier;
|
|
4450
|
-
card.id = 'req-' + id;
|
|
4451
|
-
const ctx = typeof req.context === 'string' ? req.context : JSON.stringify(req.context, null, 2);
|
|
4452
|
-
card.innerHTML =
|
|
4453
|
-
'<div class="request-header">' +
|
|
4454
|
-
'<span class="request-op">' + esc(req.operation) + '</span>' +
|
|
4455
|
-
'<span class="tier-badge tier' + req.tier + '">Tier ' + req.tier + '</span>' +
|
|
4456
|
-
'</div>' +
|
|
4457
|
-
'<div class="request-reason">' + esc(req.reason) + '</div>' +
|
|
4458
|
-
'<div class="request-context">' + esc(ctx) + '</div>' +
|
|
4459
|
-
'<div class="request-actions">' +
|
|
4460
|
-
'<button class="btn btn-approve" onclick="handleApprove(\\'' + id + '\\')">Approve</button>' +
|
|
4461
|
-
'<button class="btn btn-deny" onclick="handleDeny(\\'' + id + '\\')">Deny</button>' +
|
|
4462
|
-
'<span class="countdown" id="cd-' + id + '">' + req.remaining + 's</span>' +
|
|
4463
|
-
'</div>';
|
|
4464
|
-
list.appendChild(card);
|
|
4465
|
-
}
|
|
5319
|
+
evtSource.addEventListener('baseline-update', (e) => {
|
|
5320
|
+
const data = JSON.parse(e.data);
|
|
5321
|
+
updateBaseline(data);
|
|
5322
|
+
});
|
|
4466
5323
|
}
|
|
4467
5324
|
|
|
4468
|
-
function
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
el.className = pending.size > 0 ? 'count alert' : 'count muted';
|
|
5325
|
+
function updateBaseline(baseline) {
|
|
5326
|
+
if (!baseline) return;
|
|
5327
|
+
// Update baseline-derived stats if needed
|
|
4472
5328
|
}
|
|
4473
5329
|
|
|
4474
|
-
function
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
5330
|
+
function updatePolicy(policy) {
|
|
5331
|
+
if (!policy) return;
|
|
5332
|
+
// Update policy-derived stats
|
|
5333
|
+
if (policy.approval_channel) {
|
|
5334
|
+
// Policy info updated
|
|
4479
5335
|
}
|
|
4480
5336
|
}
|
|
4481
5337
|
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
5338
|
+
function updateProtectionStatus(status) {
|
|
5339
|
+
if (status.sovereignty_score !== undefined) {
|
|
5340
|
+
updateSovereigntyScore(status.sovereignty_score);
|
|
5341
|
+
}
|
|
5342
|
+
if (status.active_protections !== undefined) {
|
|
5343
|
+
document.getElementById('activeProtections').textContent = status.active_protections;
|
|
5344
|
+
}
|
|
5345
|
+
// Update individual protection cards
|
|
5346
|
+
if (status.encryption !== undefined) {
|
|
5347
|
+
const el = document.getElementById('encryptionStatus');
|
|
5348
|
+
el.className = 'protection-card-status ' + (status.encryption ? 'active' : 'inactive');
|
|
5349
|
+
el.textContent = status.encryption ? '\u2713 Active' : '\u2717 Inactive';
|
|
5350
|
+
}
|
|
5351
|
+
if (status.approval_gate !== undefined) {
|
|
5352
|
+
const el = document.getElementById('approvalStatus');
|
|
5353
|
+
el.className = 'protection-card-status ' + (status.approval_gate ? 'active' : 'inactive');
|
|
5354
|
+
el.textContent = status.approval_gate ? '\u2713 Active' : '\u2717 Inactive';
|
|
5355
|
+
}
|
|
5356
|
+
if (status.context_gating !== undefined) {
|
|
5357
|
+
const el = document.getElementById('contextStatus');
|
|
5358
|
+
el.className = 'protection-card-status ' + (status.context_gating ? 'active' : 'inactive');
|
|
5359
|
+
el.textContent = status.context_gating ? '\u2713 Active' : '\u2717 Inactive';
|
|
5360
|
+
}
|
|
5361
|
+
if (status.injection_detection !== undefined) {
|
|
5362
|
+
const el = document.getElementById('injectionStatus');
|
|
5363
|
+
el.className = 'protection-card-status ' + (status.injection_detection ? 'active' : 'inactive');
|
|
5364
|
+
el.textContent = status.injection_detection ? '\u2713 Active' : '\u2717 Inactive';
|
|
5365
|
+
}
|
|
5366
|
+
if (status.baseline !== undefined) {
|
|
5367
|
+
const el = document.getElementById('baselineStatus');
|
|
5368
|
+
el.className = 'protection-card-status ' + (status.baseline ? 'active' : 'inactive');
|
|
5369
|
+
el.textContent = status.baseline ? '\u2713 Active' : '\u2717 Inactive';
|
|
5370
|
+
}
|
|
5371
|
+
if (status.audit_trail !== undefined) {
|
|
5372
|
+
const el = document.getElementById('auditStatus');
|
|
5373
|
+
el.className = 'protection-card-status ' + (status.audit_trail ? 'active' : 'inactive');
|
|
5374
|
+
el.textContent = status.audit_trail ? '\u2713 Active' : '\u2717 Inactive';
|
|
4491
5375
|
}
|
|
4492
|
-
}, 1000);
|
|
4493
|
-
|
|
4494
|
-
// Approve / Deny handlers (global scope)
|
|
4495
|
-
window.handleApprove = function(id) {
|
|
4496
|
-
fetch('/api/approve/' + id, { method: 'POST', headers: authHeaders() }).then(() => {
|
|
4497
|
-
removePendingRequest(id);
|
|
4498
|
-
});
|
|
4499
|
-
};
|
|
4500
|
-
window.handleDeny = function(id) {
|
|
4501
|
-
fetch('/api/deny/' + id, { method: 'POST', headers: authHeaders() }).then(() => {
|
|
4502
|
-
removePendingRequest(id);
|
|
4503
|
-
});
|
|
4504
|
-
};
|
|
4505
|
-
|
|
4506
|
-
// Audit log
|
|
4507
|
-
function addAuditEntry(entry) {
|
|
4508
|
-
auditCount++;
|
|
4509
|
-
document.getElementById('auditCount').textContent = auditCount;
|
|
4510
|
-
const tbody = document.getElementById('auditBody');
|
|
4511
|
-
const tr = document.createElement('tr');
|
|
4512
|
-
tr.className = 'new';
|
|
4513
|
-
const time = entry.timestamp ? new Date(entry.timestamp).toLocaleTimeString() : '\u2014';
|
|
4514
|
-
const layer = entry.layer || '\u2014';
|
|
4515
|
-
tr.innerHTML =
|
|
4516
|
-
'<td class="audit-time">' + esc(time) + '</td>' +
|
|
4517
|
-
'<td><span class="audit-layer ' + layer + '">' + esc(layer) + '</span></td>' +
|
|
4518
|
-
'<td class="audit-op">' + esc(entry.operation || '\u2014') + '</td>' +
|
|
4519
|
-
'<td style="font-size:12px;color:var(--text-muted)">' + esc(entry.identity_id || '\u2014') + '</td>';
|
|
4520
|
-
tbody.insertBefore(tr, tbody.firstChild);
|
|
4521
|
-
// Keep last 100 entries
|
|
4522
|
-
while (tbody.children.length > 100) tbody.removeChild(tbody.lastChild);
|
|
4523
|
-
}
|
|
4524
|
-
|
|
4525
|
-
// Baseline
|
|
4526
|
-
function updateBaseline(b) {
|
|
4527
|
-
if (!b) return;
|
|
4528
|
-
document.getElementById('bFirstSession').textContent = b.is_first_session ? 'Yes' : 'No';
|
|
4529
|
-
document.getElementById('bStarted').textContent = b.started_at ? new Date(b.started_at).toLocaleString() : '\u2014';
|
|
4530
|
-
const ns = document.getElementById('bNamespaces');
|
|
4531
|
-
ns.innerHTML = (b.known_namespaces || []).length > 0
|
|
4532
|
-
? (b.known_namespaces || []).map(n => '<span class="tag">' + esc(n) + '</span>').join('')
|
|
4533
|
-
: '<span class="tag">none</span>';
|
|
4534
|
-
const cp = document.getElementById('bCounterparties');
|
|
4535
|
-
cp.innerHTML = (b.known_counterparties || []).length > 0
|
|
4536
|
-
? (b.known_counterparties || []).map(c => '<span class="tag">' + esc(c.slice(0,16)) + '...</span>').join('')
|
|
4537
|
-
: '<span class="tag">none</span>';
|
|
4538
|
-
const tc = document.getElementById('bToolCalls');
|
|
4539
|
-
const counts = b.tool_call_counts || {};
|
|
4540
|
-
const entries = Object.entries(counts).sort((a,b) => b[1] - a[1]);
|
|
4541
|
-
tc.innerHTML = entries.length > 0
|
|
4542
|
-
? entries.map(([k,v]) => '<div class="info-row"><span class="info-label">' + esc(k) + '</span><span class="info-value">' + v + '</span></div>').join('')
|
|
4543
|
-
: '<span class="info-value">no calls yet</span>';
|
|
4544
|
-
}
|
|
4545
|
-
|
|
4546
|
-
// Policy
|
|
4547
|
-
function updatePolicy(p) {
|
|
4548
|
-
if (!p) return;
|
|
4549
|
-
const t1 = document.getElementById('pTier1');
|
|
4550
|
-
t1.innerHTML = (p.tier1_always_approve || []).map(op =>
|
|
4551
|
-
'<div class="policy-op">' + esc(op) + '</div>'
|
|
4552
|
-
).join('');
|
|
4553
|
-
const t2 = document.getElementById('pTier2');
|
|
4554
|
-
const cfg = p.tier2_anomaly || {};
|
|
4555
|
-
t2.innerHTML = Object.entries(cfg).map(([k,v]) =>
|
|
4556
|
-
'<div class="info-row"><span class="info-label">' + esc(k) + '</span><span class="info-value">' + esc(String(v)) + '</span></div>'
|
|
4557
|
-
).join('');
|
|
4558
|
-
document.getElementById('pTier3Count').textContent = (p.tier3_always_allow || []).length + ' operations';
|
|
4559
|
-
const ch = document.getElementById('pChannel');
|
|
4560
|
-
const chan = p.approval_channel || {};
|
|
4561
|
-
ch.innerHTML = Object.entries(chan).filter(([k]) => k !== 'webhook_secret').map(([k,v]) =>
|
|
4562
|
-
'<div class="info-row"><span class="info-label">' + esc(k) + '</span><span class="info-value">' + esc(String(v)) + '</span></div>'
|
|
4563
|
-
).join('');
|
|
4564
5376
|
}
|
|
4565
5377
|
|
|
4566
|
-
|
|
4567
|
-
if (!s) return '';
|
|
4568
|
-
const d = document.createElement('div');
|
|
4569
|
-
d.textContent = String(s);
|
|
4570
|
-
return d.innerHTML;
|
|
4571
|
-
}
|
|
5378
|
+
// \u2500\u2500 Initialization \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
4572
5379
|
|
|
4573
|
-
// Init \u2014 SEC-012: exchange token for session before connecting SSE
|
|
4574
5380
|
(async function init() {
|
|
4575
5381
|
await exchangeSession();
|
|
4576
|
-
// Clean token from URL
|
|
5382
|
+
// Clean legacy ?token= from URL
|
|
4577
5383
|
if (window.location.search.includes('token=')) {
|
|
4578
|
-
|
|
4579
|
-
window.history.replaceState({}, '', clean);
|
|
5384
|
+
window.history.replaceState({}, '', window.location.pathname);
|
|
4580
5385
|
}
|
|
4581
5386
|
connect();
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
5387
|
+
|
|
5388
|
+
// Start uptime ticker
|
|
5389
|
+
setInterval(updateUptime, 1000);
|
|
5390
|
+
updateUptime();
|
|
5391
|
+
|
|
5392
|
+
// Pending request countdown timer
|
|
5393
|
+
setInterval(() => {
|
|
5394
|
+
for (const [id, req] of pendingRequests) {
|
|
5395
|
+
req.remaining = Math.max(0, req.remaining - 1);
|
|
5396
|
+
const el = document.getElementById('timer-' + id);
|
|
5397
|
+
if (el) {
|
|
5398
|
+
el.textContent = req.remaining + 's';
|
|
5399
|
+
}
|
|
5400
|
+
}
|
|
5401
|
+
}, 1000);
|
|
5402
|
+
|
|
5403
|
+
// Load initial status
|
|
5404
|
+
try {
|
|
5405
|
+
const resp = await fetch('/api/status', { headers: authHeaders() });
|
|
5406
|
+
if (resp.ok) {
|
|
5407
|
+
const status = await resp.json();
|
|
5408
|
+
if (status.baseline) updateBaseline(status.baseline);
|
|
5409
|
+
if (status.policy) updatePolicy(status.policy);
|
|
5410
|
+
}
|
|
5411
|
+
} catch (e) {
|
|
5412
|
+
// Ignore
|
|
5413
|
+
}
|
|
4586
5414
|
})();
|
|
5415
|
+
|
|
4587
5416
|
})();
|
|
4588
5417
|
</script>
|
|
5418
|
+
|
|
4589
5419
|
</body>
|
|
4590
5420
|
</html>`;
|
|
4591
5421
|
}
|
|
@@ -5121,6 +5951,25 @@ data: ${JSON.stringify(data)}
|
|
|
5121
5951
|
this.broadcastSSE("baseline-update", this.baseline.getProfile());
|
|
5122
5952
|
}
|
|
5123
5953
|
}
|
|
5954
|
+
/**
|
|
5955
|
+
* Broadcast a tool call event to connected dashboards.
|
|
5956
|
+
* Called from the gate or router when a tool is invoked.
|
|
5957
|
+
*/
|
|
5958
|
+
broadcastToolCall(data) {
|
|
5959
|
+
this.broadcastSSE("tool-call", data);
|
|
5960
|
+
}
|
|
5961
|
+
/**
|
|
5962
|
+
* Broadcast a context gate decision to connected dashboards.
|
|
5963
|
+
*/
|
|
5964
|
+
broadcastContextGateDecision(data) {
|
|
5965
|
+
this.broadcastSSE("context-gate-decision", data);
|
|
5966
|
+
}
|
|
5967
|
+
/**
|
|
5968
|
+
* Broadcast current protection status to connected dashboards.
|
|
5969
|
+
*/
|
|
5970
|
+
broadcastProtectionStatus(data) {
|
|
5971
|
+
this.broadcastSSE("protection-status", data);
|
|
5972
|
+
}
|
|
5124
5973
|
/** Get the number of pending requests */
|
|
5125
5974
|
get pendingCount() {
|
|
5126
5975
|
return this.pending.size;
|
|
@@ -5330,36 +6179,554 @@ var WebhookApprovalChannel = class {
|
|
|
5330
6179
|
);
|
|
5331
6180
|
return;
|
|
5332
6181
|
}
|
|
5333
|
-
const pending = this.pending.get(requestId);
|
|
5334
|
-
if (!pending) {
|
|
5335
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
5336
|
-
res.end(
|
|
5337
|
-
JSON.stringify({
|
|
5338
|
-
error: "Request not found or already resolved"
|
|
5339
|
-
})
|
|
5340
|
-
);
|
|
5341
|
-
return;
|
|
6182
|
+
const pending = this.pending.get(requestId);
|
|
6183
|
+
if (!pending) {
|
|
6184
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
6185
|
+
res.end(
|
|
6186
|
+
JSON.stringify({
|
|
6187
|
+
error: "Request not found or already resolved"
|
|
6188
|
+
})
|
|
6189
|
+
);
|
|
6190
|
+
return;
|
|
6191
|
+
}
|
|
6192
|
+
clearTimeout(pending.timer);
|
|
6193
|
+
this.pending.delete(requestId);
|
|
6194
|
+
const response = {
|
|
6195
|
+
decision: callbackPayload.decision,
|
|
6196
|
+
decided_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6197
|
+
decided_by: "human"
|
|
6198
|
+
};
|
|
6199
|
+
pending.resolve(response);
|
|
6200
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
6201
|
+
res.end(
|
|
6202
|
+
JSON.stringify({
|
|
6203
|
+
success: true,
|
|
6204
|
+
decision: callbackPayload.decision
|
|
6205
|
+
})
|
|
6206
|
+
);
|
|
6207
|
+
});
|
|
6208
|
+
}
|
|
6209
|
+
/** Get the number of pending requests */
|
|
6210
|
+
get pendingCount() {
|
|
6211
|
+
return this.pending.size;
|
|
6212
|
+
}
|
|
6213
|
+
};
|
|
6214
|
+
|
|
6215
|
+
// src/security/injection-detector.ts
|
|
6216
|
+
var ROLE_OVERRIDE_PATTERNS = [
|
|
6217
|
+
/ignore\s+(?:(?:previous|prior|all)\s+)?instructions/i,
|
|
6218
|
+
/you\s+are\s+now/i,
|
|
6219
|
+
/\bsystem\s*:\s+(?!working|process|design|architecture)/i,
|
|
6220
|
+
/forget\s+(?:everything|all|prior)/i,
|
|
6221
|
+
/disregard\s+(?:the\s+)?(?:previous\s+)?instructions/i,
|
|
6222
|
+
/new\s+instructions\s*:/i,
|
|
6223
|
+
/updated?\s+instructions\s*:/i
|
|
6224
|
+
];
|
|
6225
|
+
var SECURITY_BYPASS_PATTERNS = [
|
|
6226
|
+
/skip\s+(?:the\s+)?(?:filter|gate|check|verify|approve)/i,
|
|
6227
|
+
/bypass\s+(?:the\s+)?(?:filter|gate|security|check)/i,
|
|
6228
|
+
/disable\s+(?:the\s+)?(?:filter|gate|approval|security|audit|log|encrypt|verify)/i,
|
|
6229
|
+
/do\s+not\s+(?:audit|log|encrypt|verify|approve|check|sign)/i
|
|
6230
|
+
];
|
|
6231
|
+
var TOOL_INVOCATION_PATTERNS = [
|
|
6232
|
+
/sanctuary\//i,
|
|
6233
|
+
/concordia\//i,
|
|
6234
|
+
/bridge_/i,
|
|
6235
|
+
/handshake_/i
|
|
6236
|
+
];
|
|
6237
|
+
var URL_PATTERN = /https?:\/\/[^\s"'<>]+/i;
|
|
6238
|
+
var EMAIL_PATTERN = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
|
|
6239
|
+
var ZERO_WIDTH_CHARS = [
|
|
6240
|
+
"\u200B",
|
|
6241
|
+
// Zero-width space
|
|
6242
|
+
"\u200C",
|
|
6243
|
+
// Zero-width non-joiner
|
|
6244
|
+
"\u200D",
|
|
6245
|
+
// Zero-width joiner
|
|
6246
|
+
"\uFEFF"
|
|
6247
|
+
// Zero-width no-break space
|
|
6248
|
+
];
|
|
6249
|
+
var InjectionDetector = class {
|
|
6250
|
+
config;
|
|
6251
|
+
stats = {
|
|
6252
|
+
total_scans: 0,
|
|
6253
|
+
total_flags: 0,
|
|
6254
|
+
total_blocks: 0,
|
|
6255
|
+
signals_by_type: {}
|
|
6256
|
+
};
|
|
6257
|
+
constructor(config = {}) {
|
|
6258
|
+
this.config = {
|
|
6259
|
+
enabled: config.enabled ?? true,
|
|
6260
|
+
sensitivity: config.sensitivity ?? "medium",
|
|
6261
|
+
on_detection: config.on_detection ?? "escalate",
|
|
6262
|
+
custom_patterns: config.custom_patterns ?? []
|
|
6263
|
+
};
|
|
6264
|
+
}
|
|
6265
|
+
/**
|
|
6266
|
+
* Scan tool arguments for injection signals.
|
|
6267
|
+
* @param toolName Full tool name (e.g., "sanctuary/state_read")
|
|
6268
|
+
* @param args Tool arguments
|
|
6269
|
+
* @returns DetectionResult with all detected signals
|
|
6270
|
+
*/
|
|
6271
|
+
scan(toolName, args) {
|
|
6272
|
+
this.stats.total_scans++;
|
|
6273
|
+
if (!this.config.enabled) {
|
|
6274
|
+
return {
|
|
6275
|
+
flagged: false,
|
|
6276
|
+
confidence: 0,
|
|
6277
|
+
signals: [],
|
|
6278
|
+
recommendation: "allow"
|
|
6279
|
+
};
|
|
6280
|
+
}
|
|
6281
|
+
const signals = [];
|
|
6282
|
+
const visited = /* @__PURE__ */ new Set();
|
|
6283
|
+
this.scanValue(args, "", toolName, signals, visited);
|
|
6284
|
+
const flagged = signals.length > 0;
|
|
6285
|
+
if (flagged) {
|
|
6286
|
+
this.stats.total_flags++;
|
|
6287
|
+
}
|
|
6288
|
+
for (const sig of signals) {
|
|
6289
|
+
this.stats.signals_by_type[sig.type] = (this.stats.signals_by_type[sig.type] ?? 0) + 1;
|
|
6290
|
+
}
|
|
6291
|
+
const recommendation = this.computeRecommendation(
|
|
6292
|
+
signals,
|
|
6293
|
+
this.config.sensitivity
|
|
6294
|
+
);
|
|
6295
|
+
if (recommendation === "block") {
|
|
6296
|
+
this.stats.total_blocks++;
|
|
6297
|
+
}
|
|
6298
|
+
return {
|
|
6299
|
+
flagged,
|
|
6300
|
+
confidence: this.computeConfidence(signals),
|
|
6301
|
+
signals,
|
|
6302
|
+
recommendation
|
|
6303
|
+
};
|
|
6304
|
+
}
|
|
6305
|
+
/**
|
|
6306
|
+
* Recursively scan a value and all nested values.
|
|
6307
|
+
*/
|
|
6308
|
+
scanValue(value, path, toolName, signals, visited) {
|
|
6309
|
+
if (typeof value === "object" && value !== null) {
|
|
6310
|
+
if (visited.has(value)) return;
|
|
6311
|
+
visited.add(value);
|
|
6312
|
+
}
|
|
6313
|
+
if (typeof value === "string") {
|
|
6314
|
+
this.scanString(value, path, toolName, signals);
|
|
6315
|
+
} else if (Array.isArray(value)) {
|
|
6316
|
+
for (let i = 0; i < value.length; i++) {
|
|
6317
|
+
this.scanValue(value[i], `${path}[${i}]`, toolName, signals, visited);
|
|
6318
|
+
}
|
|
6319
|
+
} else if (typeof value === "object" && value !== null) {
|
|
6320
|
+
for (const [key, val] of Object.entries(value)) {
|
|
6321
|
+
this.scanValue(val, path ? `${path}.${key}` : key, toolName, signals, visited);
|
|
6322
|
+
}
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
/**
|
|
6326
|
+
* Scan a single string for injection signals.
|
|
6327
|
+
*/
|
|
6328
|
+
scanString(value, path, _toolName, signals) {
|
|
6329
|
+
if (this.isSafeField(path)) {
|
|
6330
|
+
return;
|
|
6331
|
+
}
|
|
6332
|
+
const location = path || "root";
|
|
6333
|
+
const normalized = this.normalizeConfusables(value.normalize("NFKC"));
|
|
6334
|
+
if (normalized !== value) {
|
|
6335
|
+
signals.push({
|
|
6336
|
+
type: "encoding_evasion",
|
|
6337
|
+
pattern: "unicode_normalization_delta",
|
|
6338
|
+
location,
|
|
6339
|
+
severity: "medium"
|
|
6340
|
+
});
|
|
6341
|
+
}
|
|
6342
|
+
for (const pattern of ROLE_OVERRIDE_PATTERNS) {
|
|
6343
|
+
if (pattern.test(normalized)) {
|
|
6344
|
+
signals.push({
|
|
6345
|
+
type: "role_override",
|
|
6346
|
+
pattern: pattern.source,
|
|
6347
|
+
location,
|
|
6348
|
+
severity: "high"
|
|
6349
|
+
});
|
|
6350
|
+
break;
|
|
6351
|
+
}
|
|
6352
|
+
}
|
|
6353
|
+
for (const pattern of SECURITY_BYPASS_PATTERNS) {
|
|
6354
|
+
if (pattern.test(normalized)) {
|
|
6355
|
+
signals.push({
|
|
6356
|
+
type: "security_bypass",
|
|
6357
|
+
pattern: pattern.source,
|
|
6358
|
+
location,
|
|
6359
|
+
severity: "high"
|
|
6360
|
+
});
|
|
6361
|
+
break;
|
|
6362
|
+
}
|
|
6363
|
+
}
|
|
6364
|
+
if (!this.isToolNameField(path)) {
|
|
6365
|
+
for (const pattern of TOOL_INVOCATION_PATTERNS) {
|
|
6366
|
+
if (pattern.test(normalized)) {
|
|
6367
|
+
signals.push({
|
|
6368
|
+
type: "tool_invocation_in_string",
|
|
6369
|
+
pattern: pattern.source,
|
|
6370
|
+
location,
|
|
6371
|
+
severity: "medium"
|
|
6372
|
+
});
|
|
6373
|
+
break;
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
}
|
|
6377
|
+
this.detectEncodingEvasion(value, location, signals);
|
|
6378
|
+
this.detectDataExfiltration(value, location, signals);
|
|
6379
|
+
this.detectPromptStuffing(value, location, signals);
|
|
6380
|
+
}
|
|
6381
|
+
/**
|
|
6382
|
+
* Detect base64 strings and zero-width character evasion.
|
|
6383
|
+
*/
|
|
6384
|
+
detectEncodingEvasion(value, path, signals) {
|
|
6385
|
+
if (value.length > 50 && /^[A-Za-z0-9+/]+={0,2}$/.test(value.trim())) {
|
|
6386
|
+
signals.push({
|
|
6387
|
+
type: "encoding_evasion",
|
|
6388
|
+
pattern: "base64_string",
|
|
6389
|
+
location: path || "root",
|
|
6390
|
+
severity: "medium"
|
|
6391
|
+
});
|
|
6392
|
+
}
|
|
6393
|
+
let zeroWidthCount = 0;
|
|
6394
|
+
for (const char of ZERO_WIDTH_CHARS) {
|
|
6395
|
+
zeroWidthCount += (value.match(new RegExp(char, "g")) || []).length;
|
|
6396
|
+
}
|
|
6397
|
+
if (zeroWidthCount > 0) {
|
|
6398
|
+
signals.push({
|
|
6399
|
+
type: "encoding_evasion",
|
|
6400
|
+
pattern: "zero_width_characters",
|
|
6401
|
+
location: path || "root",
|
|
6402
|
+
severity: "medium"
|
|
6403
|
+
});
|
|
6404
|
+
}
|
|
6405
|
+
const hasLatin = /[a-zA-Z]/.test(value);
|
|
6406
|
+
const hasCJK = /[\u4E00-\u9FFF\u3040-\u309F\uAC00-\uD7AF]/.test(value);
|
|
6407
|
+
const hasArabic = /[\u0600-\u06FF]/.test(value);
|
|
6408
|
+
const hasCyrillic = /[\u0400-\u04FF]/.test(value);
|
|
6409
|
+
const unicodeCategories = [hasLatin, hasCJK, hasArabic, hasCyrillic].filter(
|
|
6410
|
+
(x) => x
|
|
6411
|
+
).length;
|
|
6412
|
+
if (unicodeCategories >= 3) {
|
|
6413
|
+
signals.push({
|
|
6414
|
+
type: "encoding_evasion",
|
|
6415
|
+
pattern: "unicode_category_mixing",
|
|
6416
|
+
location: path || "root",
|
|
6417
|
+
severity: "medium"
|
|
6418
|
+
});
|
|
6419
|
+
}
|
|
6420
|
+
}
|
|
6421
|
+
/**
|
|
6422
|
+
* Detect URLs and emails in fields that shouldn't have them.
|
|
6423
|
+
*/
|
|
6424
|
+
detectDataExfiltration(value, path, signals) {
|
|
6425
|
+
if (this.isUrlSafeField(path)) {
|
|
6426
|
+
return;
|
|
6427
|
+
}
|
|
6428
|
+
if (URL_PATTERN.test(value)) {
|
|
6429
|
+
signals.push({
|
|
6430
|
+
type: "data_exfiltration",
|
|
6431
|
+
pattern: "url_in_string",
|
|
6432
|
+
location: path || "root",
|
|
6433
|
+
severity: "medium"
|
|
6434
|
+
});
|
|
6435
|
+
}
|
|
6436
|
+
if (EMAIL_PATTERN.test(value) && !this.isEmailSafeField(path)) {
|
|
6437
|
+
signals.push({
|
|
6438
|
+
type: "data_exfiltration",
|
|
6439
|
+
pattern: "email_in_string",
|
|
6440
|
+
location: path || "root",
|
|
6441
|
+
severity: "medium"
|
|
6442
|
+
});
|
|
6443
|
+
}
|
|
6444
|
+
if (value.length > 30 && value.length < 1e4 && !this.isStructuredField(path)) {
|
|
6445
|
+
const hasJsonContent = /\{[^}]*"[^"]*"[^}]*\}/.test(value);
|
|
6446
|
+
const hasXmlContent = /<[^>]+>[\s\S]*?<\/[^>]+>/.test(value);
|
|
6447
|
+
if (hasJsonContent || hasXmlContent) {
|
|
6448
|
+
signals.push({
|
|
6449
|
+
type: "data_exfiltration",
|
|
6450
|
+
pattern: "structured_data_in_string",
|
|
6451
|
+
location: path || "root",
|
|
6452
|
+
severity: "medium"
|
|
6453
|
+
});
|
|
6454
|
+
}
|
|
6455
|
+
}
|
|
6456
|
+
}
|
|
6457
|
+
/**
|
|
6458
|
+
* Detect prompt stuffing: very large strings or high repetition.
|
|
6459
|
+
*/
|
|
6460
|
+
detectPromptStuffing(value, path, signals) {
|
|
6461
|
+
if (value.length > 10240) {
|
|
6462
|
+
signals.push({
|
|
6463
|
+
type: "prompt_stuffing",
|
|
6464
|
+
pattern: "large_string",
|
|
6465
|
+
location: path || "root",
|
|
6466
|
+
severity: "low"
|
|
6467
|
+
});
|
|
6468
|
+
}
|
|
6469
|
+
if (value.length >= 100) {
|
|
6470
|
+
const windowSizes = [10, 20, 50];
|
|
6471
|
+
for (const windowSize of windowSizes) {
|
|
6472
|
+
if (value.length < windowSize * 5) continue;
|
|
6473
|
+
const pattern = value.substring(0, windowSize);
|
|
6474
|
+
let count = 0;
|
|
6475
|
+
let idx = 0;
|
|
6476
|
+
while (idx <= value.length - windowSize) {
|
|
6477
|
+
if (value.substring(idx, idx + windowSize) === pattern) {
|
|
6478
|
+
count++;
|
|
6479
|
+
idx += windowSize;
|
|
6480
|
+
} else {
|
|
6481
|
+
idx++;
|
|
6482
|
+
}
|
|
6483
|
+
if (count >= 10) break;
|
|
6484
|
+
}
|
|
6485
|
+
if (count >= 10) {
|
|
6486
|
+
signals.push({
|
|
6487
|
+
type: "prompt_stuffing",
|
|
6488
|
+
pattern: "high_repetition",
|
|
6489
|
+
location: path || "root",
|
|
6490
|
+
severity: "low"
|
|
6491
|
+
});
|
|
6492
|
+
break;
|
|
6493
|
+
}
|
|
6494
|
+
}
|
|
6495
|
+
}
|
|
6496
|
+
}
|
|
6497
|
+
/**
|
|
6498
|
+
* Determine if this field is inherently safe from role override.
|
|
6499
|
+
*/
|
|
6500
|
+
isSafeField(path) {
|
|
6501
|
+
const safePaths = [
|
|
6502
|
+
/\.version$/i,
|
|
6503
|
+
/\.timestamp$/i,
|
|
6504
|
+
/\.id$/i,
|
|
6505
|
+
/\.uuid$/i,
|
|
6506
|
+
/\.hash$/i,
|
|
6507
|
+
/\.signature$/i,
|
|
6508
|
+
/\.public_key$/i,
|
|
6509
|
+
/\.private_key$/i,
|
|
6510
|
+
/\.did$/i,
|
|
6511
|
+
/\.nonce$/i,
|
|
6512
|
+
/\.salt$/i,
|
|
6513
|
+
/\.iv$/i,
|
|
6514
|
+
/^ciphertext$/i,
|
|
6515
|
+
/^encrypted$/i
|
|
6516
|
+
];
|
|
6517
|
+
return safePaths.some((p) => p.test(path));
|
|
6518
|
+
}
|
|
6519
|
+
/**
|
|
6520
|
+
* Determine if this is a tool name field (where tool refs are expected).
|
|
6521
|
+
*/
|
|
6522
|
+
isToolNameField(path) {
|
|
6523
|
+
const toolFields = [
|
|
6524
|
+
/tool_name/i,
|
|
6525
|
+
/\.tool$/i,
|
|
6526
|
+
/^tool$/i,
|
|
6527
|
+
/operation/i
|
|
6528
|
+
];
|
|
6529
|
+
return toolFields.some((p) => p.test(path));
|
|
6530
|
+
}
|
|
6531
|
+
/**
|
|
6532
|
+
* Determine if this field is safe for URLs.
|
|
6533
|
+
*/
|
|
6534
|
+
isUrlSafeField(path) {
|
|
6535
|
+
const urlFields = [
|
|
6536
|
+
/url/i,
|
|
6537
|
+
/endpoint/i,
|
|
6538
|
+
/webhook/i,
|
|
6539
|
+
/callback/i
|
|
6540
|
+
];
|
|
6541
|
+
return urlFields.some((p) => p.test(path));
|
|
6542
|
+
}
|
|
6543
|
+
/**
|
|
6544
|
+
* Determine if this field is safe for emails.
|
|
6545
|
+
*/
|
|
6546
|
+
isEmailSafeField(path) {
|
|
6547
|
+
const emailFields = [
|
|
6548
|
+
/email/i,
|
|
6549
|
+
/contact/i,
|
|
6550
|
+
/recipient/i,
|
|
6551
|
+
/sender/i,
|
|
6552
|
+
/from/i,
|
|
6553
|
+
/to/i
|
|
6554
|
+
];
|
|
6555
|
+
return emailFields.some((p) => p.test(path));
|
|
6556
|
+
}
|
|
6557
|
+
/**
|
|
6558
|
+
* Determine if this field is safe for structured data (JSON/XML).
|
|
6559
|
+
*/
|
|
6560
|
+
isStructuredField(path) {
|
|
6561
|
+
const structuredFields = [
|
|
6562
|
+
/data/i,
|
|
6563
|
+
/payload/i,
|
|
6564
|
+
/body/i,
|
|
6565
|
+
/json/i,
|
|
6566
|
+
/xml/i
|
|
6567
|
+
];
|
|
6568
|
+
return structuredFields.some((p) => p.test(path));
|
|
6569
|
+
}
|
|
6570
|
+
/**
|
|
6571
|
+
* SEC-032: Map common cross-script confusable characters to their Latin equivalents.
|
|
6572
|
+
* NFKC normalization handles fullwidth and compatibility forms, but does NOT map
|
|
6573
|
+
* Cyrillic/Greek lookalikes to Latin (they're distinct codepoints by design).
|
|
6574
|
+
* This covers the most common confusables used in injection evasion.
|
|
6575
|
+
*/
|
|
6576
|
+
normalizeConfusables(value) {
|
|
6577
|
+
const confusables = {
|
|
6578
|
+
// Cyrillic → Latin
|
|
6579
|
+
"\u0410": "A",
|
|
6580
|
+
"\u0430": "a",
|
|
6581
|
+
// А а
|
|
6582
|
+
"\u0412": "B",
|
|
6583
|
+
"\u0432": "b",
|
|
6584
|
+
// В (not exact) в (not exact)
|
|
6585
|
+
"\u0421": "C",
|
|
6586
|
+
"\u0441": "c",
|
|
6587
|
+
// С с
|
|
6588
|
+
"\u0415": "E",
|
|
6589
|
+
"\u0435": "e",
|
|
6590
|
+
// Е е
|
|
6591
|
+
"\u041D": "H",
|
|
6592
|
+
"\u043D": "h",
|
|
6593
|
+
// Н (not exact) н (not exact)
|
|
6594
|
+
"\u041A": "K",
|
|
6595
|
+
"\u043A": "k",
|
|
6596
|
+
// К к (not exact)
|
|
6597
|
+
"\u041C": "M",
|
|
6598
|
+
"\u043C": "m",
|
|
6599
|
+
// М (not exact) м (not exact)
|
|
6600
|
+
"\u041E": "O",
|
|
6601
|
+
"\u043E": "o",
|
|
6602
|
+
// О о
|
|
6603
|
+
"\u0420": "P",
|
|
6604
|
+
"\u0440": "p",
|
|
6605
|
+
// Р р
|
|
6606
|
+
"\u0422": "T",
|
|
6607
|
+
"\u0442": "t",
|
|
6608
|
+
// Т (not exact) т (not exact)
|
|
6609
|
+
"\u0425": "X",
|
|
6610
|
+
"\u0445": "x",
|
|
6611
|
+
// Х х
|
|
6612
|
+
"\u0423": "Y",
|
|
6613
|
+
"\u0443": "y",
|
|
6614
|
+
// У (not exact) у
|
|
6615
|
+
// Greek → Latin
|
|
6616
|
+
"\u0391": "A",
|
|
6617
|
+
"\u03B1": "a",
|
|
6618
|
+
// Α α (not exact)
|
|
6619
|
+
"\u0392": "B",
|
|
6620
|
+
"\u03B2": "b",
|
|
6621
|
+
// Β β (not exact)
|
|
6622
|
+
"\u0395": "E",
|
|
6623
|
+
"\u03B5": "e",
|
|
6624
|
+
// Ε ε (not exact)
|
|
6625
|
+
"\u0397": "H",
|
|
6626
|
+
// Η
|
|
6627
|
+
"\u0399": "I",
|
|
6628
|
+
"\u03B9": "i",
|
|
6629
|
+
// Ι ι
|
|
6630
|
+
"\u039A": "K",
|
|
6631
|
+
"\u03BA": "k",
|
|
6632
|
+
// Κ κ
|
|
6633
|
+
"\u039C": "M",
|
|
6634
|
+
// Μ
|
|
6635
|
+
"\u039D": "N",
|
|
6636
|
+
// Ν
|
|
6637
|
+
"\u039F": "O",
|
|
6638
|
+
"\u03BF": "o",
|
|
6639
|
+
// Ο ο
|
|
6640
|
+
"\u03A1": "P",
|
|
6641
|
+
"\u03C1": "p",
|
|
6642
|
+
// Ρ ρ (not exact)
|
|
6643
|
+
"\u03A4": "T",
|
|
6644
|
+
"\u03C4": "t",
|
|
6645
|
+
// Τ τ (not exact)
|
|
6646
|
+
"\u03A5": "Y",
|
|
6647
|
+
"\u03C5": "y",
|
|
6648
|
+
// Υ υ (not exact)
|
|
6649
|
+
"\u03A7": "X",
|
|
6650
|
+
"\u03C7": "x"
|
|
6651
|
+
// Χ χ (not exact)
|
|
6652
|
+
};
|
|
6653
|
+
let result = value;
|
|
6654
|
+
if (/[^\x00-\x7F]/.test(value)) {
|
|
6655
|
+
const chars = [];
|
|
6656
|
+
for (const ch of result) {
|
|
6657
|
+
chars.push(confusables[ch] ?? ch);
|
|
5342
6658
|
}
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
decision: callbackPayload.decision,
|
|
5347
|
-
decided_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5348
|
-
decided_by: "human"
|
|
5349
|
-
};
|
|
5350
|
-
pending.resolve(response);
|
|
5351
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5352
|
-
res.end(
|
|
5353
|
-
JSON.stringify({
|
|
5354
|
-
success: true,
|
|
5355
|
-
decision: callbackPayload.decision
|
|
5356
|
-
})
|
|
5357
|
-
);
|
|
5358
|
-
});
|
|
6659
|
+
result = chars.join("");
|
|
6660
|
+
}
|
|
6661
|
+
return result;
|
|
5359
6662
|
}
|
|
5360
|
-
/**
|
|
5361
|
-
|
|
5362
|
-
|
|
6663
|
+
/**
|
|
6664
|
+
* Compute confidence score based on signals.
|
|
6665
|
+
* More high-severity signals = higher confidence.
|
|
6666
|
+
*/
|
|
6667
|
+
computeConfidence(signals) {
|
|
6668
|
+
if (signals.length === 0) return 0;
|
|
6669
|
+
let score = 0;
|
|
6670
|
+
let highCount = 0;
|
|
6671
|
+
for (const sig of signals) {
|
|
6672
|
+
switch (sig.severity) {
|
|
6673
|
+
case "high":
|
|
6674
|
+
highCount++;
|
|
6675
|
+
score += 0.35;
|
|
6676
|
+
break;
|
|
6677
|
+
case "medium":
|
|
6678
|
+
score += 0.15;
|
|
6679
|
+
break;
|
|
6680
|
+
case "low":
|
|
6681
|
+
score += 0.05;
|
|
6682
|
+
break;
|
|
6683
|
+
}
|
|
6684
|
+
}
|
|
6685
|
+
if (highCount > 1) {
|
|
6686
|
+
score += (highCount - 1) * 0.15;
|
|
6687
|
+
}
|
|
6688
|
+
return Math.min(score, 1);
|
|
6689
|
+
}
|
|
6690
|
+
/**
|
|
6691
|
+
* Compute recommendation based on signals and sensitivity.
|
|
6692
|
+
*/
|
|
6693
|
+
computeRecommendation(signals, sensitivity) {
|
|
6694
|
+
if (signals.length === 0) return "allow";
|
|
6695
|
+
const highSeverity = signals.filter((s) => s.severity === "high");
|
|
6696
|
+
const mediumSeverity = signals.filter((s) => s.severity === "medium");
|
|
6697
|
+
switch (sensitivity) {
|
|
6698
|
+
case "low":
|
|
6699
|
+
return highSeverity.length > 0 ? "escalate" : "allow";
|
|
6700
|
+
case "medium":
|
|
6701
|
+
if (highSeverity.length > 0) return "block";
|
|
6702
|
+
return mediumSeverity.length > 0 ? "escalate" : "allow";
|
|
6703
|
+
case "high":
|
|
6704
|
+
if (highSeverity.length > 0 || mediumSeverity.length > 1) return "block";
|
|
6705
|
+
if (mediumSeverity.length > 0) return "block";
|
|
6706
|
+
return signals.length > 0 ? "escalate" : "allow";
|
|
6707
|
+
}
|
|
6708
|
+
}
|
|
6709
|
+
/**
|
|
6710
|
+
* Get statistics about scans performed.
|
|
6711
|
+
*/
|
|
6712
|
+
getStats() {
|
|
6713
|
+
return {
|
|
6714
|
+
total_scans: this.stats.total_scans,
|
|
6715
|
+
total_flags: this.stats.total_flags,
|
|
6716
|
+
total_blocks: this.stats.total_blocks,
|
|
6717
|
+
signals_by_type: { ...this.stats.signals_by_type }
|
|
6718
|
+
};
|
|
6719
|
+
}
|
|
6720
|
+
/**
|
|
6721
|
+
* Reset statistics.
|
|
6722
|
+
*/
|
|
6723
|
+
resetStats() {
|
|
6724
|
+
this.stats = {
|
|
6725
|
+
total_scans: 0,
|
|
6726
|
+
total_flags: 0,
|
|
6727
|
+
total_blocks: 0,
|
|
6728
|
+
signals_by_type: {}
|
|
6729
|
+
};
|
|
5363
6730
|
}
|
|
5364
6731
|
};
|
|
5365
6732
|
|
|
@@ -5369,11 +6736,15 @@ var ApprovalGate = class {
|
|
|
5369
6736
|
baseline;
|
|
5370
6737
|
channel;
|
|
5371
6738
|
auditLog;
|
|
5372
|
-
|
|
6739
|
+
injectionDetector;
|
|
6740
|
+
onInjectionAlert;
|
|
6741
|
+
constructor(policy, baseline, channel, auditLog, injectionDetector, onInjectionAlert) {
|
|
5373
6742
|
this.policy = policy;
|
|
5374
6743
|
this.baseline = baseline;
|
|
5375
6744
|
this.channel = channel;
|
|
5376
6745
|
this.auditLog = auditLog;
|
|
6746
|
+
this.injectionDetector = injectionDetector ?? new InjectionDetector();
|
|
6747
|
+
this.onInjectionAlert = onInjectionAlert;
|
|
5377
6748
|
}
|
|
5378
6749
|
/**
|
|
5379
6750
|
* Evaluate a tool call against the Principal Policy.
|
|
@@ -5385,6 +6756,48 @@ var ApprovalGate = class {
|
|
|
5385
6756
|
async evaluate(toolName, args) {
|
|
5386
6757
|
const operation = extractOperationName(toolName);
|
|
5387
6758
|
this.baseline.recordToolCall(operation);
|
|
6759
|
+
const injectionResult = this.injectionDetector.scan(toolName, args);
|
|
6760
|
+
if (injectionResult.flagged) {
|
|
6761
|
+
this.auditLog.append("l2", `injection_detected:${operation}`, "system", {
|
|
6762
|
+
confidence: injectionResult.confidence,
|
|
6763
|
+
signals: injectionResult.signals.map((s) => ({
|
|
6764
|
+
type: s.type,
|
|
6765
|
+
location: s.location,
|
|
6766
|
+
severity: s.severity
|
|
6767
|
+
})),
|
|
6768
|
+
recommendation: injectionResult.recommendation
|
|
6769
|
+
});
|
|
6770
|
+
if (this.onInjectionAlert) {
|
|
6771
|
+
this.onInjectionAlert({
|
|
6772
|
+
toolName,
|
|
6773
|
+
result: injectionResult,
|
|
6774
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6775
|
+
});
|
|
6776
|
+
}
|
|
6777
|
+
if (injectionResult.recommendation === "block") {
|
|
6778
|
+
return {
|
|
6779
|
+
allowed: false,
|
|
6780
|
+
tier: 1,
|
|
6781
|
+
reason: `Blocked: prompt injection detected in "${operation}" (confidence: ${(injectionResult.confidence * 100).toFixed(0)}%)`,
|
|
6782
|
+
approval_required: false
|
|
6783
|
+
};
|
|
6784
|
+
}
|
|
6785
|
+
if (injectionResult.recommendation === "escalate") {
|
|
6786
|
+
return this.requestApproval(
|
|
6787
|
+
operation,
|
|
6788
|
+
1,
|
|
6789
|
+
`Potential prompt injection detected in "${operation}" (confidence: ${(injectionResult.confidence * 100).toFixed(0)}%, ${injectionResult.signals.length} signal(s))`,
|
|
6790
|
+
{
|
|
6791
|
+
operation,
|
|
6792
|
+
injection_detection: {
|
|
6793
|
+
confidence: injectionResult.confidence,
|
|
6794
|
+
signal_count: injectionResult.signals.length,
|
|
6795
|
+
signal_types: [...new Set(injectionResult.signals.map((s) => s.type))]
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6798
|
+
);
|
|
6799
|
+
}
|
|
6800
|
+
}
|
|
5388
6801
|
if (this.policy.tier1_always_approve.includes(operation)) {
|
|
5389
6802
|
return this.requestApproval(operation, 1, `"${operation}" is a Tier 1 operation (always requires approval)`, {
|
|
5390
6803
|
operation,
|
|
@@ -5563,6 +6976,10 @@ var ApprovalGate = class {
|
|
|
5563
6976
|
getBaseline() {
|
|
5564
6977
|
return this.baseline;
|
|
5565
6978
|
}
|
|
6979
|
+
/** Get the injection detector for stats/configuration access */
|
|
6980
|
+
getInjectionDetector() {
|
|
6981
|
+
return this.injectionDetector;
|
|
6982
|
+
}
|
|
5566
6983
|
};
|
|
5567
6984
|
|
|
5568
6985
|
// src/principal-policy/tools.ts
|
|
@@ -8759,9 +10176,345 @@ function matchesFieldPattern(normalizedField, pattern) {
|
|
|
8759
10176
|
return false;
|
|
8760
10177
|
}
|
|
8761
10178
|
|
|
10179
|
+
// src/l2-operational/context-gate-enforcer.ts
|
|
10180
|
+
init_encoding();
|
|
10181
|
+
init_hashing();
|
|
10182
|
+
var BUILTIN_SENSITIVE_PATTERNS = [
|
|
10183
|
+
"*_key",
|
|
10184
|
+
"*_token",
|
|
10185
|
+
"*_secret",
|
|
10186
|
+
"api_key",
|
|
10187
|
+
"access_token",
|
|
10188
|
+
"refresh_token",
|
|
10189
|
+
"password",
|
|
10190
|
+
"passwd",
|
|
10191
|
+
"credential*",
|
|
10192
|
+
"auth_*",
|
|
10193
|
+
"ssn",
|
|
10194
|
+
"social_security*",
|
|
10195
|
+
"tax_id*",
|
|
10196
|
+
"credit_card*",
|
|
10197
|
+
"card_number*",
|
|
10198
|
+
"cvv",
|
|
10199
|
+
"cvc",
|
|
10200
|
+
"private_key",
|
|
10201
|
+
"secret_key",
|
|
10202
|
+
"master_key"
|
|
10203
|
+
];
|
|
10204
|
+
var ContextGateEnforcer = class {
|
|
10205
|
+
policyStore;
|
|
10206
|
+
auditLog;
|
|
10207
|
+
config;
|
|
10208
|
+
stats = {
|
|
10209
|
+
calls_inspected: 0,
|
|
10210
|
+
calls_bypassed: 0,
|
|
10211
|
+
fields_redacted: 0,
|
|
10212
|
+
fields_hashed: 0,
|
|
10213
|
+
fields_blocked: 0,
|
|
10214
|
+
calls_blocked: 0
|
|
10215
|
+
};
|
|
10216
|
+
constructor(policyStore, auditLog, config) {
|
|
10217
|
+
this.policyStore = policyStore;
|
|
10218
|
+
this.auditLog = auditLog;
|
|
10219
|
+
this.config = config;
|
|
10220
|
+
}
|
|
10221
|
+
/**
|
|
10222
|
+
* Wrap a tool handler to apply automatic context gating.
|
|
10223
|
+
*
|
|
10224
|
+
* The wrapped handler:
|
|
10225
|
+
* 1. Checks if tool should be filtered (based on bypass_prefixes)
|
|
10226
|
+
* 2. If not filtering, calls original handler directly
|
|
10227
|
+
* 3. If filtering:
|
|
10228
|
+
* a. Gets the active policy or falls back to built-in patterns
|
|
10229
|
+
* b. Calls filterContext() with tool arguments
|
|
10230
|
+
* c. If any field triggered "deny" and on_deny is "block", returns error
|
|
10231
|
+
* d. If on_deny is "redact", replaces denied fields with "[REDACTED]"
|
|
10232
|
+
* e. Calls original handler with filtered arguments
|
|
10233
|
+
* f. Logs the filtering decision
|
|
10234
|
+
* 4. In log_only mode: runs filter, logs what would happen, passes original args
|
|
10235
|
+
*/
|
|
10236
|
+
wrapHandler(toolName, originalHandler) {
|
|
10237
|
+
return async (args) => {
|
|
10238
|
+
if (!this.config.enabled) {
|
|
10239
|
+
return originalHandler(args);
|
|
10240
|
+
}
|
|
10241
|
+
if (!this.shouldFilter(toolName)) {
|
|
10242
|
+
this.stats.calls_bypassed++;
|
|
10243
|
+
return originalHandler(args);
|
|
10244
|
+
}
|
|
10245
|
+
this.stats.calls_inspected++;
|
|
10246
|
+
const policy = this.config.default_policy_id ? await this.policyStore.get(this.config.default_policy_id) : null;
|
|
10247
|
+
if (policy) {
|
|
10248
|
+
return this.filterWithPolicy(
|
|
10249
|
+
toolName,
|
|
10250
|
+
args,
|
|
10251
|
+
originalHandler,
|
|
10252
|
+
policy
|
|
10253
|
+
);
|
|
10254
|
+
} else {
|
|
10255
|
+
return this.filterWithBuiltinPatterns(
|
|
10256
|
+
toolName,
|
|
10257
|
+
args,
|
|
10258
|
+
originalHandler
|
|
10259
|
+
);
|
|
10260
|
+
}
|
|
10261
|
+
};
|
|
10262
|
+
}
|
|
10263
|
+
/**
|
|
10264
|
+
* Filter tool arguments using an explicit policy.
|
|
10265
|
+
*/
|
|
10266
|
+
async filterWithPolicy(toolName, args, originalHandler, policy) {
|
|
10267
|
+
const provider = this.extractProviderCategory(toolName);
|
|
10268
|
+
const result = filterContext(policy, provider, args);
|
|
10269
|
+
const deniedFields = result.decisions.filter((d) => d.action === "deny");
|
|
10270
|
+
if (deniedFields.length > 0) {
|
|
10271
|
+
if (this.config.on_deny === "block") {
|
|
10272
|
+
this.stats.calls_blocked++;
|
|
10273
|
+
this.auditLog.append(
|
|
10274
|
+
"l2",
|
|
10275
|
+
"context_gate_enforcer_block",
|
|
10276
|
+
"system",
|
|
10277
|
+
{
|
|
10278
|
+
tool_name: toolName,
|
|
10279
|
+
policy_id: policy.policy_id,
|
|
10280
|
+
provider,
|
|
10281
|
+
denied_fields: deniedFields.map((d) => d.field),
|
|
10282
|
+
original_context_hash: result.original_context_hash
|
|
10283
|
+
}
|
|
10284
|
+
);
|
|
10285
|
+
return toolResult({
|
|
10286
|
+
error: "context_gating_blocked",
|
|
10287
|
+
message: "Tool call contains fields that trigger deny action",
|
|
10288
|
+
tool: toolName,
|
|
10289
|
+
denied_fields: deniedFields.map((d) => d.field),
|
|
10290
|
+
recommendation: "Remove the denied fields from context or update the context-gating policy."
|
|
10291
|
+
});
|
|
10292
|
+
}
|
|
10293
|
+
}
|
|
10294
|
+
const filteredArgs = this.buildFilteredArgs(args, result.decisions);
|
|
10295
|
+
if (this.config.log_only) {
|
|
10296
|
+
this.auditLog.append(
|
|
10297
|
+
"l2",
|
|
10298
|
+
"context_gate_enforcer_log_only",
|
|
10299
|
+
"system",
|
|
10300
|
+
{
|
|
10301
|
+
tool_name: toolName,
|
|
10302
|
+
policy_id: policy.policy_id,
|
|
10303
|
+
provider,
|
|
10304
|
+
fields_total: Object.keys(args).length,
|
|
10305
|
+
fields_redacted: result.fields_redacted,
|
|
10306
|
+
fields_hashed: result.fields_hashed,
|
|
10307
|
+
fields_blocked: deniedFields.length,
|
|
10308
|
+
original_context_hash: result.original_context_hash
|
|
10309
|
+
}
|
|
10310
|
+
);
|
|
10311
|
+
this.stats.fields_redacted += result.fields_redacted;
|
|
10312
|
+
this.stats.fields_hashed += result.fields_hashed;
|
|
10313
|
+
this.stats.fields_blocked += deniedFields.length;
|
|
10314
|
+
return originalHandler(args);
|
|
10315
|
+
}
|
|
10316
|
+
this.auditLog.append(
|
|
10317
|
+
"l2",
|
|
10318
|
+
"context_gate_enforcer_filter",
|
|
10319
|
+
"system",
|
|
10320
|
+
{
|
|
10321
|
+
tool_name: toolName,
|
|
10322
|
+
policy_id: policy.policy_id,
|
|
10323
|
+
provider,
|
|
10324
|
+
fields_total: Object.keys(args).length,
|
|
10325
|
+
fields_redacted: result.fields_redacted,
|
|
10326
|
+
fields_hashed: result.fields_hashed,
|
|
10327
|
+
fields_blocked: deniedFields.length,
|
|
10328
|
+
original_context_hash: result.original_context_hash
|
|
10329
|
+
}
|
|
10330
|
+
);
|
|
10331
|
+
this.stats.fields_redacted += result.fields_redacted;
|
|
10332
|
+
this.stats.fields_hashed += result.fields_hashed;
|
|
10333
|
+
this.stats.fields_blocked += deniedFields.length;
|
|
10334
|
+
return originalHandler(filteredArgs);
|
|
10335
|
+
}
|
|
10336
|
+
/**
|
|
10337
|
+
* Filter tool arguments using built-in sensitive patterns.
|
|
10338
|
+
* This provides baseline protection when no explicit policy is configured.
|
|
10339
|
+
*/
|
|
10340
|
+
async filterWithBuiltinPatterns(toolName, args, originalHandler) {
|
|
10341
|
+
const fieldsToRedact = [];
|
|
10342
|
+
const originalHash = hashToString(
|
|
10343
|
+
stringToBytes(JSON.stringify(args))
|
|
10344
|
+
);
|
|
10345
|
+
for (const field of Object.keys(args)) {
|
|
10346
|
+
if (matchesPattern(field, BUILTIN_SENSITIVE_PATTERNS)) {
|
|
10347
|
+
fieldsToRedact.push(field);
|
|
10348
|
+
}
|
|
10349
|
+
}
|
|
10350
|
+
if (fieldsToRedact.length === 0) {
|
|
10351
|
+
this.auditLog.append(
|
|
10352
|
+
"l2",
|
|
10353
|
+
"context_gate_enforcer_builtin_pass",
|
|
10354
|
+
"system",
|
|
10355
|
+
{
|
|
10356
|
+
tool_name: toolName,
|
|
10357
|
+
reason: "No sensitive field patterns detected"
|
|
10358
|
+
}
|
|
10359
|
+
);
|
|
10360
|
+
return originalHandler(args);
|
|
10361
|
+
}
|
|
10362
|
+
const filteredArgs = {};
|
|
10363
|
+
for (const [key, value] of Object.entries(args)) {
|
|
10364
|
+
if (fieldsToRedact.includes(key)) {
|
|
10365
|
+
filteredArgs[key] = "[REDACTED]";
|
|
10366
|
+
} else {
|
|
10367
|
+
filteredArgs[key] = value;
|
|
10368
|
+
}
|
|
10369
|
+
}
|
|
10370
|
+
const filteredHash = hashToString(
|
|
10371
|
+
stringToBytes(JSON.stringify(filteredArgs))
|
|
10372
|
+
);
|
|
10373
|
+
if (this.config.log_only) {
|
|
10374
|
+
this.auditLog.append(
|
|
10375
|
+
"l2",
|
|
10376
|
+
"context_gate_enforcer_builtin_log_only",
|
|
10377
|
+
"system",
|
|
10378
|
+
{
|
|
10379
|
+
tool_name: toolName,
|
|
10380
|
+
fields_redacted: fieldsToRedact.length,
|
|
10381
|
+
redacted_fields: fieldsToRedact,
|
|
10382
|
+
original_context_hash: originalHash
|
|
10383
|
+
}
|
|
10384
|
+
);
|
|
10385
|
+
this.stats.fields_redacted += fieldsToRedact.length;
|
|
10386
|
+
return originalHandler(args);
|
|
10387
|
+
}
|
|
10388
|
+
this.auditLog.append(
|
|
10389
|
+
"l2",
|
|
10390
|
+
"context_gate_enforcer_builtin_filter",
|
|
10391
|
+
"system",
|
|
10392
|
+
{
|
|
10393
|
+
tool_name: toolName,
|
|
10394
|
+
fields_redacted: fieldsToRedact.length,
|
|
10395
|
+
redacted_fields: fieldsToRedact,
|
|
10396
|
+
original_context_hash: originalHash,
|
|
10397
|
+
filtered_context_hash: filteredHash
|
|
10398
|
+
}
|
|
10399
|
+
);
|
|
10400
|
+
this.stats.fields_redacted += fieldsToRedact.length;
|
|
10401
|
+
return originalHandler(filteredArgs);
|
|
10402
|
+
}
|
|
10403
|
+
/**
|
|
10404
|
+
* Check if a tool should be filtered based on bypass prefixes.
|
|
10405
|
+
*
|
|
10406
|
+
* SEC-033: Uses exact namespace component matching, not bare startsWith().
|
|
10407
|
+
* A prefix of "sanctuary/" matches "sanctuary/state_read" but NOT
|
|
10408
|
+
* "sanctuary_evil/steal_data" (no slash boundary confusion). The prefix
|
|
10409
|
+
* must match exactly up to its length, and the prefix must end with "/"
|
|
10410
|
+
* to enforce namespace boundaries (if it doesn't, we add one for safety).
|
|
10411
|
+
*/
|
|
10412
|
+
shouldFilter(toolName) {
|
|
10413
|
+
for (const prefix of this.config.bypass_prefixes) {
|
|
10414
|
+
const safePrefix = prefix.endsWith("/") ? prefix : prefix + "/";
|
|
10415
|
+
if (toolName === safePrefix.slice(0, -1) || toolName.startsWith(safePrefix)) {
|
|
10416
|
+
return false;
|
|
10417
|
+
}
|
|
10418
|
+
}
|
|
10419
|
+
return true;
|
|
10420
|
+
}
|
|
10421
|
+
/**
|
|
10422
|
+
* Extract provider category from tool name.
|
|
10423
|
+
* Default: "tool-api". Override for specific patterns.
|
|
10424
|
+
*/
|
|
10425
|
+
extractProviderCategory(toolName) {
|
|
10426
|
+
if (toolName.includes("inference") || toolName.includes("llm")) {
|
|
10427
|
+
return "inference";
|
|
10428
|
+
}
|
|
10429
|
+
if (toolName.includes("log") || toolName.includes("telemetry")) {
|
|
10430
|
+
return "logging";
|
|
10431
|
+
}
|
|
10432
|
+
if (toolName.includes("analytics") || toolName.includes("metric")) {
|
|
10433
|
+
return "analytics";
|
|
10434
|
+
}
|
|
10435
|
+
return "tool-api";
|
|
10436
|
+
}
|
|
10437
|
+
/**
|
|
10438
|
+
* Build filtered arguments from filter decisions.
|
|
10439
|
+
*/
|
|
10440
|
+
buildFilteredArgs(originalArgs, decisions) {
|
|
10441
|
+
const filtered = {};
|
|
10442
|
+
for (const decision of decisions) {
|
|
10443
|
+
switch (decision.action) {
|
|
10444
|
+
case "allow":
|
|
10445
|
+
filtered[decision.field] = originalArgs[decision.field];
|
|
10446
|
+
break;
|
|
10447
|
+
case "redact":
|
|
10448
|
+
filtered[decision.field] = "[REDACTED]";
|
|
10449
|
+
break;
|
|
10450
|
+
case "hash":
|
|
10451
|
+
filtered[decision.field] = decision.hash_value;
|
|
10452
|
+
break;
|
|
10453
|
+
case "summarize":
|
|
10454
|
+
filtered[decision.field] = originalArgs[decision.field];
|
|
10455
|
+
break;
|
|
10456
|
+
}
|
|
10457
|
+
}
|
|
10458
|
+
return filtered;
|
|
10459
|
+
}
|
|
10460
|
+
/**
|
|
10461
|
+
* Set the active policy ID.
|
|
10462
|
+
*/
|
|
10463
|
+
setDefaultPolicy(policyId) {
|
|
10464
|
+
this.config.default_policy_id = policyId;
|
|
10465
|
+
}
|
|
10466
|
+
/**
|
|
10467
|
+
* Get current enforcer status and stats.
|
|
10468
|
+
*/
|
|
10469
|
+
getStatus() {
|
|
10470
|
+
return {
|
|
10471
|
+
enabled: this.config.enabled,
|
|
10472
|
+
log_only: this.config.log_only,
|
|
10473
|
+
default_policy_id: this.config.default_policy_id ?? null,
|
|
10474
|
+
stats: { ...this.stats }
|
|
10475
|
+
};
|
|
10476
|
+
}
|
|
10477
|
+
/**
|
|
10478
|
+
* Toggle enforcer enabled state.
|
|
10479
|
+
*/
|
|
10480
|
+
setEnabled(enabled) {
|
|
10481
|
+
this.config.enabled = enabled;
|
|
10482
|
+
}
|
|
10483
|
+
/**
|
|
10484
|
+
* Toggle log_only mode.
|
|
10485
|
+
*/
|
|
10486
|
+
setLogOnly(logOnly) {
|
|
10487
|
+
this.config.log_only = logOnly;
|
|
10488
|
+
}
|
|
10489
|
+
/**
|
|
10490
|
+
* Reset stats counters.
|
|
10491
|
+
*/
|
|
10492
|
+
resetStats() {
|
|
10493
|
+
this.stats = {
|
|
10494
|
+
calls_inspected: 0,
|
|
10495
|
+
calls_bypassed: 0,
|
|
10496
|
+
fields_redacted: 0,
|
|
10497
|
+
fields_hashed: 0,
|
|
10498
|
+
fields_blocked: 0,
|
|
10499
|
+
calls_blocked: 0
|
|
10500
|
+
};
|
|
10501
|
+
}
|
|
10502
|
+
};
|
|
10503
|
+
|
|
8762
10504
|
// src/l2-operational/context-gate-tools.ts
|
|
8763
10505
|
function createContextGateTools(storage, masterKey, auditLog) {
|
|
8764
10506
|
const policyStore = new ContextGatePolicyStore(storage, masterKey);
|
|
10507
|
+
const enforcerConfig = {
|
|
10508
|
+
enabled: false,
|
|
10509
|
+
// Off by default; agents must explicitly enable it
|
|
10510
|
+
bypass_prefixes: ["sanctuary/"],
|
|
10511
|
+
// Skip internal tools by default
|
|
10512
|
+
log_only: false,
|
|
10513
|
+
// Filter immediately
|
|
10514
|
+
on_deny: "block"
|
|
10515
|
+
// Block requests with denied fields
|
|
10516
|
+
};
|
|
10517
|
+
const enforcer = new ContextGateEnforcer(policyStore, auditLog, enforcerConfig);
|
|
8765
10518
|
const tools = [
|
|
8766
10519
|
// ── Set Policy ──────────────────────────────────────────────────
|
|
8767
10520
|
{
|
|
@@ -9114,9 +10867,121 @@ function createContextGateTools(storage, masterKey, auditLog) {
|
|
|
9114
10867
|
message: policies.length === 0 ? "No context-gating policies configured. Use sanctuary/context_gate_set_policy to create one." : `${policies.length} context-gating ${policies.length === 1 ? "policy" : "policies"} configured.`
|
|
9115
10868
|
});
|
|
9116
10869
|
}
|
|
10870
|
+
},
|
|
10871
|
+
// ── Enforcer Status ─────────────────────────────────────────────────
|
|
10872
|
+
{
|
|
10873
|
+
name: "sanctuary/context_gate_enforcer_status",
|
|
10874
|
+
description: "Get the status of the automatic context gate enforcer, including enabled/disabled state, log_only mode, active policy, and statistics. The enforcer automatically filters tool arguments when enabled. Use this to monitor what the enforcer has been filtering.",
|
|
10875
|
+
inputSchema: {
|
|
10876
|
+
type: "object",
|
|
10877
|
+
properties: {}
|
|
10878
|
+
},
|
|
10879
|
+
handler: async () => {
|
|
10880
|
+
const status = enforcer.getStatus();
|
|
10881
|
+
auditLog.append(
|
|
10882
|
+
"l2",
|
|
10883
|
+
"context_gate_enforcer_status_query",
|
|
10884
|
+
"system",
|
|
10885
|
+
{
|
|
10886
|
+
enabled: status.enabled,
|
|
10887
|
+
log_only: status.log_only,
|
|
10888
|
+
default_policy_id: status.default_policy_id
|
|
10889
|
+
}
|
|
10890
|
+
);
|
|
10891
|
+
return toolResult({
|
|
10892
|
+
enforcer_status: status,
|
|
10893
|
+
description: "The enforcer is " + (status.enabled ? "enabled" : "disabled") + ". " + (status.log_only ? "Currently in log_only mode \u2014 filtering is logged but not applied." : "Filtering is actively applied to tool arguments."),
|
|
10894
|
+
guidance: status.stats.calls_inspected > 0 ? `Over ${status.stats.calls_inspected} tool calls, ${status.stats.fields_redacted} sensitive fields were redacted. Use sanctuary/context_gate_enforcer_configure to adjust settings.` : "No tool calls have been inspected yet."
|
|
10895
|
+
});
|
|
10896
|
+
}
|
|
10897
|
+
},
|
|
10898
|
+
// ── Enforcer Configuration ──────────────────────────────────────────
|
|
10899
|
+
{
|
|
10900
|
+
name: "sanctuary/context_gate_enforcer_configure",
|
|
10901
|
+
description: "Configure the automatic context gate enforcer. Control whether it filters tool arguments, toggle log_only mode for gradual rollout, set the active policy, and choose what to do when denied fields are encountered (block the request or redact the field). Use this to enable automatic context protection.",
|
|
10902
|
+
inputSchema: {
|
|
10903
|
+
type: "object",
|
|
10904
|
+
properties: {
|
|
10905
|
+
enabled: {
|
|
10906
|
+
type: "boolean",
|
|
10907
|
+
description: "Enable or disable the automatic enforcer. When disabled, no filtering occurs. Default: leave unchanged."
|
|
10908
|
+
},
|
|
10909
|
+
log_only: {
|
|
10910
|
+
type: "boolean",
|
|
10911
|
+
description: "Enable log_only mode: filter decisions are logged but original args are passed to handlers. Useful for monitoring before enabling actual filtering. Default: leave unchanged."
|
|
10912
|
+
},
|
|
10913
|
+
default_policy_id: {
|
|
10914
|
+
type: "string",
|
|
10915
|
+
description: "Set the default context-gating policy to use for filtering. If not set, the enforcer uses built-in sensitive field patterns. Default: leave unchanged."
|
|
10916
|
+
},
|
|
10917
|
+
on_deny: {
|
|
10918
|
+
type: "string",
|
|
10919
|
+
enum: ["block", "redact"],
|
|
10920
|
+
description: "Action to take when a field triggers the deny action: 'block' returns an error and prevents the call, 'redact' replaces the denied field with [REDACTED] and continues. Default: leave unchanged."
|
|
10921
|
+
},
|
|
10922
|
+
reset_stats: {
|
|
10923
|
+
type: "boolean",
|
|
10924
|
+
description: "Reset the enforcer statistics counters to zero. Default: false."
|
|
10925
|
+
}
|
|
10926
|
+
}
|
|
10927
|
+
},
|
|
10928
|
+
handler: async (args) => {
|
|
10929
|
+
const changes = {};
|
|
10930
|
+
if (args.enabled !== void 0) {
|
|
10931
|
+
enforcer.setEnabled(args.enabled);
|
|
10932
|
+
changes.enabled = args.enabled;
|
|
10933
|
+
}
|
|
10934
|
+
if (args.log_only !== void 0) {
|
|
10935
|
+
enforcer.setLogOnly(args.log_only);
|
|
10936
|
+
changes.log_only = args.log_only;
|
|
10937
|
+
}
|
|
10938
|
+
if (args.default_policy_id !== void 0) {
|
|
10939
|
+
const policyId = args.default_policy_id;
|
|
10940
|
+
const policy = await policyStore.get(policyId);
|
|
10941
|
+
if (!policy) {
|
|
10942
|
+
return toolResult({
|
|
10943
|
+
error: "policy_not_found",
|
|
10944
|
+
message: `No context-gating policy found with ID "${policyId}"`
|
|
10945
|
+
});
|
|
10946
|
+
}
|
|
10947
|
+
enforcer.setDefaultPolicy(policyId);
|
|
10948
|
+
changes.default_policy_id = policyId;
|
|
10949
|
+
}
|
|
10950
|
+
if (args.on_deny !== void 0) {
|
|
10951
|
+
const onDeny = args.on_deny;
|
|
10952
|
+
if (onDeny !== "block" && onDeny !== "redact") {
|
|
10953
|
+
return toolResult({
|
|
10954
|
+
error: "invalid_on_deny",
|
|
10955
|
+
message: "on_deny must be 'block' or 'redact'"
|
|
10956
|
+
});
|
|
10957
|
+
}
|
|
10958
|
+
enforcerConfig.on_deny = onDeny;
|
|
10959
|
+
changes.on_deny = onDeny;
|
|
10960
|
+
}
|
|
10961
|
+
if (args.reset_stats === true) {
|
|
10962
|
+
enforcer.resetStats();
|
|
10963
|
+
changes.reset_stats = true;
|
|
10964
|
+
}
|
|
10965
|
+
const newStatus = enforcer.getStatus();
|
|
10966
|
+
auditLog.append(
|
|
10967
|
+
"l2",
|
|
10968
|
+
"context_gate_enforcer_configure",
|
|
10969
|
+
"system",
|
|
10970
|
+
{
|
|
10971
|
+
changes,
|
|
10972
|
+
new_status: newStatus
|
|
10973
|
+
}
|
|
10974
|
+
);
|
|
10975
|
+
return toolResult({
|
|
10976
|
+
configured: true,
|
|
10977
|
+
changes,
|
|
10978
|
+
new_status: newStatus,
|
|
10979
|
+
message: Object.keys(changes).length > 0 ? "Enforcer configuration updated." : "No changes made (no configuration parameters provided)."
|
|
10980
|
+
});
|
|
10981
|
+
}
|
|
9117
10982
|
}
|
|
9118
10983
|
];
|
|
9119
|
-
return { tools, policyStore };
|
|
10984
|
+
return { tools, policyStore, enforcer };
|
|
9120
10985
|
}
|
|
9121
10986
|
function checkMemoryProtection() {
|
|
9122
10987
|
const checks = {
|
|
@@ -9861,11 +11726,7 @@ async function createSanctuaryServer(options) {
|
|
|
9861
11726
|
handshakeResults
|
|
9862
11727
|
);
|
|
9863
11728
|
const { tools: auditTools } = createAuditTools(config);
|
|
9864
|
-
const { tools: contextGateTools } = createContextGateTools(
|
|
9865
|
-
storage,
|
|
9866
|
-
masterKey,
|
|
9867
|
-
auditLog
|
|
9868
|
-
);
|
|
11729
|
+
const { tools: contextGateTools, enforcer: contextGateEnforcer } = createContextGateTools(storage, masterKey, auditLog);
|
|
9869
11730
|
const hardeningTools = createL2HardeningTools(config.storage_path, auditLog);
|
|
9870
11731
|
const policy = await loadPrincipalPolicy(config.storage_path);
|
|
9871
11732
|
const baseline = new BaselineTracker(storage, masterKey);
|
|
@@ -9903,9 +11764,27 @@ async function createSanctuaryServer(options) {
|
|
|
9903
11764
|
} else {
|
|
9904
11765
|
approvalChannel = new StderrApprovalChannel(policy.approval_channel);
|
|
9905
11766
|
}
|
|
9906
|
-
const
|
|
11767
|
+
const injectionDetector = new InjectionDetector({
|
|
11768
|
+
enabled: true,
|
|
11769
|
+
sensitivity: "medium",
|
|
11770
|
+
on_detection: "escalate"
|
|
11771
|
+
});
|
|
11772
|
+
const onInjectionAlert = dashboard ? (alert) => {
|
|
11773
|
+
dashboard.broadcastSSE("injection-alert", {
|
|
11774
|
+
tool: alert.toolName,
|
|
11775
|
+
confidence: alert.result.confidence,
|
|
11776
|
+
signals: alert.result.signals.map((s) => ({
|
|
11777
|
+
type: s.type,
|
|
11778
|
+
location: s.location,
|
|
11779
|
+
severity: s.severity
|
|
11780
|
+
})),
|
|
11781
|
+
recommendation: alert.result.recommendation,
|
|
11782
|
+
timestamp: alert.timestamp
|
|
11783
|
+
});
|
|
11784
|
+
} : void 0;
|
|
11785
|
+
const gate = new ApprovalGate(policy, baseline, approvalChannel, auditLog, injectionDetector, onInjectionAlert);
|
|
9907
11786
|
const policyTools = createPrincipalPolicyTools(policy, baseline, auditLog);
|
|
9908
|
-
|
|
11787
|
+
let allTools = [
|
|
9909
11788
|
...l1Tools,
|
|
9910
11789
|
...l2Tools,
|
|
9911
11790
|
...l3Tools,
|
|
@@ -9920,6 +11799,10 @@ async function createSanctuaryServer(options) {
|
|
|
9920
11799
|
...hardeningTools,
|
|
9921
11800
|
manifestTool
|
|
9922
11801
|
];
|
|
11802
|
+
allTools = allTools.map((tool) => ({
|
|
11803
|
+
...tool,
|
|
11804
|
+
handler: contextGateEnforcer.wrapHandler(tool.name, tool.handler)
|
|
11805
|
+
}));
|
|
9923
11806
|
const server = createServer(allTools, { gate });
|
|
9924
11807
|
await saveConfig(config);
|
|
9925
11808
|
const saveBaseline = () => {
|