@knowttl/tenable-axi 0.1.6 → 0.1.7

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 CHANGED
@@ -71,6 +71,7 @@ The [generated command reference](https://github.com/knowttl/tenable-axi/blob/ma
71
71
  | `tag category/value/assignment/exclusion/asset-filter` | Inspect and manage platform tags | Read/write | [Platform tags](https://github.com/knowttl/tenable-axi/blob/main/docs/behavior.md#platform-tags) |
72
72
  | `initiative`, `combination` | Manage Exposure Response workflows | Read/write | [Exposure Response](https://github.com/knowttl/tenable-axi/blob/main/docs/behavior.md#exposure-response) |
73
73
  | `export` | Create jobs, check status and download results | Read/write | [Exports](https://github.com/knowttl/tenable-axi/blob/main/docs/behavior.md#inventory-exports) |
74
+ | `raw` | Read API paths and send guarded writes | Read/write | [Raw API](https://github.com/knowttl/tenable-axi/blob/main/docs/behavior.md#raw-api) |
74
75
  | `auth`, `profile`, `config`, `doctor` | Inspect setup and module access | Local/read | [Doctor](https://github.com/knowttl/tenable-axi/blob/main/docs/commands.md#doctor) |
75
76
  | `setup hooks`, `hook` | Install integrations and read local context | Local | [Integration](https://github.com/knowttl/tenable-axi/blob/main/docs/agent-integration.md) |
76
77
 
@@ -83,7 +84,7 @@ Preview first, then pass `--execute --confirm '<exact preview confirmation>'` to
83
84
  There is no `TENABLE_AXI_ALLOW_*` environment gate; configured operation allowlists control scope.
84
85
  A durable redacted journal records intent before sending; reconcile unknown outcomes before retrying.
85
86
  Credentials use environment/file SecretRefs, never inline secrets or arguments.
86
- Credential minting, users, roles, access-control administration and arbitrary HTTP stay blocked.
87
+ Credential minting, users, roles and access-control administration stay blocked; raw HTTP is limited to validated paths on the exact origin.
87
88
  See [write safety](https://github.com/knowttl/tenable-axi/blob/main/docs/safety.md) and the [permission ledger](https://github.com/knowttl/tenable-axi/blob/main/docs/design.md#complete-operation-ledger).
88
89
 
89
90
  ## Configuration
@@ -111,7 +112,7 @@ See [configuration](https://github.com/knowttl/tenable-axi/blob/main/docs/config
111
112
 
112
113
  ## Output and exit codes
113
114
 
114
- Stdout uses compact TOON; bare `--version`, `-v` and `-V` print the package version.
115
+ Stdout uses compact TOON except for successful raw responses; bare `--version`, `-v` and `-V` print the package version.
115
116
  `--fields` selects properties and `--full` removes text truncation without expanding row or transport bounds.
116
117
  Ordinary lists default to 100 rows; `--all` remains bounded at 10,000.
117
118
  Resume a returned `--cursor` with the same profile, filters, fields and sort.
@@ -21,11 +21,11 @@ export declare const techniqueProperties: readonly ["priority", "state", "status
21
21
  export declare function attackFilterSchema(technique: boolean): z.ZodUnion<readonly [z.ZodObject<{
22
22
  property: z.ZodEnum<{
23
23
  status: "status";
24
+ target: "target";
24
25
  name: "name";
25
26
  priority: "priority";
26
27
  summary: "summary";
27
28
  path_status: "path_status";
28
- target: "target";
29
29
  serial_id: "serial_id";
30
30
  mitre_id: "mitre_id";
31
31
  state: "state";
@@ -72,11 +72,11 @@ export declare function attackFilterSchema(technique: boolean): z.ZodUnion<reado
72
72
  value: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
73
73
  property: z.ZodEnum<{
74
74
  status: "status";
75
+ target: "target";
75
76
  name: "name";
76
77
  priority: "priority";
77
78
  summary: "summary";
78
79
  path_status: "path_status";
79
- target: "target";
80
80
  serial_id: "serial_id";
81
81
  mitre_id: "mitre_id";
82
82
  state: "state";
@@ -123,11 +123,11 @@ export declare function attackFilterSchema(technique: boolean): z.ZodUnion<reado
123
123
  value: z.ZodArray<z.ZodObject<{
124
124
  property: z.ZodEnum<{
125
125
  status: "status";
126
+ target: "target";
126
127
  name: "name";
127
128
  priority: "priority";
128
129
  summary: "summary";
129
130
  path_status: "path_status";
130
- target: "target";
131
131
  serial_id: "serial_id";
132
132
  mitre_id: "mitre_id";
133
133
  state: "state";
@@ -2,6 +2,9 @@ import type { OperationBinding } from "./transport-core.js";
2
2
  import type { MutationOperation } from "./writes-core.js";
3
3
  export declare const DESCRIPTION = "Investigate Tenable One exposure and run explicitly guarded writes";
4
4
  export declare const SETUP_GUIDANCE = "Run tenable-axi config path; configure a profile with accessKey and secretKey SecretRefs";
5
+ export declare const capabilities: {
6
+ readonly rawWrites: true;
7
+ };
5
8
  export declare const transportBindings: Readonly<Record<string, OperationBinding>>;
6
9
  export declare const mutationOperations: Readonly<Record<string, MutationOperation>>;
7
10
  export declare const catalogue: {
@@ -94,6 +97,35 @@ export declare const catalogue: {
94
97
  };
95
98
  examples: string[];
96
99
  };
100
+ readonly "raw get": {
101
+ readonly description: "Read any Tenable API path on the exact origin with the selected profile keys";
102
+ readonly flags: {
103
+ readonly config: "Config path; default platform path";
104
+ readonly profile: "Profile name; default credential precedence";
105
+ readonly path: "Required absolute API path such as /api/v1/t1/tags/properties";
106
+ readonly query: "URL query such as limit=10&offset=0";
107
+ readonly out: "Save response bytes to a new file";
108
+ readonly help: "Show help; default false";
109
+ };
110
+ readonly examples: readonly ["tenable-axi raw get --path /api/v1/t1/tags/properties", "tenable-axi raw get --path /api/v1/t1/tags/search --query limit=5"];
111
+ };
112
+ readonly "raw write": {
113
+ readonly description: "Send one raw write when the profile allows writes and the operation list includes raw-write";
114
+ readonly flags: {
115
+ readonly config: "Config path; default platform path";
116
+ readonly profile: "Profile name; default credential precedence";
117
+ readonly method: "Required POST, PUT, PATCH or DELETE";
118
+ readonly path: "Required absolute API path such as /api/v1/...";
119
+ readonly query: "URL query such as key=value";
120
+ readonly "body-file": "JSON body file or - for stdin";
121
+ readonly execute: "Send after exact confirmation; default preview only";
122
+ readonly "dry-run": "Preview only; incompatible with --execute";
123
+ readonly confirm: "Exact preview confirmation";
124
+ readonly "intent-id": "Optional durable intent identifier";
125
+ readonly help: "Show help; default false";
126
+ };
127
+ readonly examples: readonly ["tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json", "tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json --execute --confirm <preview confirm>"];
128
+ };
97
129
  readonly "setup hooks": {
98
130
  readonly description: "Explicitly install or repair local agent session integrations";
99
131
  readonly flags: {
@@ -7,6 +7,7 @@ import { platformTagBindings, platformTagCatalogue, platformTagMutations } from
7
7
  import { responseBindings, responseCatalogue, responseMutations } from "./response-catalogue.js";
8
8
  export const DESCRIPTION = "Investigate Tenable One exposure and run explicitly guarded writes";
9
9
  export const SETUP_GUIDANCE = "Run tenable-axi config path; configure a profile with accessKey and secretKey SecretRefs";
10
+ export const capabilities = { rawWrites: true };
10
11
  // Endpoint slices add reviewed executable bindings alongside their commands.
11
12
  export const transportBindings = Object.freeze({ ...inventoryBindings, ...exposureBindings, ...attackBindings, ...inventoryExportBindings, ...attackExportBindings, ...platformTagBindings, ...responseBindings });
12
13
  export const mutationOperations = Object.freeze({ ...inventoryExportMutations, ...attackExportMutations, ...platformTagMutations, ...responseMutations });
@@ -18,6 +19,16 @@ export const catalogue = {
18
19
  ...attackExportCatalogue,
19
20
  ...platformTagCatalogue,
20
21
  ...responseCatalogue,
22
+ "raw get": {
23
+ description: "Read any Tenable API path on the exact origin with the selected profile keys",
24
+ flags: { config: "Config path; default platform path", profile: "Profile name; default credential precedence", path: "Required absolute API path such as /api/v1/t1/tags/properties", query: "URL query such as limit=10&offset=0", out: "Save response bytes to a new file", help: "Show help; default false" },
25
+ examples: ["tenable-axi raw get --path /api/v1/t1/tags/properties", "tenable-axi raw get --path /api/v1/t1/tags/search --query limit=5"],
26
+ },
27
+ "raw write": {
28
+ description: "Send one raw write when the profile allows writes and the operation list includes raw-write",
29
+ flags: { config: "Config path; default platform path", profile: "Profile name; default credential precedence", method: "Required POST, PUT, PATCH or DELETE", path: "Required absolute API path such as /api/v1/...", query: "URL query such as key=value", "body-file": "JSON body file or - for stdin", execute: "Send after exact confirmation; default preview only", "dry-run": "Preview only; incompatible with --execute", confirm: "Exact preview confirmation", "intent-id": "Optional durable intent identifier", help: "Show help; default false" },
30
+ examples: ["tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json", "tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json --execute --confirm <preview confirm>"],
31
+ },
21
32
  "setup hooks": {
22
33
  description: "Explicitly install or repair local agent session integrations",
23
34
  flags: { scope: "user or project; default user; project targets the current directory", help: "Show help; default false" },
@@ -61,6 +72,7 @@ export function help() {
61
72
  return {
62
73
  description: DESCRIPTION,
63
74
  commands: Object.fromEntries(Object.entries(catalogue).map(([name, entry]) => [name, entry.description])),
75
+ capabilities,
64
76
  flags: Object.fromEntries(Object.entries(catalogue.home.flags).map(([name, description]) => [`--${name}`, description])),
65
77
  version: "-v, -V, --version: print the bare version",
66
78
  examples: catalogue.home.examples,
package/dist/src/cli.d.ts CHANGED
@@ -6,6 +6,10 @@ export declare function main(argv?: string[], options?: {
6
6
  stdout?: {
7
7
  write: (chunk: string) => unknown;
8
8
  };
9
+ rawOutput?: (chunk: Uint8Array) => void | Promise<void>;
10
+ stderr?: {
11
+ write: (chunk: string) => unknown;
12
+ };
9
13
  transportFactory?: TransportFactory;
10
14
  writeCoordinatorFactory?: WriteCoordinatorFactory;
11
15
  }): Promise<void>;
package/dist/src/cli.js CHANGED
@@ -9,19 +9,24 @@ import { TransportError } from "./transport.js";
9
9
  import { attackCommand } from "./attack.js";
10
10
  import { attackExportCommand } from "./attack-export.js";
11
11
  import { inventoryExportCommand } from "./inventory-export.js";
12
+ import { rawCommand } from "./raw.js";
12
13
  import { createWriteCoordinator } from "./writes.js";
13
14
  import { platformTagCommand } from "./platform-tag.js";
14
15
  import { responseCommand } from "./response.js";
15
16
  import { setupHooks } from "./setup.js";
16
17
  export async function main(argv = process.argv.slice(2), options = {}) {
17
18
  const store = credentialStore(options.credentials);
19
+ let rawStream = false;
20
+ let rawStreamError = false;
21
+ let abortedStdout = false;
18
22
  await runAxiCli({
19
23
  description: DESCRIPTION,
20
24
  argv: ["scaffold"],
21
25
  topLevelHelp: "",
22
26
  home: async () => store.redactor.payload(await exposureCommand([], store, options.transportFactory)),
23
- stdout: { write: (chunk) => (options.stdout ?? process.stdout).write(store.redactor.text(chunk)) },
24
- formatError: (error) => ({
27
+ stdout: { write: (chunk) => rawStreamError ? (options.stderr ?? process.stderr).write(store.redactor.text(chunk))
28
+ : rawStream ? undefined : (options.stdout ?? process.stdout).write(store.redactor.text(chunk)) },
29
+ formatError: (error) => (rawStreamError = rawStream, {
25
30
  output: `${encode(store.redactor.value({
26
31
  ...((!argv.length || argv[0] === "home" || argv[0]?.startsWith("--") && argv[0] !== "--help")
27
32
  && !(error instanceof AxiError && error.code === "VALIDATION_ERROR") ? homeIdentity() : {}),
@@ -36,6 +41,29 @@ export async function main(argv = process.argv.slice(2), options = {}) {
36
41
  return setupHooks(argv);
37
42
  if (argv[0] === "tag" && !["list", "properties"].includes(argv[1] ?? ""))
38
43
  return store.redactor.payload(await platformTagCommand(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials))));
44
+ if (argv[0] === "raw")
45
+ return store.redactor.payload(await rawCommand(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials)), (chunk, contentType, signal) => {
46
+ if (!rawStream)
47
+ (options.stderr ?? process.stderr).write(`Content-Type: ${contentType ?? "application/octet-stream"}\n`);
48
+ rawStream = true;
49
+ return (options.rawOutput ?? ((bytes) => new Promise((resolve, reject) => {
50
+ const onError = (error) => reject(error);
51
+ const onAbort = () => { abortedStdout = true; process.stdout.destroy(); };
52
+ process.stdout.once("error", onError);
53
+ signal.addEventListener("abort", onAbort, { once: true });
54
+ if (signal.aborted)
55
+ onAbort();
56
+ process.stdout.write(bytes, (error) => {
57
+ signal.removeEventListener("abort", onAbort);
58
+ if (error)
59
+ reject(error);
60
+ else {
61
+ process.stdout.off("error", onError);
62
+ resolve();
63
+ }
64
+ });
65
+ })))(chunk);
66
+ }));
39
67
  if (["initiative", "combination"].includes(argv[0] ?? "")) {
40
68
  const result = await responseCommand(argv, store, options.transportFactory, options.writeCoordinatorFactory ?? ((flags) => createWriteCoordinator(flags, options.credentials)));
41
69
  if (result.error)
@@ -66,4 +94,6 @@ export async function main(argv = process.argv.slice(2), options = {}) {
66
94
  },
67
95
  },
68
96
  });
97
+ if (abortedStdout)
98
+ process.stderr.write("", () => process.exit(process.exitCode));
69
99
  }
@@ -2,4 +2,5 @@ import type { credentialStore } from "./profiles.js";
2
2
  import type { TransportFactory } from "./exposure.js";
3
3
  import { createWriteCoordinator, type WriteCoordinatorOptions } from "./writes.js";
4
4
  export type WriteCoordinatorFactory = (options: WriteCoordinatorOptions) => ReturnType<typeof createWriteCoordinator>;
5
+ export declare function bodyFile(path: string): unknown;
5
6
  export declare function inventoryExportCommand(argv: string[], store: ReturnType<typeof credentialStore>, factory?: TransportFactory, writeFactory?: WriteCoordinatorFactory): Promise<Record<string, unknown>>;
@@ -6,7 +6,7 @@ import { exportOutputPath, saveExport } from "./export-file.js";
6
6
  import { exportStatus } from "./export-wait.js";
7
7
  import { createTransport, TransportError } from "./transport.js";
8
8
  import { createWriteCoordinator } from "./writes.js";
9
- function bodyFile(path) {
9
+ export function bodyFile(path) {
10
10
  const fd = path === "-" ? 0 : openSync(path, "r");
11
11
  try {
12
12
  const chunks = [];
@@ -0,0 +1,4 @@
1
+ import type { TransportFactory } from "./exposure.js";
2
+ import { type WriteCoordinatorFactory } from "./inventory-export.js";
3
+ import type { credentialStore } from "./profiles.js";
4
+ export declare function rawCommand(argv: string[], store: ReturnType<typeof credentialStore>, factory?: TransportFactory, writeFactory?: WriteCoordinatorFactory, output?: (chunk: Uint8Array, contentType: string | null, signal: AbortSignal) => void | Promise<void>): Promise<Record<string, unknown>>;
@@ -0,0 +1,85 @@
1
+ import { AxiError } from "axi-sdk-js";
2
+ import { closeSync, openSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { z } from "zod";
4
+ import { catalogue } from "./catalogue.js";
5
+ import { bodyFile } from "./inventory-export.js";
6
+ import { createTransport } from "./transport.js";
7
+ import { createWriteCoordinator } from "./writes.js";
8
+ const accessControlRoute = /(?:^|\/)(?:users?|(?:access-)?groups?|roles?|permissions?|access-control|credentials?|share|(?:[a-z0-9._~]+-)*keys?|apikeys?)(?:\/|$)/i;
9
+ const apiPath = z.string()
10
+ .regex(/^\/[A-Za-z0-9._~/-]+$/)
11
+ .refine((path) => !/(?:^|\/)\.{1,2}(?:\/|$)|\/\//.test(path))
12
+ .refine((path) => !accessControlRoute.test(path));
13
+ const writeMethod = z.enum(["POST", "PUT", "PATCH", "DELETE"]);
14
+ export async function rawCommand(argv, store, factory = createTransport, writeFactory = createWriteCoordinator, output = () => { }) {
15
+ const name = argv.slice(0, 2).join(" ");
16
+ const entry = catalogue[name];
17
+ const usage = (message) => {
18
+ throw new AxiError(message, "VALIDATION_ERROR", [entry
19
+ ? `Valid flags for ${name}: ${Object.keys(entry.flags).map((flag) => `--${flag}`).join(", ")}`
20
+ : "Valid commands: raw get, raw write"]);
21
+ };
22
+ if (!entry)
23
+ usage("Unknown raw command");
24
+ const flags = new Map();
25
+ for (let index = 2; index < argv.length; index++) {
26
+ const flag = argv[index];
27
+ if (!flag.startsWith("--") || !Object.hasOwn(entry.flags, flag.slice(2)) || flags.has(flag))
28
+ usage(`Unknown argument, flag, or duplicate flag: ${flag}`);
29
+ const value = ["--help", "--execute", "--dry-run"].includes(flag) ? "true" : argv[++index];
30
+ if (!value || value.startsWith("--"))
31
+ usage(`Missing value for ${flag}`);
32
+ flags.set(flag, value);
33
+ }
34
+ const get = (key) => flags.get(`--${key}`);
35
+ if (get("help"))
36
+ return { command: name, ...entry };
37
+ const path = apiPath.safeParse(get("path")).data ?? usage("--path must be an absolute Tenable API path of letters, digits, dots, dashes, underscores, tildes and slashes, without dot segments or access-control routes");
38
+ const params = new URLSearchParams(get("query") ?? "");
39
+ const query = Object.fromEntries([...new Set(params.keys())].map((key) => [key, params.getAll(key)]));
40
+ if (argv[1] === "get") {
41
+ const profile = store.select(store.load(get("config")).config, get("profile"));
42
+ const transport = factory({ keys: store.credentials(profile), origin: profile.origin });
43
+ const out = get("out");
44
+ let fd;
45
+ let completed = false;
46
+ try {
47
+ const response = await transport.request("raw-get", { raw: { method: "GET", path }, query, rawOutput: async (contentType, signal) => {
48
+ if (out)
49
+ fd = openSync(out, "wx", 0o600);
50
+ if (!out)
51
+ await output(new Uint8Array(), contentType, signal);
52
+ return (chunk) => { if (fd !== undefined)
53
+ writeFileSync(fd, chunk);
54
+ else
55
+ return output(chunk, contentType, signal); };
56
+ } });
57
+ completed = true;
58
+ return out ? { status: response.status, contentType: response.contentType, output: out } : {};
59
+ }
60
+ finally {
61
+ if (fd !== undefined) {
62
+ closeSync(fd);
63
+ if (!completed)
64
+ unlinkSync(out);
65
+ }
66
+ }
67
+ }
68
+ const method = writeMethod.safeParse(get("method")).data ?? usage("--method must be POST, PUT, PATCH or DELETE");
69
+ let body;
70
+ if (get("body-file")) {
71
+ try {
72
+ body = bodyFile(get("body-file"));
73
+ }
74
+ catch {
75
+ usage("Cannot read --body-file as JSON within the 1 MiB limit");
76
+ }
77
+ }
78
+ const result = await writeFactory({ config: get("config"), profile: get("profile") }).run("raw-write", { query, body }, { execute: get("execute") === "true", dryRun: get("dry-run") === "true", confirm: get("confirm"), intentId: get("intent-id") }, { method, path }, async (contentType, signal) => {
79
+ await output(new Uint8Array(), contentType, signal);
80
+ return (chunk) => output(chunk, contentType, signal);
81
+ });
82
+ if (result.kind !== "success")
83
+ return result;
84
+ return {};
85
+ }
@@ -1,4 +1,4 @@
1
- import type { z } from "zod";
1
+ import { z } from "zod";
2
2
  export declare const TENABLE_ORIGIN = "https://cloud.tenable.com";
3
3
  export type ApiKeys = Readonly<{
4
4
  accessKey: string;
@@ -15,6 +15,10 @@ export type OperationBinding = Readonly<{
15
15
  permissionHelp: string;
16
16
  validationHelp: string;
17
17
  }>;
18
+ export type RawRoute = Readonly<{
19
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
20
+ path: string;
21
+ }>;
18
22
  export type RequestOptions = {
19
23
  pathParams?: Readonly<Record<string, string>>;
20
24
  query?: Readonly<Record<string, string | number | boolean | readonly string[]>>;
@@ -23,12 +27,15 @@ export type RequestOptions = {
23
27
  signal?: AbortSignal;
24
28
  authorization?: unknown;
25
29
  retry?: false;
30
+ raw?: RawRoute;
31
+ rawOutput?: (contentType: string | null, signal: AbortSignal) => ((chunk: Uint8Array) => void | Promise<void>) | undefined | Promise<((chunk: Uint8Array) => void | Promise<void>) | undefined>;
26
32
  };
27
33
  export type Transport = {
28
34
  prepare(operation: string, options?: RequestOptions): PreparedRequest;
29
35
  request(operation: string, options?: RequestOptions): Promise<{
30
36
  status: number;
31
37
  body: unknown;
38
+ contentType?: string | null;
32
39
  }>;
33
40
  };
34
41
  export type PreparedRequest = Readonly<{
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  import { ResponseDiagnostics } from "./response-diagnostics.js";
2
3
  export const TENABLE_ORIGIN = "https://cloud.tenable.com";
3
4
  export class TransportError extends Error {
@@ -88,17 +89,26 @@ export function constructTransport(options, dependencies) {
88
89
  }
89
90
  return url;
90
91
  }
91
- function prepare(operation, input = {}) {
92
+ function resolve(operation, input) {
93
+ if (input.raw) {
94
+ return { method: input.raw.method, path: input.raw.path, effect: input.raw.method === "GET" ? "read" : "write",
95
+ query: Object.keys(input.query ?? {}), decoder: z.unknown(), permissionHelp: "Check that the key has the permission for this route",
96
+ validationHelp: "Check the path, query and body against the Tenable API reference" };
97
+ }
92
98
  const binding = Object.hasOwn(bindings, operation) ? bindings[operation] : undefined;
93
99
  if (!binding)
94
100
  fail("OPERATION_BLOCKED", "Operation has no executable catalogue binding");
101
+ return binding;
102
+ }
103
+ function prepare(operation, input = {}) {
104
+ const binding = resolve(operation, input);
95
105
  const url = destination(operation, binding, input).href;
96
106
  const body = input.body === undefined ? undefined : JSON.stringify(input.body);
97
107
  return Object.freeze({ operation, method: binding.method, url, body, effect: binding.effect });
98
108
  }
99
109
  async function request(operation, input = {}) {
100
110
  const { url, body } = prepare(operation, input);
101
- const record = bindings[operation];
111
+ const record = resolve(operation, input);
102
112
  const canonical = new URL(url);
103
113
  canonical.searchParams.sort();
104
114
  const identity = JSON.stringify([operation, canonical.href, body]);
@@ -127,19 +137,39 @@ export function constructTransport(options, dependencies) {
127
137
  let response;
128
138
  let text;
129
139
  let file;
140
+ let contents;
141
+ let streamed = false;
142
+ const waitForOutput = async (value) => {
143
+ let cancel;
144
+ const aborted = new Promise((_, reject) => {
145
+ cancel = () => reject(new Error("Request aborted"));
146
+ controller.signal.addEventListener("abort", cancel, { once: true });
147
+ if (controller.signal.aborted)
148
+ cancel();
149
+ });
150
+ try {
151
+ return await Promise.race([value, aborted]);
152
+ }
153
+ finally {
154
+ controller.signal.removeEventListener("abort", cancel);
155
+ }
156
+ };
130
157
  try {
131
158
  response = await dependencies.fetch(url, {
132
159
  method: record.method, redirect: "error", signal: controller.signal,
133
- headers: { "X-ApiKeys": header, Accept: record.responseMode === "file" ? "application/octet-stream" : "application/json", ...(body === undefined ? {} : { "Content-Type": "application/json" }) },
160
+ headers: { "X-ApiKeys": header, Accept: input.raw ? "*/*" : record.responseMode === "file" ? "application/octet-stream" : "application/json", ...(body === undefined ? {} : { "Content-Type": "application/json" }) },
134
161
  ...(body === undefined ? {} : { body }),
135
162
  });
136
163
  if (response.status >= 300 && response.status < 400) {
137
164
  await response.body?.cancel();
138
165
  fail("DESTINATION_DENIED", "Tenable redirects are refused", operation, [], { status: response.status });
139
166
  }
140
- const reader = response.body?.getReader();
141
167
  const chunks = [];
142
- const downloading = record.responseMode === "file" && response.status >= 200 && response.status < 300;
168
+ const output = input.raw && response.status >= 200 && response.status < 300
169
+ ? await waitForOutput(input.rawOutput?.(response.headers.get("content-type"), controller.signal)) : undefined;
170
+ streamed = output !== undefined;
171
+ const reader = response.body?.getReader();
172
+ const downloading = (record.responseMode === "file" || !!input.raw) && response.status >= 200 && response.status < 300;
143
173
  const ceiling = downloading ? 128 * 1024 * 1024 : 20 * 1024 * 1024;
144
174
  if (downloading && Number(response.headers.get("content-length")) > ceiling) {
145
175
  await reader?.cancel();
@@ -155,16 +185,19 @@ export function constructTransport(options, dependencies) {
155
185
  controller.abort();
156
186
  fail("BYTE_BUDGET_EXCEEDED", "Invocation decoded response byte budget exceeded", operation);
157
187
  }
158
- chunks.push(chunk.value);
188
+ if (output)
189
+ await waitForOutput(output(chunk.value));
190
+ else
191
+ chunks.push(chunk.value);
159
192
  }
160
193
  }
161
194
  finally {
162
195
  await reader?.cancel().catch(() => { });
163
196
  }
164
- const contents = Buffer.concat(chunks);
165
- if (downloading)
197
+ contents = Buffer.concat(chunks);
198
+ if (record.responseMode === "file" && downloading)
166
199
  file = contents;
167
- text = downloading ? "" : contents.toString("utf8");
200
+ text = record.responseMode === "file" && downloading ? "" : contents.toString("utf8");
168
201
  }
169
202
  catch (error) {
170
203
  if (error instanceof TransportError)
@@ -183,6 +216,9 @@ export function constructTransport(options, dependencies) {
183
216
  if (now() >= deadline)
184
217
  fail(record.effect === "write" ? "OUTCOME_UNKNOWN" : "DEADLINE_EXCEEDED", "Invocation deadline exceeded", operation);
185
218
  if (response.status >= 200 && response.status < 300) {
219
+ const contentType = response.headers.get("content-type");
220
+ if (input.raw)
221
+ return { status: response.status, body: streamed ? undefined : contents, contentType };
186
222
  if (record.responseMode === "file") {
187
223
  if (response.status === 204)
188
224
  fail("EXPORT_NOT_READY", "Export chunk is not ready; check status before downloading", operation);
@@ -50,6 +50,10 @@ export type MutationOptions = {
50
50
  confirm?: string;
51
51
  intentId?: string;
52
52
  };
53
+ export type RawWriteRoute = Readonly<{
54
+ method: "POST" | "PUT" | "PATCH" | "DELETE";
55
+ path: string;
56
+ }>;
53
57
  export declare function constructWriteCoordinator(options: WriteCoordinatorOptions, dependencies: {
54
58
  operations: Readonly<Record<string, MutationOperation>>;
55
59
  bindings: Readonly<Record<string, OperationBinding>>;
@@ -63,7 +67,7 @@ export declare function constructWriteCoordinator(options: WriteCoordinatorOptio
63
67
  allowWrites: boolean;
64
68
  operations: readonly string[];
65
69
  }>;
66
- run: (operation: string, input: unknown, flags?: MutationOptions) => Promise<{
70
+ run: (operation: string, input: unknown, flags?: MutationOptions, raw?: RawWriteRoute, rawOutput?: RequestOptions["rawOutput"]) => Promise<{
67
71
  kind: "dry-run";
68
72
  preview: Readonly<{
69
73
  profile: string;
@@ -78,6 +82,7 @@ export declare function constructWriteCoordinator(options: WriteCoordinatorOptio
78
82
  auditId?: undefined;
79
83
  status?: undefined;
80
84
  response?: undefined;
85
+ contentType?: undefined;
81
86
  } | {
82
87
  kind: "noop";
83
88
  preview: Readonly<{
@@ -93,6 +98,7 @@ export declare function constructWriteCoordinator(options: WriteCoordinatorOptio
93
98
  auditId?: undefined;
94
99
  status?: undefined;
95
100
  response?: undefined;
101
+ contentType?: undefined;
96
102
  } | {
97
103
  kind: "success";
98
104
  preview: Readonly<{
@@ -108,11 +114,13 @@ export declare function constructWriteCoordinator(options: WriteCoordinatorOptio
108
114
  auditId: `${string}-${string}-${string}-${string}-${string}`;
109
115
  status: number;
110
116
  response: unknown;
117
+ contentType: string | null | undefined;
111
118
  }>;
112
119
  reader: {
113
120
  request: (name: string, options?: RequestOptions) => Promise<{
114
121
  status: number;
115
122
  body: unknown;
123
+ contentType?: string | null;
116
124
  }>;
117
125
  };
118
126
  };
@@ -5,6 +5,14 @@ import { z } from "zod";
5
5
  import { credentialStore } from "./profiles.js";
6
6
  import { privateFiles } from "./private-file.js";
7
7
  import { constructTransport, TransportError } from "./transport-core.js";
8
+ function rawWriteDefinition(route) {
9
+ return {
10
+ input: z.strictObject({ query: z.record(z.string(), z.union([z.string(), z.array(z.string())])).optional(), body: z.unknown().optional() }),
11
+ prepare: (input) => ({ target: { kind: `${route.method} ${route.path}`, payload: true }, request: input }),
12
+ effect: `Send ${route.method} ${route.path}`,
13
+ readBackHelp: ["Read the target through its owning Tenable API before any new intent; never replay this intent"],
14
+ };
15
+ }
8
16
  function canonical(value) {
9
17
  const normalize = (value) => {
10
18
  if (Array.isArray(value))
@@ -129,10 +137,10 @@ export function constructWriteCoordinator(options, dependencies) {
129
137
  }
130
138
  }
131
139
  }
132
- async function run(operation, input, flags = {}) {
140
+ async function run(operation, input, flags = {}, raw, rawOutput) {
133
141
  flags = { ...flags };
134
- const definition = Object.hasOwn(definitions, operation) ? definitions[operation] : undefined;
135
- if (!definition || bindings[operation]?.effect !== "write")
142
+ const definition = raw ? rawWriteDefinition(raw) : Object.hasOwn(definitions, operation) ? definitions[operation] : undefined;
143
+ if (!definition || (!raw && bindings[operation]?.effect !== "write"))
136
144
  fail("OPERATION_BLOCKED", "Operation has no reviewed write binding", operation);
137
145
  const parsed = definition.input.safeParse(input);
138
146
  if (!parsed.success)
@@ -140,7 +148,7 @@ export function constructWriteCoordinator(options, dependencies) {
140
148
  const prepared = definition.prepare(JSON.parse(canonical(parsed.data)));
141
149
  const request = JSON.parse(canonical(prepared.request));
142
150
  const target = JSON.parse(canonical(prepared.target));
143
- const securityField = (value) => !!value && typeof value === "object" && Object.entries(value).some(([key, child]) => /^(?:access_control|permissions|roles|credentials|api_keys)$/i.test(key) || securityField(child));
151
+ const securityField = (value) => !!value && typeof value === "object" && Object.entries(value).some(([key, child]) => /^(?:acl|access_control|permissions?|roles|credentials|api_keys)$/i.test(key) || securityField(child));
144
152
  if (securityField(request.body))
145
153
  fail("VALIDATION_ERROR", "Security administration payloads are blocked", operation);
146
154
  const uuid = z.string().uuid();
@@ -157,7 +165,7 @@ export function constructWriteCoordinator(options, dependencies) {
157
165
  if (!scope.operations.includes(operation))
158
166
  fail("OPERATION_NOT_WRITABLE", "Operation is outside the configured write scope", operation);
159
167
  const connection = sender();
160
- const plan = connection.prepare(operation, request);
168
+ const plan = connection.prepare(operation, { ...request, raw });
161
169
  const { effect: _effect, ...identity } = plan;
162
170
  const confirmationTarget = "payload" in target ? { kind: target.kind, digest: digest(canonical(request)) } : target;
163
171
  const confirm = canonical([scope.profile, operation, confirmationTarget]);
@@ -197,7 +205,7 @@ export function constructWriteCoordinator(options, dependencies) {
197
205
  authorizations.set(authorization, canonical(identity));
198
206
  let response;
199
207
  try {
200
- response = await connection.request(operation, { ...request, authorization });
208
+ response = await connection.request(operation, { ...request, raw, rawOutput, authorization });
201
209
  }
202
210
  catch (error) {
203
211
  authorizations.delete(authorization);
@@ -210,7 +218,8 @@ export function constructWriteCoordinator(options, dependencies) {
210
218
  throw new TransportError({ ...upstream.error, auditId }, upstream.help);
211
219
  }
212
220
  append("outcome", "SUCCESS", response.status);
213
- return { kind: "success", preview, auditId, status: response.status, response: store.redactor.payload(response.body) };
221
+ return { kind: "success", preview, auditId, status: response.status,
222
+ response: Buffer.isBuffer(response.body) && raw ? response.body : store.redactor.payload(response.body), contentType: response.contentType };
214
223
  }
215
224
  return { scope, run, reader };
216
225
  }
@@ -8,7 +8,7 @@ export declare function createWriteCoordinator(options?: WriteCoordinatorOptions
8
8
  allowWrites: boolean;
9
9
  operations: readonly string[];
10
10
  }>;
11
- run: (operation: string, input: unknown, flags?: import("./writes-core.js").MutationOptions) => Promise<{
11
+ run: (operation: string, input: unknown, flags?: import("./writes-core.js").MutationOptions, raw?: import("./writes-core.js").RawWriteRoute, rawOutput?: import("./transport-core.js").RequestOptions["rawOutput"]) => Promise<{
12
12
  kind: "dry-run";
13
13
  preview: Readonly<{
14
14
  profile: string;
@@ -23,6 +23,7 @@ export declare function createWriteCoordinator(options?: WriteCoordinatorOptions
23
23
  auditId?: undefined;
24
24
  status?: undefined;
25
25
  response?: undefined;
26
+ contentType?: undefined;
26
27
  } | {
27
28
  kind: "noop";
28
29
  preview: Readonly<{
@@ -38,6 +39,7 @@ export declare function createWriteCoordinator(options?: WriteCoordinatorOptions
38
39
  auditId?: undefined;
39
40
  status?: undefined;
40
41
  response?: undefined;
42
+ contentType?: undefined;
41
43
  } | {
42
44
  kind: "success";
43
45
  preview: Readonly<{
@@ -53,11 +55,13 @@ export declare function createWriteCoordinator(options?: WriteCoordinatorOptions
53
55
  auditId: `${string}-${string}-${string}-${string}-${string}`;
54
56
  status: number;
55
57
  response: unknown;
58
+ contentType: string | null | undefined;
56
59
  }>;
57
60
  reader: {
58
61
  request: (name: string, options?: import("./transport-core.js").RequestOptions) => Promise<{
59
62
  status: number;
60
63
  body: unknown;
64
+ contentType?: string | null;
61
65
  }>;
62
66
  };
63
67
  };
package/docs/commands.md CHANGED
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/generate-docs.mjs from src/catalogue.ts. Do not hand-edit. -->
1
+ <!-- Generated by scripts/generate-docs.ts from src/catalogue.ts. Do not hand-edit. -->
2
2
 
3
3
  # Command reference
4
4
 
@@ -47,6 +47,8 @@ Investigate Tenable One exposure and run explicitly guarded writes.
47
47
  - [initiative show](#initiative-show)
48
48
  - [initiative update](#initiative-update)
49
49
  - [profile list](#profile-list)
50
+ - [raw get](#raw-get)
51
+ - [raw write](#raw-write)
50
52
  - [setup hooks](#setup-hooks)
51
53
  - [software list](#software-list)
52
54
  - [software properties](#software-properties)
@@ -114,6 +116,8 @@ Investigate Tenable One exposure and run explicitly guarded writes.
114
116
  | `tenable-axi initiative show` | show initiative |
115
117
  | `tenable-axi initiative update` | Preview or update initiative |
116
118
  | `tenable-axi profile list` | List configured profiles without resolving secrets or contacting Tenable |
119
+ | `tenable-axi raw get` | Read any Tenable API path on the exact origin with the selected profile keys |
120
+ | `tenable-axi raw write` | Send one raw write when the profile allows writes and the operation list includes raw-write |
117
121
  | `tenable-axi setup hooks` | Explicitly install or repair local agent session integrations |
118
122
  | `tenable-axi software list` | Search software; the pinned API exposes no stable software ID |
119
123
  | `tenable-axi software properties` | Discover software properties and supported operators |
@@ -1065,6 +1069,47 @@ tenable-axi profile list
1065
1069
  tenable-axi profile list --config /example/config.json
1066
1070
  ```
1067
1071
 
1072
+ ## raw get
1073
+
1074
+ Read any Tenable API path on the exact origin with the selected profile keys
1075
+
1076
+ | Flag | Meaning |
1077
+ |---|---|
1078
+ | `--config` | Config path; default platform path |
1079
+ | `--profile` | Profile name; default credential precedence |
1080
+ | `--path` | Required absolute API path such as /api/v1/t1/tags/properties |
1081
+ | `--query` | URL query such as limit=10&offset=0 |
1082
+ | `--out` | Save response bytes to a new file |
1083
+ | `--help` | Show help; default false |
1084
+
1085
+ ```sh
1086
+ tenable-axi raw get --path /api/v1/t1/tags/properties
1087
+ tenable-axi raw get --path /api/v1/t1/tags/search --query limit=5
1088
+ ```
1089
+
1090
+ ## raw write
1091
+
1092
+ Send one raw write when the profile allows writes and the operation list includes raw-write
1093
+
1094
+ | Flag | Meaning |
1095
+ |---|---|
1096
+ | `--config` | Config path; default platform path |
1097
+ | `--profile` | Profile name; default credential precedence |
1098
+ | `--method` | Required POST, PUT, PATCH or DELETE |
1099
+ | `--path` | Required absolute API path such as /api/v1/... |
1100
+ | `--query` | URL query such as key=value |
1101
+ | `--body-file` | JSON body file or - for stdin |
1102
+ | `--execute` | Send after exact confirmation; default preview only |
1103
+ | `--dry-run` | Preview only; incompatible with --execute |
1104
+ | `--confirm` | Exact preview confirmation |
1105
+ | `--intent-id` | Optional durable intent identifier |
1106
+ | `--help` | Show help; default false |
1107
+
1108
+ ```sh
1109
+ tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json
1110
+ tenable-axi raw write --method PATCH --path /api/v1/example --body-file body.json --execute --confirm <preview confirm>
1111
+ ```
1112
+
1068
1113
  ## setup hooks
1069
1114
 
1070
1115
  Explicitly install or repair local agent session integrations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowttl/tenable-axi",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Investigate Tenable One exposure and run explicitly guarded writes",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,13 +34,13 @@
34
34
  "packageManager": "pnpm@10.34.6",
35
35
  "scripts": {
36
36
  "build": "tsc -p tsconfig.json",
37
- "typecheck": "tsc --noEmit -p tsconfig.json",
37
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.tooling.json",
38
38
  "lint": "pnpm run typecheck",
39
- "test": "node scripts/isolated.mjs node scripts/test-changes.mjs",
40
- "docs:generate": "node scripts/generate-docs.mjs",
41
- "docs:check": "node scripts/generate-docs.mjs --check",
42
- "spec:generate": "node scripts/specs.mjs --generate",
43
- "spec:check": "node scripts/specs.mjs --check"
39
+ "test": "node scripts/isolated.ts node scripts/test-changes.ts",
40
+ "docs:generate": "node scripts/generate-docs.ts",
41
+ "docs:check": "node scripts/generate-docs.ts --check",
42
+ "spec:generate": "node scripts/specs.ts --generate",
43
+ "spec:check": "node scripts/specs.ts --check"
44
44
  },
45
45
  "dependencies": {
46
46
  "@toon-format/toon": "2.3.1",
@@ -3,7 +3,7 @@ name: tenable-axi
3
3
  description: "Investigate Tenable One assets, findings, software, exposure and attack evidence with bounded read-only commands; diagnose failures and distinguish guarded writes."
4
4
  ---
5
5
 
6
- <!-- Generated by scripts/generate-docs.mjs from src/catalogue.ts. Do not hand-edit. -->
6
+ <!-- Generated by scripts/generate-docs.ts from src/catalogue.ts. Do not hand-edit. -->
7
7
 
8
8
  # tenable-axi investigation guide
9
9
 
@@ -86,11 +86,11 @@ Other remote reads: `home`, `card show`, `tag properties`, platform `tag categor
86
86
  Local reads: `auth status`, `profile list`, `config path`, `hook`, help and version.
87
87
  Configured home reads up to five live cards; the optional hook reads local posture only.
88
88
 
89
- Exclude all `create/update/delete/bulk-delete`, `tag assignment add/remove` and `export * start` commands from read allowlists.
89
+ Exclude all `create/update/delete/bulk-delete`, `tag assignment add/remove`, `export * start` and `raw write` commands from read allowlists.
90
90
  Writes require a file profile's `allowWrites` and exact operation allowlist even for previews, followed by `--execute` and the exact preview `--confirm` string.
91
91
  `TENABLE_AXI_READ_ONLY=true` forces read-only.
92
92
  Export downloads read remotely but create a local file at an explicit new output path; `setup hooks` changes local integration files and needs explicit installation intent.
93
- Users, roles, access control, credential minting and arbitrary HTTP are unavailable.
93
+ Users, roles, access control and credential minting are unavailable; raw HTTP is available through `raw get` and guarded `raw write` on validated paths.
94
94
 
95
95
  ## Help and failures
96
96
 
@@ -100,7 +100,7 @@ Leaf `--help` returns that command's flags, defaults, required selectors and exa
100
100
  Group-only help such as `asset --help` is unsupported and returns a usage error with valid commands.
101
101
  The [command reference](https://github.com/knowttl/tenable-axi/blob/main/docs/commands.md) lists the full surface.
102
102
 
103
- Stdout is structured TOON, including errors and actionable help.
103
+ Stdout is structured TOON, including errors and actionable help, except that successful raw responses stream bytes with the content type reported on stderr; see [raw API behavior](https://github.com/knowttl/tenable-axi/blob/main/docs/behavior.md#raw-api).
104
104
  Exit 0 means success (still inspect completeness), 1 means operation/configuration failure, and 2 means CLI usage validation failure.
105
105
 
106
106
  | Code | Adjustment |