@pnpm/error 1100.0.0 → 1100.0.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 +1 -1
- package/lib/index.d.ts +14 -0
- package/lib/index.js +50 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> An error class for pnpm errors
|
|
4
4
|
|
|
5
5
|
<!--@shields('npm')-->
|
|
6
|
-
[](https://
|
|
6
|
+
[](https://npmx.dev/package/@pnpm/error)
|
|
7
7
|
<!--/@-->
|
|
8
8
|
|
|
9
9
|
## Installation
|
package/lib/index.d.ts
CHANGED
|
@@ -27,6 +27,20 @@ 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
|
+
export declare function redactUrlCredentials(text: string): string;
|
|
30
44
|
export declare class LockfileMissingDependencyError extends PnpmError {
|
|
31
45
|
constructor(depPath: string);
|
|
32
46
|
}
|
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 ${request.url}: ${response.statusText} - ${response.status}`;
|
|
25
|
+
const message = `GET ${redactUrlCredentials(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) {
|
|
@@ -39,6 +39,55 @@ export class FetchError extends PnpmError {
|
|
|
39
39
|
this.response = response;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Strip `user:pass@` (or `user@`) userinfo that follows a URL scheme in any
|
|
44
|
+
* text, e.g. `GET https://user:pass@host/pkg: …` → `GET https://host/pkg: …`.
|
|
45
|
+
* A registry configured as `https://user:pass@host/` would otherwise leak its
|
|
46
|
+
* embedded basic-auth credentials into every error message that interpolates
|
|
47
|
+
* the request URL (terminal output, CI logs). `FetchError` already hides the
|
|
48
|
+
* auth *header*; this covers credentials carried in the URL itself.
|
|
49
|
+
*
|
|
50
|
+
* Implemented as a single forward scan rather than a regex: `text` is
|
|
51
|
+
* uncontrolled (it interpolates the request URL), so a backtracking pattern is
|
|
52
|
+
* a ReDoS vector, and the scan strips up to the **last** `@` in the authority
|
|
53
|
+
* so a raw `@` inside the password (`user:p@ss@host`) doesn't leak its tail.
|
|
54
|
+
*/
|
|
55
|
+
export function redactUrlCredentials(text) {
|
|
56
|
+
let result = '';
|
|
57
|
+
let cursor = 0;
|
|
58
|
+
while (cursor < text.length) {
|
|
59
|
+
const schemeSep = text.indexOf('://', cursor);
|
|
60
|
+
if (schemeSep === -1)
|
|
61
|
+
return result + text.slice(cursor);
|
|
62
|
+
const authorityStart = schemeSep + 3;
|
|
63
|
+
result += text.slice(cursor, authorityStart);
|
|
64
|
+
cursor = authorityStart;
|
|
65
|
+
// Only treat `://` as a URL authority boundary when a scheme character
|
|
66
|
+
// (schemes end in an ASCII alphanumeric) sits right before it; otherwise a
|
|
67
|
+
// bare `://` in the text is left untouched.
|
|
68
|
+
if (schemeSep === 0 || !isSchemeTailChar(text.charCodeAt(schemeSep - 1)))
|
|
69
|
+
continue;
|
|
70
|
+
// Userinfo runs to the last `@` within the authority, which itself ends at
|
|
71
|
+
// the first `/`, `?`, `#`, or whitespace.
|
|
72
|
+
let lastAt = -1;
|
|
73
|
+
for (let i = authorityStart; i < text.length; i++) {
|
|
74
|
+
const code = text.charCodeAt(i);
|
|
75
|
+
if (code === 0x2f || code === 0x3f || code === 0x23 || isAsciiWhitespace(code))
|
|
76
|
+
break;
|
|
77
|
+
if (code === 0x40)
|
|
78
|
+
lastAt = i;
|
|
79
|
+
}
|
|
80
|
+
if (lastAt !== -1)
|
|
81
|
+
cursor = lastAt + 1;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function isSchemeTailChar(code) {
|
|
86
|
+
return (code >= 0x30 && code <= 0x39) || (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);
|
|
87
|
+
}
|
|
88
|
+
function isAsciiWhitespace(code) {
|
|
89
|
+
return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0b || code === 0x0c || code === 0x0d;
|
|
90
|
+
}
|
|
42
91
|
function hideAuthInformation(authHeaderValue) {
|
|
43
92
|
const [authType, token] = authHeaderValue.split(' ');
|
|
44
93
|
if (token == null)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/error",
|
|
3
|
-
"version": "1100.0.
|
|
3
|
+
"version": "1100.0.1",
|
|
4
4
|
"description": "An error class for pnpm errors",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -9,8 +9,11 @@
|
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"funding": "https://opencollective.com/pnpm",
|
|
12
|
-
"repository":
|
|
13
|
-
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/pnpm/pnpm/tree/main/pnpm11/core/error"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/pnpm11/core/error#readme",
|
|
14
17
|
"bugs": {
|
|
15
18
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
16
19
|
},
|
|
@@ -28,7 +31,8 @@
|
|
|
28
31
|
"@pnpm/constants": "1100.0.0"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@
|
|
34
|
+
"@jest/globals": "30.4.1",
|
|
35
|
+
"@pnpm/error": "1100.0.1"
|
|
32
36
|
},
|
|
33
37
|
"engines": {
|
|
34
38
|
"node": ">=22.13"
|