unbound-cli 1.20.6 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/package.json +1 -1
- package/src/commands/false-positive.js +130 -0
- package/src/commands/flags.js +11 -11
- package/src/commands/trace.js +11 -13
- package/src/index.js +7 -1
- package/src/lib/flags.js +13 -28
- package/test/false-positive.test.js +116 -0
- package/test/flags.test.js +36 -19
package/README.md
CHANGED
|
@@ -315,9 +315,10 @@ Listing needs Admin, Manager or Analytics Viewer. `mark-fp` needs Admin.
|
|
|
315
315
|
|---------|-------------|
|
|
316
316
|
| `unbound flags terminal` | Terminal runs that a tool policy flagged (block, approval, warn, audit) |
|
|
317
317
|
| `unbound flags terminal mark-fp <id> --risk-score <n>` | Reject the run's risk score as a false positive |
|
|
318
|
-
| `unbound flags data-security` | PII and secrets a guardrail found (values
|
|
318
|
+
| `unbound flags data-security` | PII and secrets a guardrail found (the detected values and prompts are never shown) |
|
|
319
319
|
| `unbound flags data-security mark-fp <action-id>` | Mark a detection as a false positive |
|
|
320
|
-
| `unbound trace <trace-id>` | The log, terminal runs and data security detections for one trace ID (prompts and values
|
|
320
|
+
| `unbound trace <trace-id>` | The log, terminal runs and data security detections for one trace ID (prompts and detected values are never shown) |
|
|
321
|
+
| `unbound false-positive list\|mark\|unmark <trace-id>` | Any user: show, mark or unmark a false positive on their own findings (alias `fp`; admins can act on any finding in their org) |
|
|
321
322
|
|
|
322
323
|
```bash
|
|
323
324
|
unbound flags terminal --action block,warn --time-window SEVEN_DAYS
|
|
@@ -327,7 +328,7 @@ unbound flags data-security mark-fp 5521
|
|
|
327
328
|
unbound trace 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c --json
|
|
328
329
|
```
|
|
329
330
|
|
|
330
|
-
Terminal `mark-fp` records the same feedback as rejecting a risk score in the dashboard. It does not hide the run. Data security `mark-fp` moves the detection to `--findings false-positive`, and the gateway then skips that value for the organization.
|
|
331
|
+
Terminal `mark-fp` records the same feedback as rejecting a risk score in the dashboard. It does not hide the run. Data security `mark-fp` moves the detection to `--findings false-positive`, and the gateway then skips that value for the organization. The CLI never shows a detected value or the prompt it was found in; see them in the console.
|
|
331
332
|
|
|
332
333
|
## Configuration
|
|
333
334
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const api = require('../api');
|
|
2
|
+
const config = require('../config');
|
|
3
|
+
const output = require('../output');
|
|
4
|
+
const { confirm } = require('../utils');
|
|
5
|
+
const { resolveTraceId } = require('../lib/flags');
|
|
6
|
+
|
|
7
|
+
const PATH = '/api/v1/analytics/guardrails/my_false_positive/';
|
|
8
|
+
const HEADERS = ['ID', 'Type', 'Action', 'Status'];
|
|
9
|
+
|
|
10
|
+
function statusOf(finding) {
|
|
11
|
+
return finding.is_false_positive ? 'False positive' : 'Flagged';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// The one finding a mark or unmark acts on: the --finding id, or the only candidate on the trace.
|
|
15
|
+
function chooseFinding(findings, mark, findingId) {
|
|
16
|
+
if (findingId !== undefined) {
|
|
17
|
+
const id = Number(findingId);
|
|
18
|
+
const found = findings.find((f) => f.id === id);
|
|
19
|
+
if (!found) throw new Error(`Finding ${findingId} is not one of your findings on this trace.`);
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
const candidates = findings.filter((f) => (mark ? f.markable : f.unmarkable));
|
|
23
|
+
if (candidates.length === 0) {
|
|
24
|
+
throw new Error(mark ? 'Nothing on this trace is left to mark.' : 'No mark of yours on this trace can be unmarked.');
|
|
25
|
+
}
|
|
26
|
+
if (candidates.length > 1) {
|
|
27
|
+
throw new Error(`${candidates.length} findings match (IDs ${candidates.map((f) => f.id).join(', ')}). Pass --finding <id>.`);
|
|
28
|
+
}
|
|
29
|
+
return candidates[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function fetchFindings(trace) {
|
|
33
|
+
const data = await api.get(`${PATH}?trace_id=${trace}`);
|
|
34
|
+
return data.findings || [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function run(fn) {
|
|
38
|
+
try {
|
|
39
|
+
if (!config.isLoggedIn()) throw new Error('Not logged in. Run `unbound login` first.');
|
|
40
|
+
await fn();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
output.error(err.message);
|
|
43
|
+
process.exitCode = 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function list(traceValue, opts) {
|
|
48
|
+
const trace = resolveTraceId(traceValue);
|
|
49
|
+
const findings = await fetchFindings(trace);
|
|
50
|
+
if (opts.json) {
|
|
51
|
+
output.json({ trace_id: trace, findings });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (findings.length === 0) {
|
|
55
|
+
output.info(`No findings of yours on trace ${trace}.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
output.logTable(HEADERS, findings.map((f) => [String(f.id), f.type, f.action, statusOf(f)]));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function setMark(traceValue, opts, mark) {
|
|
62
|
+
const trace = resolveTraceId(traceValue);
|
|
63
|
+
const finding = chooseFinding(await fetchFindings(trace), mark, opts.finding);
|
|
64
|
+
const verb = mark ? 'Mark' : 'Unmark';
|
|
65
|
+
if (!opts.yes && !(await confirm(`${verb} ${finding.type} finding ${finding.id} on trace ${trace} as a false positive?`))) {
|
|
66
|
+
output.info('Cancelled.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const data = await api.post(PATH, {
|
|
70
|
+
body: { trace_id: trace, guardrail_action_id: finding.id, is_false_positive: mark },
|
|
71
|
+
});
|
|
72
|
+
if (opts.json) {
|
|
73
|
+
output.json(data);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
output.success(`${data.message}: ${finding.type} finding ${finding.id}.`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function register(program) {
|
|
80
|
+
const fp = program
|
|
81
|
+
.command('false-positive')
|
|
82
|
+
.alias('fp')
|
|
83
|
+
.description('Mark or unmark a data security finding of yours as a false positive, by trace ID.');
|
|
84
|
+
|
|
85
|
+
fp
|
|
86
|
+
.command('list <trace-id>')
|
|
87
|
+
.description('Show your findings on a trace ID.')
|
|
88
|
+
.option('--json', 'Output JSON')
|
|
89
|
+
.addHelpText('after', `
|
|
90
|
+
The trace ID is the UUID shown under "Enforced by Unbound" on a blocked request.
|
|
91
|
+
Only findings on your own requests are listed. Detected values are never shown.
|
|
92
|
+
|
|
93
|
+
Examples:
|
|
94
|
+
$ unbound false-positive list 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
|
|
95
|
+
`)
|
|
96
|
+
.action((trace, opts) => run(() => list(trace, opts)));
|
|
97
|
+
|
|
98
|
+
fp
|
|
99
|
+
.command('mark <trace-id>')
|
|
100
|
+
.description('Mark one of your findings on a trace ID as a false positive.')
|
|
101
|
+
.option('--finding <id>', 'Finding ID, when the trace has more than one (see "list")')
|
|
102
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
103
|
+
.option('--json', 'Output the JSON response')
|
|
104
|
+
.addHelpText('after', `
|
|
105
|
+
You can only mark findings on your own requests. Admins can use this command on
|
|
106
|
+
any finding in their organization, or work by action ID with
|
|
107
|
+
\`unbound flags data-security mark-fp\`.
|
|
108
|
+
|
|
109
|
+
Examples:
|
|
110
|
+
$ unbound false-positive mark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
|
|
111
|
+
$ unbound false-positive mark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c --finding 5521 --yes
|
|
112
|
+
`)
|
|
113
|
+
.action((trace, opts) => run(() => setMark(trace, opts, true)));
|
|
114
|
+
|
|
115
|
+
fp
|
|
116
|
+
.command('unmark <trace-id>')
|
|
117
|
+
.description('Unmark a false positive you marked.')
|
|
118
|
+
.option('--finding <id>', 'Finding ID, when the trace has more than one (see "list")')
|
|
119
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
120
|
+
.option('--json', 'Output the JSON response')
|
|
121
|
+
.addHelpText('after', `
|
|
122
|
+
You can unmark only a mark you made. Admins can unmark any.
|
|
123
|
+
|
|
124
|
+
Examples:
|
|
125
|
+
$ unbound false-positive unmark 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
|
|
126
|
+
`)
|
|
127
|
+
.action((trace, opts) => run(() => setMark(trace, opts, false)));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = { register, chooseFinding };
|
package/src/commands/flags.js
CHANGED
|
@@ -113,19 +113,16 @@ async function listDataSecurity(opts) {
|
|
|
113
113
|
const data = await api.get(`${DATA_SECURITY_PATH}?${buildQueryString(query)}`);
|
|
114
114
|
const logs = (data.logs && data.logs.data) || [];
|
|
115
115
|
if (opts.json) {
|
|
116
|
-
|
|
117
|
-
output.json(payload);
|
|
116
|
+
output.json({ ...data, logs: { ...data.logs, data: logs.map(redactDataSecurityLog) } });
|
|
118
117
|
return;
|
|
119
118
|
}
|
|
120
119
|
if (logs.length === 0) {
|
|
121
120
|
output.info('No data security flags for this window and filter set.');
|
|
122
121
|
return;
|
|
123
122
|
}
|
|
124
|
-
output.logTable(DATA_SECURITY_HEADERS, dataSecurityRows(logs, {
|
|
125
|
-
{ wide: Boolean(opts.wide) });
|
|
123
|
+
output.logTable(DATA_SECURITY_HEADERS, dataSecurityRows(logs), { wide: Boolean(opts.wide) });
|
|
126
124
|
const totalPages = data.logs.total_pages;
|
|
127
125
|
pageFooter(query.page, totalPages, data.logs.total_items, 'flagged requests', query.page < (totalPages || 0));
|
|
128
|
-
if (!opts.reveal) output.info('Detected values are masked. Use --reveal to show them.');
|
|
129
126
|
output.info('Mark one as a false positive: unbound flags data-security mark-fp <Action ID>');
|
|
130
127
|
}
|
|
131
128
|
|
|
@@ -207,26 +204,28 @@ Admin only.
|
|
|
207
204
|
|
|
208
205
|
const dataSecurity = flags
|
|
209
206
|
.command('data-security')
|
|
210
|
-
.description('List
|
|
207
|
+
.description('List requests where a data security guardrail found PII or a secret, without the values (Analytics > Data).')
|
|
211
208
|
.option('--guardrail <names>', 'Guardrail names or IDs, comma-separated, e.g. PII,Secrets')
|
|
212
209
|
.option('--action <actions>', `Action taken, comma-separated: ${DATA_SECURITY_ACTIONS.join(', ')}`)
|
|
213
210
|
.option('--findings <which>', `${Object.keys(FINDINGS).join(' | ')} (default real)`)
|
|
214
211
|
.option('--trace <trace-id>', 'Only the request with this gateway trace ID (default --findings all)')
|
|
215
|
-
.option('--reveal', 'Show detected values and prompts in clear text')
|
|
216
212
|
.option('--page <n>', 'Page number (10 requests per page)')
|
|
217
|
-
.option('--json', 'Output the JSON response (values
|
|
213
|
+
.option('--json', 'Output the JSON response (without detected values or prompts)')
|
|
218
214
|
.option('--wide', 'Print full values instead of clipping to terminal width');
|
|
219
215
|
addWindowOptions(dataSecurity)
|
|
220
216
|
.addHelpText('after', `
|
|
221
217
|
Columns:
|
|
222
218
|
Action ID The detection's ID. Pass it to \`mark-fp\`.
|
|
223
|
-
|
|
219
|
+
Type The kind of data found, e.g. EMAIL_ADDRESS or AWS key.
|
|
220
|
+
|
|
221
|
+
The detected values and the prompts are never shown here. See them in the
|
|
222
|
+
console under Analytics > Data.
|
|
224
223
|
${WINDOW_HELP}
|
|
225
224
|
Examples:
|
|
226
225
|
$ unbound flags data-security
|
|
227
226
|
$ unbound flags data-security --guardrail Secrets --action block
|
|
228
227
|
$ unbound flags data-security --findings false-positive
|
|
229
|
-
$ unbound flags data-security --trace 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
|
|
228
|
+
$ unbound flags data-security --trace 3f2a6c1e-8b7d-4e2f-9a1c-5d6e7f8a9b0c
|
|
230
229
|
|
|
231
230
|
Admin, Manager or Analytics Viewer.
|
|
232
231
|
`)
|
|
@@ -243,7 +242,8 @@ same value for everyone in your organization.
|
|
|
243
242
|
Examples:
|
|
244
243
|
$ unbound flags data-security mark-fp 5521
|
|
245
244
|
|
|
246
|
-
Admin only.
|
|
245
|
+
Admin only. To mark a finding of your own without a role, use
|
|
246
|
+
\`unbound false-positive mark <trace-id>\`.
|
|
247
247
|
`)
|
|
248
248
|
.action((id, opts) => run(() => markDataSecurityFalsePositive(id, opts)));
|
|
249
249
|
|
package/src/commands/trace.js
CHANGED
|
@@ -32,7 +32,7 @@ const SOURCES = [
|
|
|
32
32
|
rows: (data, trace) => (data.prompts || []).filter((p) => sameTrace(p.traceId, trace)),
|
|
33
33
|
more: (data, page) => page < (data.total_pages || 0),
|
|
34
34
|
headers: LOG_HEADERS,
|
|
35
|
-
toTable: (rows
|
|
35
|
+
toTable: (rows) => logRows(rows),
|
|
36
36
|
redact: (rows) => rows.map(redactLog),
|
|
37
37
|
},
|
|
38
38
|
{
|
|
@@ -52,7 +52,7 @@ const SOURCES = [
|
|
|
52
52
|
rows: (data, trace) => ((data.logs && data.logs.data) || []).filter((l) => sameTrace(l.trace_id, trace)),
|
|
53
53
|
more: (data, page) => page < ((data.logs && data.logs.total_pages) || 0),
|
|
54
54
|
headers: DATA_SECURITY_HEADERS,
|
|
55
|
-
toTable: (rows
|
|
55
|
+
toTable: (rows) => dataSecurityRows(rows),
|
|
56
56
|
redact: (rows) => rows.map(redactDataSecurityLog),
|
|
57
57
|
},
|
|
58
58
|
];
|
|
@@ -77,13 +77,13 @@ async function lookup(trace) {
|
|
|
77
77
|
}));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function printJson(trace, results
|
|
80
|
+
function printJson(trace, results) {
|
|
81
81
|
const payload = { trace_id: trace };
|
|
82
82
|
for (const { source, rows, error, incomplete } of results) {
|
|
83
83
|
if (error) {
|
|
84
84
|
payload[source.key] = { error };
|
|
85
85
|
} else {
|
|
86
|
-
payload[source.key] = { rows: source.redact
|
|
86
|
+
payload[source.key] = { rows: source.redact ? source.redact(rows) : rows };
|
|
87
87
|
if (incomplete) payload[source.key].incomplete = true;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -103,10 +103,8 @@ function printTables(trace, results, opts) {
|
|
|
103
103
|
}
|
|
104
104
|
if (incomplete) output.warn(`${source.title}: more than ${MAX_PAGES} pages matched. Only the first ${MAX_PAGES} are shown.`);
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
output.info('Prompts and detected values are hidden. Use --reveal to show them.');
|
|
109
|
-
}
|
|
106
|
+
console.log('');
|
|
107
|
+
output.info('Prompts and detected values are not shown in the CLI. See them in the console.');
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
async function runTrace(value, opts) {
|
|
@@ -115,7 +113,7 @@ async function runTrace(value, opts) {
|
|
|
115
113
|
const trace = resolveTraceId(value);
|
|
116
114
|
const results = await lookup(trace);
|
|
117
115
|
if (opts.json) {
|
|
118
|
-
printJson(trace, results
|
|
116
|
+
printJson(trace, results);
|
|
119
117
|
} else {
|
|
120
118
|
printTables(trace, results, opts);
|
|
121
119
|
}
|
|
@@ -132,17 +130,17 @@ function register(program) {
|
|
|
132
130
|
.command('trace <trace-id>')
|
|
133
131
|
.description('Find everything recorded for one gateway trace ID: the log, terminal runs and data security flags.')
|
|
134
132
|
.option('--json', 'Output one JSON object with a key per source')
|
|
135
|
-
.option('--reveal', 'Show prompts and detected data security values in clear text')
|
|
136
133
|
.option('--wide', 'Print full values instead of clipping to terminal width')
|
|
137
134
|
.addHelpText('after', `
|
|
138
135
|
The trace ID is the UUID shown to a user under a blocked or warned action.
|
|
139
136
|
|
|
140
137
|
Sources:
|
|
141
|
-
Logs The request
|
|
138
|
+
Logs The request (any age)
|
|
142
139
|
Terminal Runs Tool calls on the request, flagged or not (last 3 months)
|
|
143
|
-
Data Security PII or secret detections on the request (last 3 months)
|
|
140
|
+
Data Security PII or secret detections on the request, without the values (last 3 months)
|
|
144
141
|
|
|
145
|
-
Prompts and detected values are
|
|
142
|
+
Prompts and detected data security values are never shown. See them in the
|
|
143
|
+
console.
|
|
146
144
|
|
|
147
145
|
The exit code is 1 when a source cannot be read, for example because your
|
|
148
146
|
role cannot see it, or when a source has more than ${MAX_PAGES} pages. The
|
package/src/index.js
CHANGED
|
@@ -178,11 +178,16 @@ FLAGS AND FALSE POSITIVES (Admin/Analytics Viewer/Manager; mark-fp is Admin only
|
|
|
178
178
|
$ unbound flags terminal Terminal runs a tool policy flagged
|
|
179
179
|
$ unbound flags terminal mark-fp <id> --risk-score <n>
|
|
180
180
|
Mark a flagged run as a false positive
|
|
181
|
-
$ unbound flags data-security PII and secrets a guardrail found (values
|
|
181
|
+
$ unbound flags data-security PII and secrets a guardrail found (values never shown)
|
|
182
182
|
$ unbound flags data-security mark-fp <action-id>
|
|
183
183
|
Mark a detection as a false positive
|
|
184
184
|
$ unbound trace <trace-id> Log, terminal runs and data security for one trace ID
|
|
185
185
|
|
|
186
|
+
FALSE POSITIVES ON YOUR OWN REQUESTS (any user)
|
|
187
|
+
$ unbound false-positive list <trace-id> Your findings on a blocked request
|
|
188
|
+
$ unbound false-positive mark <trace-id> Mark one as a false positive
|
|
189
|
+
$ unbound false-positive unmark <trace-id> Undo a mark you made
|
|
190
|
+
|
|
186
191
|
CHAT (Admin/Analytics Viewer/Manager)
|
|
187
192
|
$ unbound chat Interactive REPL (multi-turn, in-memory history)
|
|
188
193
|
$ unbound chat -m "show cost by provider for the last 30 days"
|
|
@@ -228,6 +233,7 @@ require('./commands/tools').register(program);
|
|
|
228
233
|
require('./commands/analytics').register(program);
|
|
229
234
|
require('./commands/flags').register(program);
|
|
230
235
|
require('./commands/trace').register(program);
|
|
236
|
+
require('./commands/false-positive').register(program);
|
|
231
237
|
require('./commands/download').register(program);
|
|
232
238
|
require('./commands/setup').register(program);
|
|
233
239
|
require('./commands/discover').register(program);
|
package/src/lib/flags.js
CHANGED
|
@@ -98,24 +98,12 @@ function resolveGuardrailIds(raw, available) {
|
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
/**
|
|
102
|
-
function maskValue(value) {
|
|
103
|
-
const text = String(value ?? '');
|
|
104
|
-
if (!text) return '';
|
|
105
|
-
if (text.length < 10) return '****';
|
|
106
|
-
return `${text.slice(0, 2)}****${text.slice(-2)}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** A data security log with every detected value masked and the raw prompt removed. */
|
|
101
|
+
/** A data security log without its detected values or prompt text; the CLI never prints either, masked or not. */
|
|
110
102
|
function redactDataSecurityLog(log) {
|
|
111
|
-
const { prompt, sensitive_contents: contents, ...rest } = log;
|
|
103
|
+
const { prompt, sensitive_contents: contents, prompt_mask_values: maskValues, ...rest } = log;
|
|
112
104
|
return {
|
|
113
105
|
...rest,
|
|
114
|
-
|
|
115
|
-
sensitive_content_details: (log.sensitive_content_details || []).map((d) => ({
|
|
116
|
-
...d,
|
|
117
|
-
sensitive_content: maskValue(d.sensitive_content),
|
|
118
|
-
})),
|
|
106
|
+
sensitive_content_details: (log.sensitive_content_details || []).map(({ sensitive_content: value, ...d }) => d),
|
|
119
107
|
};
|
|
120
108
|
}
|
|
121
109
|
|
|
@@ -161,42 +149,41 @@ function terminalRows(rows, { wide = false } = {}) {
|
|
|
161
149
|
]);
|
|
162
150
|
}
|
|
163
151
|
|
|
164
|
-
const DATA_SECURITY_HEADERS = ['Action ID', 'Time (UTC)', 'User', 'AI Tool', 'Guardrail', '
|
|
152
|
+
const DATA_SECURITY_HEADERS = ['Action ID', 'Time (UTC)', 'User', 'AI Tool', 'Guardrail', 'Type', 'Action', 'False Positive', 'Trace ID'];
|
|
165
153
|
|
|
166
|
-
/** One row per detection, because mark-fp takes a detection's action ID. */
|
|
167
|
-
function dataSecurityRows(logs
|
|
154
|
+
/** One row per detection, because mark-fp takes a detection's action ID; the detected value is never shown. */
|
|
155
|
+
function dataSecurityRows(logs) {
|
|
168
156
|
const rows = [];
|
|
169
157
|
for (const log of logs || []) {
|
|
170
158
|
const base = [shortTime(log.timestamp), log.user_email || log.user_name || '', log.application_name || ''];
|
|
171
159
|
const details = log.sensitive_content_details || [];
|
|
172
160
|
if (details.length === 0) {
|
|
173
161
|
// Detections with no stored value carry no action ID in the response.
|
|
174
|
-
rows.push(['-', ...base, (log.guardrails || []).join(', '), (log.guardrail_actions || []).join(', '),
|
|
175
|
-
|
|
162
|
+
rows.push(['-', ...base, (log.guardrails || []).join(', '), '', (log.guardrail_actions || []).join(', '),
|
|
163
|
+
log.has_false_positive ? 'yes' : '', log.trace_id || '']);
|
|
176
164
|
continue;
|
|
177
165
|
}
|
|
178
166
|
for (const d of details) {
|
|
179
|
-
rows.push([String(d.action_id), ...base, d.guardrail_name || d.entity_type || '', d.action || '',
|
|
180
|
-
reveal ? clipText(d.sensitive_content, 40, wide) : maskValue(d.sensitive_content),
|
|
167
|
+
rows.push([String(d.action_id), ...base, d.guardrail_name || '', d.entity_type || '', d.action || '',
|
|
181
168
|
d.is_false_positive ? 'yes' : '', log.trace_id || '']);
|
|
182
169
|
}
|
|
183
170
|
}
|
|
184
171
|
return rows;
|
|
185
172
|
}
|
|
186
173
|
|
|
187
|
-
// Prompt text on a log can hold
|
|
174
|
+
// Prompt text on a log can hold a secret or PII the user pasted.
|
|
188
175
|
const LOG_TEXT_FIELDS = ['userPrompt', 'systemPrompt', 'assistantPrompt', 'cleanedPrompt'];
|
|
189
176
|
|
|
190
|
-
/** A log with its prompt text removed. */
|
|
177
|
+
/** A log with its prompt text removed; the CLI never prints prompts, which can hold a secret the user pasted. */
|
|
191
178
|
function redactLog(log) {
|
|
192
179
|
const copy = { ...log };
|
|
193
180
|
for (const field of LOG_TEXT_FIELDS) delete copy[field];
|
|
194
181
|
return copy;
|
|
195
182
|
}
|
|
196
183
|
|
|
197
|
-
const LOG_HEADERS = ['Log ID', 'Time (UTC)', 'User', 'AI Tool', 'Model', 'Status'
|
|
184
|
+
const LOG_HEADERS = ['Log ID', 'Time (UTC)', 'User', 'AI Tool', 'Model', 'Status'];
|
|
198
185
|
|
|
199
|
-
function logRows(prompts
|
|
186
|
+
function logRows(prompts) {
|
|
200
187
|
return (prompts || []).map((p) => [
|
|
201
188
|
p.urlKey || p.id || '',
|
|
202
189
|
shortTime(p.requestInitializedAt),
|
|
@@ -204,7 +191,6 @@ function logRows(prompts, { reveal = false, wide = false } = {}) {
|
|
|
204
191
|
p.toolType || '',
|
|
205
192
|
(p.aiModel && p.aiModel.name) || '',
|
|
206
193
|
p.statusCode ?? '',
|
|
207
|
-
reveal ? clipText(p.userPrompt || '', 60, wide) : '(hidden)',
|
|
208
194
|
]);
|
|
209
195
|
}
|
|
210
196
|
|
|
@@ -220,7 +206,6 @@ module.exports = {
|
|
|
220
206
|
dataSecurityRows,
|
|
221
207
|
feedbackLabel,
|
|
222
208
|
logRows,
|
|
223
|
-
maskValue,
|
|
224
209
|
redactDataSecurityLog,
|
|
225
210
|
redactLog,
|
|
226
211
|
resolveGuardrailIds,
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const http = require('http');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const { chooseFinding } = require('../src/commands/false-positive');
|
|
10
|
+
|
|
11
|
+
const TRACE = '225c6413-26e4-4cd2-85a6-8c5ccfc3c5ef';
|
|
12
|
+
const PATH = '/api/v1/analytics/guardrails/my_false_positive/';
|
|
13
|
+
const flagged = { id: 11, type: 'API Key', action: 'BLOCK', is_false_positive: false, markable: true, unmarkable: false };
|
|
14
|
+
const marked = { id: 12, type: 'PII', action: 'AUDIT', is_false_positive: true, markable: false, unmarkable: true };
|
|
15
|
+
|
|
16
|
+
test('mark picks the only unmarked finding and unmark the only marked one', () => {
|
|
17
|
+
assert.equal(chooseFinding([flagged, marked], true).id, 11);
|
|
18
|
+
assert.equal(chooseFinding([flagged, marked], false).id, 12);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('--finding picks that finding and refuses one that is not on the list', () => {
|
|
22
|
+
assert.equal(chooseFinding([flagged, marked], true, '12').id, 12);
|
|
23
|
+
assert.throws(() => chooseFinding([flagged], true, '99'), /not one of your findings/);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('several candidates need --finding, and none is an error', () => {
|
|
27
|
+
const other = { ...flagged, id: 13 };
|
|
28
|
+
assert.throws(() => chooseFinding([flagged, other], true), /Pass --finding/);
|
|
29
|
+
assert.throws(() => chooseFinding([marked], true), /left to mark/);
|
|
30
|
+
assert.throws(() => chooseFinding([flagged], false), /can be unmarked/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function startServer(routes) {
|
|
34
|
+
const seen = [];
|
|
35
|
+
const server = http.createServer((req, res) => {
|
|
36
|
+
let body = '';
|
|
37
|
+
req.on('data', (c) => { body += c; });
|
|
38
|
+
req.on('end', () => {
|
|
39
|
+
const url = new URL(req.url, 'http://x');
|
|
40
|
+
seen.push({ method: req.method, path: url.pathname, query: url.searchParams, body: body ? JSON.parse(body) : null });
|
|
41
|
+
const [status, payload] = routes(req.method) || [404, { error: 'no route' }];
|
|
42
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
43
|
+
res.end(JSON.stringify(payload));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve({ server, seen, port: server.address().port })));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function runCli(port, args) {
|
|
50
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'fp-test-'));
|
|
51
|
+
fs.mkdirSync(path.join(home, '.unbound'));
|
|
52
|
+
fs.writeFileSync(path.join(home, '.unbound', 'config.json'),
|
|
53
|
+
JSON.stringify({ api_key: 'test-key', base_url: `http://127.0.0.1:${port}` }));
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const child = spawn('node', [path.join(__dirname, '..', 'src', 'index.js'), ...args], {
|
|
56
|
+
env: { ...process.env, HOME: home, UNBOUND_TOKEN: 'test-key', UNBOUND_API_URL: '', UNBOUND_TELEMETRY: '0', UNBOUND_NO_UPDATE_CHECK: '1' },
|
|
57
|
+
});
|
|
58
|
+
let stdout = '';
|
|
59
|
+
let stderr = '';
|
|
60
|
+
child.stdout.on('data', (d) => { stdout += d; });
|
|
61
|
+
child.stderr.on('data', (d) => { stderr += d; });
|
|
62
|
+
child.on('close', (code) => {
|
|
63
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
64
|
+
resolve({ code, stdout, stderr });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test('mark looks the trace up, then posts the chosen finding', async () => {
|
|
70
|
+
const { server, seen, port } = await startServer((method) =>
|
|
71
|
+
(method === 'GET' ? [200, { findings: [flagged] }] : [200, { message: 'False positive marked' }]));
|
|
72
|
+
try {
|
|
73
|
+
const r = await runCli(port, ['false-positive', 'mark', TRACE.toUpperCase(), '--yes']);
|
|
74
|
+
assert.equal(r.code, 0, r.stderr);
|
|
75
|
+
assert.equal(seen[0].path, PATH);
|
|
76
|
+
assert.equal(seen[0].query.get('trace_id'), TRACE);
|
|
77
|
+
assert.deepEqual(seen[1].body, { trace_id: TRACE, guardrail_action_id: 11, is_false_positive: true });
|
|
78
|
+
assert.match(r.stdout + r.stderr, /False positive marked/);
|
|
79
|
+
} finally {
|
|
80
|
+
server.close();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('unmark posts is_false_positive false', async () => {
|
|
85
|
+
const { server, seen, port } = await startServer((method) =>
|
|
86
|
+
(method === 'GET' ? [200, { findings: [marked] }] : [200, { message: 'False positive unmarked' }]));
|
|
87
|
+
try {
|
|
88
|
+
const r = await runCli(port, ['fp', 'unmark', TRACE, '-y']);
|
|
89
|
+
assert.equal(r.code, 0, r.stderr);
|
|
90
|
+
assert.deepEqual(seen[1].body, { trace_id: TRACE, guardrail_action_id: 12, is_false_positive: false });
|
|
91
|
+
} finally {
|
|
92
|
+
server.close();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('a trace with none of your findings posts nothing and exits 1', async () => {
|
|
97
|
+
const { server, seen, port } = await startServer(() => [200, { findings: [] }]);
|
|
98
|
+
try {
|
|
99
|
+
const r = await runCli(port, ['false-positive', 'mark', TRACE, '--yes']);
|
|
100
|
+
assert.equal(r.code, 1);
|
|
101
|
+
assert.equal(seen.filter((s) => s.method === 'POST').length, 0);
|
|
102
|
+
} finally {
|
|
103
|
+
server.close();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('an invalid trace ID never reaches the backend', async () => {
|
|
108
|
+
const { server, seen, port } = await startServer(() => [200, { findings: [] }]);
|
|
109
|
+
try {
|
|
110
|
+
const r = await runCli(port, ['false-positive', 'list', 'not-a-uuid']);
|
|
111
|
+
assert.equal(r.code, 1);
|
|
112
|
+
assert.equal(seen.length, 0);
|
|
113
|
+
} finally {
|
|
114
|
+
server.close();
|
|
115
|
+
}
|
|
116
|
+
});
|
package/test/flags.test.js
CHANGED
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
buildDataSecurityQuery,
|
|
11
11
|
buildTerminalQuery,
|
|
12
12
|
dataSecurityRows,
|
|
13
|
-
maskValue,
|
|
14
13
|
redactDataSecurityLog,
|
|
15
14
|
resolveGuardrailIds,
|
|
16
15
|
resolveTraceId,
|
|
@@ -56,12 +55,6 @@ test('guardrail names resolve to IDs case-insensitively, and an unknown name lis
|
|
|
56
55
|
assert.throws(() => resolveGuardrailIds('nope', available), /Available: PII, Secrets/);
|
|
57
56
|
});
|
|
58
57
|
|
|
59
|
-
test('maskValue keeps only the ends of a long value', () => {
|
|
60
|
-
assert.equal(maskValue('AKIAE2ETESTKEY0000001'), 'AK****01');
|
|
61
|
-
assert.equal(maskValue('short'), '****');
|
|
62
|
-
assert.equal(maskValue(''), '');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
58
|
const LOG = {
|
|
66
59
|
id: 7,
|
|
67
60
|
trace_id: TRACE,
|
|
@@ -77,18 +70,37 @@ const LOG = {
|
|
|
77
70
|
prompt: { user_prompt: 'my key is AKIAE2ETESTKEY0000001' },
|
|
78
71
|
};
|
|
79
72
|
|
|
80
|
-
test('redacted data security JSON carries no detected value and no prompt', () => {
|
|
81
|
-
const
|
|
82
|
-
assert.ok(!
|
|
83
|
-
assert.ok(!(
|
|
73
|
+
test('redacted data security JSON carries no detected value, masked or not, and no prompt', () => {
|
|
74
|
+
const redacted = redactDataSecurityLog({ ...LOG, prompt_mask_values: ['AKIAE2ETESTKEY0000001'] });
|
|
75
|
+
assert.ok(!JSON.stringify(redacted).includes('AKIA'), JSON.stringify(redacted));
|
|
76
|
+
for (const key of ['prompt', 'sensitive_contents', 'prompt_mask_values']) assert.ok(!(key in redacted), key);
|
|
77
|
+
assert.ok(!('sensitive_content' in redacted.sensitive_content_details[0]));
|
|
78
|
+
assert.equal(redacted.sensitive_content_details[0].action_id, 1);
|
|
84
79
|
});
|
|
85
80
|
|
|
86
|
-
test('data security rows list one line per detection,
|
|
81
|
+
test('data security rows list one line per detection, with no value column', () => {
|
|
87
82
|
const [row] = dataSecurityRows([LOG]);
|
|
88
83
|
assert.equal(row[0], '1');
|
|
89
84
|
assert.equal(row[1], '2026-09-24 19:17');
|
|
90
|
-
assert.equal(row
|
|
91
|
-
assert.
|
|
85
|
+
assert.equal(row.length, 9);
|
|
86
|
+
assert.ok(!row.join(' ').includes('AKIA'), row.join(' '));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('flags data-security prints no detected value in the table or JSON, and has no --reveal', async () => {
|
|
90
|
+
const { server, port } = await startServer((method, url) =>
|
|
91
|
+
(url.pathname === '/api/v1/analytics/guardrails/' ? [200, { logs: { data: [LOG], total_pages: 1 } }] : null));
|
|
92
|
+
try {
|
|
93
|
+
for (const args of [['flags', 'data-security'], ['flags', 'data-security', '--json']]) {
|
|
94
|
+
const r = await runCli(port, args);
|
|
95
|
+
assert.equal(r.code, 0, r.stderr);
|
|
96
|
+
assert.ok(!r.stdout.includes('AKIA'), r.stdout);
|
|
97
|
+
}
|
|
98
|
+
const reveal = await runCli(port, ['flags', 'data-security', '--reveal']);
|
|
99
|
+
assert.notEqual(reveal.code, 0);
|
|
100
|
+
assert.ok(!reveal.stdout.includes('AKIA'), reveal.stdout);
|
|
101
|
+
} finally {
|
|
102
|
+
server.close();
|
|
103
|
+
}
|
|
92
104
|
});
|
|
93
105
|
|
|
94
106
|
test('terminal rows show policies with their action and the feedback as a label', () => {
|
|
@@ -178,7 +190,7 @@ test('flags data-security mark-fp posts the detection ID', async () => {
|
|
|
178
190
|
}
|
|
179
191
|
});
|
|
180
192
|
|
|
181
|
-
test('trace keeps only exact log matches,
|
|
193
|
+
test('trace keeps only exact log matches, never prints a data security value, and exits 1 when a source fails', async () => {
|
|
182
194
|
const { server, port } = await startServer((method, url) => {
|
|
183
195
|
if (url.pathname === '/api/v1/logs/prompts/') {
|
|
184
196
|
return [200, { prompts: [
|
|
@@ -201,13 +213,18 @@ test('trace keeps only exact log matches, masks values, and exits 1 when a sourc
|
|
|
201
213
|
assert.deepEqual(out.logs.rows.map((p) => p.id), ['1']);
|
|
202
214
|
assert.equal(out.terminal_runs.error, 'Manager or admin access required');
|
|
203
215
|
assert.equal(out.data_security.rows.length, 1);
|
|
204
|
-
assert.ok(!r.stdout.includes('
|
|
216
|
+
assert.ok(!r.stdout.includes('AKIA'), 'no value, masked or not, without --reveal');
|
|
217
|
+
// The log's prompt can hold the secret the guardrail found, so it is never printed either.
|
|
218
|
+
assert.ok(!('userPrompt' in out.logs.rows[0]));
|
|
219
|
+
const revealed = await runCli(port, ['trace', TRACE, '--json', '--reveal']);
|
|
220
|
+
assert.notEqual(revealed.code, 0);
|
|
221
|
+
assert.ok(!revealed.stdout.includes('AKIA'), revealed.stdout);
|
|
205
222
|
} finally {
|
|
206
223
|
server.close();
|
|
207
224
|
}
|
|
208
225
|
});
|
|
209
226
|
|
|
210
|
-
test('trace reads every page of a source and
|
|
227
|
+
test('trace reads every page of a source and never prints log prompts', async () => {
|
|
211
228
|
const { server, seen, port } = await startServer((method, url) => {
|
|
212
229
|
const page = url.searchParams.get('page');
|
|
213
230
|
if (url.pathname === '/api/v1/logs/prompts/') {
|
|
@@ -228,8 +245,8 @@ test('trace reads every page of a source and hides log prompts in the table', as
|
|
|
228
245
|
['1', '2']);
|
|
229
246
|
const table = await runCli(port, ['trace', TRACE]);
|
|
230
247
|
assert.ok(!table.stdout.includes('AKIAE2ETESTKEY0000001'), table.stdout);
|
|
231
|
-
const
|
|
232
|
-
assert.ok(
|
|
248
|
+
const wide = await runCli(port, ['trace', TRACE, '--wide']);
|
|
249
|
+
assert.ok(!wide.stdout.includes('AKIAE2ETESTKEY0000001'), wide.stdout);
|
|
233
250
|
} finally {
|
|
234
251
|
server.close();
|
|
235
252
|
}
|