@nuelink/nuelink-cli 1.6.0 → 1.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.1
4
+
5
+ - Reject HTTP redirects for API requests so mutation bodies and credentials are never forwarded to redirect destinations.
6
+
3
7
  ## 1.6.0
4
8
 
5
9
  - Add collection update, channel assignment, and queue slot management commands.
package/README.md CHANGED
@@ -267,7 +267,7 @@ nuelink-cli posts:add-json --brand-id 13493 --collection-id 33273 --payload ./po
267
267
  ```
268
268
 
269
269
  You can also pipe JSON through stdin with `--payload -`.
270
- CLI 1.5.0 preserves contract-nullable fields exactly; the dry-run body matches
270
+ CLI 1.6.0 preserves contract-nullable fields exactly; the dry-run body matches
271
271
  the JSON body sent by the request.
272
272
 
273
273
  Example `post.json`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuelink/nuelink-cli",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "The official Nuelink CLI for automating social media workflows from your terminal. Schedule posts, upload media, manage brands, and integrate Nuelink into scripts, CI/CD pipelines, and AI agents.",
5
5
  "license": "MIT",
6
6
  "author": "Nuelink",
package/src/http.js CHANGED
@@ -185,6 +185,8 @@ async function nuelinkRequest({ apiKey, method = "GET", endpoint, query, body, m
185
185
  const init = {
186
186
  method,
187
187
  headers,
188
+ // API mutations must never replay a body or credentials to a redirect target.
189
+ redirect: "error",
188
190
  };
189
191
 
190
192
  if (multipart) {
package/test/cli.test.mjs CHANGED
@@ -3,9 +3,10 @@ import assert from "node:assert/strict";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
6
- import { spawnSync } from "node:child_process";
6
+ import { spawn, spawnSync } from "node:child_process";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { pathToFileURL } from "node:url";
9
+ import { createServer } from "node:http";
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = path.dirname(__filename);
@@ -43,6 +44,32 @@ function runCli({ args, homeDir, capturePath, withMock = true, input, extraEnv =
43
44
  });
44
45
  }
45
46
 
47
+ function runCliAsync({ args, homeDir, capturePath, withMock = false, extraEnv = {} }) {
48
+ const nodeArgs = withMock
49
+ ? ["--require", mockCjsPath, mainPath, ...args]
50
+ : [mainPath, ...args];
51
+ return new Promise((resolve, reject) => {
52
+ const child = spawn(process.execPath, nodeArgs, {
53
+ cwd: workspaceRoot,
54
+ env: {
55
+ ...process.env,
56
+ HOME: homeDir,
57
+ USERPROFILE: homeDir,
58
+ NUELINK_API_KEY: currentApiKey(),
59
+ NUELINK_MOCK_CAPTURE_PATH: capturePath,
60
+ ...extraEnv,
61
+ },
62
+ stdio: ["ignore", "pipe", "pipe"],
63
+ });
64
+ let stdout = "";
65
+ let stderr = "";
66
+ child.stdout.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
67
+ child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
68
+ child.on("error", reject);
69
+ child.on("close", (status) => resolve({ status, stdout, stderr }));
70
+ });
71
+ }
72
+
46
73
  function assertJsonError(result, code) {
47
74
  assert.equal(result.status, 1, result.stderr);
48
75
  assert.equal(result.stderr, "");
@@ -68,12 +95,68 @@ test("brands command builds pagination query", async () => {
68
95
  const url = new URL(capture.url);
69
96
 
70
97
  assert.equal(capture.method, "GET");
98
+ assert.equal(capture.redirect, "error");
71
99
  assert.equal(url.pathname, "/api/public/v1/brands");
72
100
  assert.equal(url.searchParams.get("per_page"), "2");
73
101
  assert.equal(url.searchParams.get("page"), "3");
74
102
  assert.match(capture.headers.Authorization || capture.headers.authorization, /^Bearer\s+/);
75
103
  });
76
104
 
105
+ test("mutation requests reject cross-origin redirects before forwarding their body", async () => {
106
+ const homeDir = await setupTempHome();
107
+ let forwardedRequests = 0;
108
+ let originalRequest;
109
+ const destination = createServer(() => {
110
+ forwardedRequests += 1;
111
+ });
112
+ const destinationAddress = await new Promise((resolve) => {
113
+ destination.listen(0, "127.0.0.1", () => resolve(destination.address()));
114
+ });
115
+ const origin = createServer((request, response) => {
116
+ let body = "";
117
+ request.setEncoding("utf8");
118
+ request.on("data", (chunk) => { body += chunk; });
119
+ request.on("end", () => {
120
+ originalRequest = {
121
+ method: request.method,
122
+ authorization: request.headers.authorization,
123
+ body,
124
+ };
125
+ response.writeHead(307, { location: `http://127.0.0.1:${destinationAddress.port}/capture` });
126
+ response.end();
127
+ });
128
+ });
129
+
130
+ try {
131
+ const originAddress = await new Promise((resolve) => {
132
+ origin.listen(0, "127.0.0.1", () => resolve(origin.address()));
133
+ });
134
+ const result = await runCliAsync({
135
+ args: ["collections:create", "--brand-id", "13493", "--title", "redirect guard"],
136
+ homeDir,
137
+ capturePath: path.join(homeDir, "capture-redirect-policy.json"),
138
+ withMock: false,
139
+ extraEnv: {
140
+ NUELINK_BASE_URL: `http://127.0.0.1:${originAddress.port}/api/public/v1`,
141
+ NUELINK_ALLOW_INSECURE_HTTP: "1",
142
+ },
143
+ });
144
+
145
+ assert.equal(result.status, 1);
146
+ assert.deepEqual(originalRequest, {
147
+ method: "POST",
148
+ authorization: `Bearer ${currentApiKey()}`,
149
+ body: JSON.stringify({ title: "redirect guard", description: "", channels: [], queues: [] }),
150
+ });
151
+ assert.equal(forwardedRequests, 0);
152
+ } finally {
153
+ await Promise.all([
154
+ new Promise((resolve) => origin.close(resolve)),
155
+ new Promise((resolve) => destination.close(resolve)),
156
+ ]);
157
+ }
158
+ });
159
+
77
160
  test("automations command builds pagination query", async () => {
78
161
  const homeDir = await setupTempHome();
79
162
  const capturePath = path.join(homeDir, "capture-automations.json");
@@ -41,6 +41,7 @@ globalThis.fetch = async (input, init = {}) => {
41
41
  requestCount,
42
42
  url: url.toString(),
43
43
  method: init.method || "GET",
44
+ redirect: init.redirect,
44
45
  headers,
45
46
  body: parsedBody,
46
47
  };
@@ -41,6 +41,7 @@ globalThis.fetch = async (input, init = {}) => {
41
41
  requestCount,
42
42
  url: url.toString(),
43
43
  method: init.method || "GET",
44
+ redirect: init.redirect,
44
45
  headers,
45
46
  body: parsedBody,
46
47
  };