@pnpm/error 1100.1.3 → 1100.1.4

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,11 @@
1
1
  # @pnpm/error
2
2
 
3
+ ## 1100.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fetch and tarball errors no longer print the secrets of the URL they name. Inline `user:pass@` credentials and the query string or fragment of a signed URL are hidden, so a failed install or `pnpm add <url>` cannot leak them into terminal scrollback or CI logs.
8
+
3
9
  ## 1100.1.3
4
10
 
5
11
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -27,19 +27,6 @@ export declare class FetchError extends PnpmError {
27
27
  readonly request: FetchErrorRequest;
28
28
  constructor(request: FetchErrorRequest, response: FetchErrorResponse, hint?: string);
29
29
  }
30
- /**
31
- * Strip `user:pass@` (or `user@`) userinfo that follows a URL scheme in any
32
- * text, e.g. `GET https://user:pass@host/pkg: …` → `GET https://host/pkg: …`.
33
- * A registry configured as `https://user:pass@host/` would otherwise leak its
34
- * embedded basic-auth credentials into every error message that interpolates
35
- * the request URL (terminal output, CI logs). `FetchError` already hides the
36
- * auth *header*; this covers credentials carried in the URL itself.
37
- *
38
- * Implemented as a single forward scan rather than a regex: `text` is
39
- * uncontrolled (it interpolates the request URL), so a backtracking pattern is
40
- * a ReDoS vector, and the scan strips up to the **last** `@` in the authority
41
- * so a raw `@` inside the password (`user:p@ss@host`) doesn't leak its tail.
42
- */
43
30
  export declare function redactUrlCredentials(text: string): string;
44
31
  /**
45
32
  * Make untrusted, URL-bearing text safe to print or log: redact inline
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@ export class FetchError extends PnpmError {
22
22
  if (request.authHeaderValue) {
23
23
  _request.authHeaderValue = hideAuthInformation(request.authHeaderValue);
24
24
  }
25
- const message = `GET ${redactUrlCredentials(request.url)}: ${response.statusText} - ${response.status}`;
25
+ const message = `GET ${redactUrlSecrets(request.url)}: ${response.statusText} - ${response.status}`;
26
26
  // NOTE: For security reasons, some registries respond with 404 on authentication errors as well.
27
27
  // So we print authorization info on 404 errors as well.
28
28
  if (response.status === 401 || response.status === 403 || response.status === 404) {
@@ -52,6 +52,32 @@ export class FetchError extends PnpmError {
52
52
  * a ReDoS vector, and the scan strips up to the **last** `@` in the authority
53
53
  * so a raw `@` inside the password (`user:p@ss@host`) doesn't leak its tail.
54
54
  */
55
+ /**
56
+ * A request URL made safe to print: its `user:pass@` userinfo and control
57
+ * characters redacted ({@link redactAndSanitize}), then everything from the
58
+ * query or fragment onwards dropped — a signed tarball or registry URL
59
+ * carries a reusable token there, which credential redaction alone keeps.
60
+ *
61
+ * `[hidden]` when the cut would leave credential material behind. A password
62
+ * containing `?` or `#` defeats the userinfo scan — it reads the `?` as the
63
+ * end of the authority and leaves the whole `user:pa?ss@host` in place — so
64
+ * cutting there would publish the password's prefix. The authority is
65
+ * therefore checked before the cut, not after: any `@` still in front of the
66
+ * path means the userinfo survived.
67
+ *
68
+ * Cuts rather than re-rendering through `URL`, unlike
69
+ * {@link redactUrlForDisplay}: that round-trip normalizes the spelling
70
+ * (`https://host` gains a trailing slash, percent-escapes change case), and
71
+ * an error message should echo the URL the request was given.
72
+ */
73
+ function redactUrlSecrets(url) {
74
+ const sanitized = redactAndSanitize(url);
75
+ const schemeEnd = sanitized.indexOf('://');
76
+ const afterScheme = schemeEnd === -1 ? sanitized : sanitized.slice(schemeEnd + '://'.length);
77
+ if (afterScheme.split('/')[0].includes('@'))
78
+ return '[hidden]';
79
+ return sanitized.split(/[?#]/)[0];
80
+ }
55
81
  export function redactUrlCredentials(text) {
56
82
  let result = '';
57
83
  let cursor = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/error",
3
- "version": "1100.1.3",
3
+ "version": "1100.1.4",
4
4
  "description": "An error class for pnpm errors",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@jest/globals": "30.4.1",
35
- "@pnpm/error": "1100.1.3"
35
+ "@pnpm/error": "1100.1.4"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=22.13"