@nocobase/utils 2.3.0-alpha.1 → 3.0.0-alpha.2

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/lib/cors.js CHANGED
@@ -71,11 +71,14 @@ function isSameOrigin(ctx, origin) {
71
71
  }
72
72
  __name(isSameOrigin, "isSameOrigin");
73
73
  function isTrustedOrigin(ctx, origin) {
74
- var _a;
75
74
  if (isSameOrigin(ctx, origin)) {
76
75
  return true;
77
76
  }
78
- return ((_a = getCorsWhitelist()) == null ? void 0 : _a.has(origin)) || false;
77
+ const whitelist = getCorsWhitelist();
78
+ if (!whitelist) {
79
+ return false;
80
+ }
81
+ return whitelist.has("*") || whitelist.has(origin);
79
82
  }
80
83
  __name(isTrustedOrigin, "isTrustedOrigin");
81
84
  // Annotate the CommonJS export names for ESM import in node:
@@ -30,7 +30,8 @@ export declare function checkUrlAgainstWhitelist(url?: string): void;
30
30
  * Drop-in replacement for `axios.request()` with built-in SSRF protection.
31
31
  *
32
32
  * Validates `config.url` against {@link checkUrlAgainstWhitelist} before
33
- * forwarding to axios. Use this instead of calling axios directly for all
33
+ * forwarding to axios. Every redirect destination is validated before the
34
+ * next request is sent. Use this instead of calling axios directly for all
34
35
  * server-initiated outbound HTTP requests.
35
36
  */
36
37
  export declare function serverRequest<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
@@ -207,7 +207,18 @@ __name(checkUrlAgainstWhitelist, "checkUrlAgainstWhitelist");
207
207
  async function serverRequest(config) {
208
208
  checkUrlAgainstWhitelist(config.url);
209
209
  await warnIfResolvedSsrfRiskTarget(config.url);
210
- return import_axios.default.request(config);
210
+ return import_axios.default.request({
211
+ ...config,
212
+ // Axios request interceptors do not run again for redirects. In Node.js,
213
+ // beforeRedirect runs after Location is resolved and before the next hop
214
+ // is sent, so every redirect destination must be checked here.
215
+ beforeRedirect: /* @__PURE__ */ __name((options) => {
216
+ if (typeof options.href !== "string") {
217
+ throw new Error("Unable to validate redirect destination.");
218
+ }
219
+ checkUrlAgainstWhitelist(options.href);
220
+ }, "beforeRedirect")
221
+ });
211
222
  }
212
223
  __name(serverRequest, "serverRequest");
213
224
  // Annotate the CommonJS export names for ESM import in node:
@@ -43,12 +43,19 @@ __export(storage_path_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(storage_path_exports);
45
45
  var import_path = __toESM(require("path"));
46
+ function resolveDefaultStorageRoot() {
47
+ if (import_path.default.basename(process.cwd()) === "source") {
48
+ return import_path.default.resolve(process.cwd(), "..", "storage");
49
+ }
50
+ return import_path.default.resolve(process.cwd(), "storage");
51
+ }
52
+ __name(resolveDefaultStorageRoot, "resolveDefaultStorageRoot");
46
53
  function resolveStorageRoot() {
47
54
  const raw = process.env.STORAGE_PATH;
48
55
  if (raw) {
49
56
  return import_path.default.isAbsolute(raw) ? raw : import_path.default.resolve(process.cwd(), raw);
50
57
  }
51
- return import_path.default.resolve(process.cwd(), "storage");
58
+ return resolveDefaultStorageRoot();
52
59
  }
53
60
  __name(resolveStorageRoot, "resolveStorageRoot");
54
61
  function storagePathJoin(...segments) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "2.3.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -21,5 +21,5 @@
21
21
  "object-path": "^0.11.8",
22
22
  "ses": "^1.14.0"
23
23
  },
24
- "gitHead": "2377df8ceb12549149017f7f14a61207bf6e49a2"
24
+ "gitHead": "a3faea21082b30989301de04591ee1b91fd4e6a5"
25
25
  }