@dx-do/client 7.14.0 → 7.15.0
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/dist/index.cjs.js
CHANGED
|
@@ -48704,7 +48704,9 @@ class StrictMap extends Map {
|
|
|
48704
48704
|
* Redaction helpers for keeping auth tokens and other secrets out of logs.
|
|
48705
48705
|
*
|
|
48706
48706
|
* Auth tokens live in axios `error.config.headers` — e.g. `Authorization: Bearer
|
|
48707
|
-
* <userToken>` and `X-Asm-Auth: <dxASMToken
|
|
48707
|
+
* <userToken>` and `X-Asm-Auth: <dxASMToken>` — and in request bodies that carry a
|
|
48708
|
+
* token field (the audit record), which axios keeps as JSON text in
|
|
48709
|
+
* `error.config.data`. Anything that serializes a whole
|
|
48708
48710
|
* error / config / headers object (`JSON.stringify`, an AxiosError's `.toJSON()`,
|
|
48709
48711
|
* `console.log(err)`, or a logger that deep-prints its argument) will spill them.
|
|
48710
48712
|
* These helpers strip the secrets before anything is logged or re-thrown.
|
|
@@ -48724,14 +48726,48 @@ const SENSITIVE_KEYS = new Set([
|
|
|
48724
48726
|
'agenttoken',
|
|
48725
48727
|
'accesstoken',
|
|
48726
48728
|
'refreshtoken',
|
|
48729
|
+
'authtoken',
|
|
48730
|
+
'revoketoken',
|
|
48727
48731
|
'password',
|
|
48728
48732
|
'apikey',
|
|
48729
48733
|
'x-api-key',
|
|
48734
|
+
// Notification-channel write bodies (webhook auth, ServiceNow OAuth).
|
|
48735
|
+
'tokenvalue',
|
|
48736
|
+
'clientsecret',
|
|
48737
|
+
'client_secret',
|
|
48738
|
+
'certprivatekeybase64',
|
|
48730
48739
|
]);
|
|
48740
|
+
/**
|
|
48741
|
+
* Names that mark a credential where the name is data, not the object key: a
|
|
48742
|
+
* custom header inside a `headers` map (`X-Auth-Token`), or a name/value
|
|
48743
|
+
* property entry (`{ propertyName: 'ITSM_ServiceMgmt_Password', propertyValue }`
|
|
48744
|
+
* in a ServiceNow channel body).
|
|
48745
|
+
*/
|
|
48746
|
+
const SECRET_NAME = /authorization|token|secret|password|key|cookie/i;
|
|
48731
48747
|
/** Matches `Bearer <token>` anywhere in a string. */
|
|
48732
48748
|
const BEARER = /Bearer\s+\S+/gi;
|
|
48749
|
+
/** Matches a `"key": "value"` pair in JSON text, capturing the key and separator. */
|
|
48750
|
+
const JSON_STRING_PAIR = /"([^"\\]+)"(\s*:\s*)"(?:[^"\\]|\\.)*"/g;
|
|
48751
|
+
/**
|
|
48752
|
+
* axios serializes a request body to a JSON string before sending, so an error's
|
|
48753
|
+
* `config.data` is text, not an object — and the audit record carries the user
|
|
48754
|
+
* token in that body (#994). JSON text is parsed and redacted by key; text that
|
|
48755
|
+
* does not parse (truncated, embedded in a message) has its sensitive
|
|
48756
|
+
* `"key": "value"` pairs masked by pattern.
|
|
48757
|
+
*/
|
|
48733
48758
|
function redactString(value) {
|
|
48734
|
-
|
|
48759
|
+
const trimmed = value.trimStart();
|
|
48760
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
48761
|
+
try {
|
|
48762
|
+
return JSON.stringify(redactValue(JSON.parse(value)));
|
|
48763
|
+
}
|
|
48764
|
+
catch {
|
|
48765
|
+
// Not JSON — fall through to the pattern scrub.
|
|
48766
|
+
}
|
|
48767
|
+
}
|
|
48768
|
+
return value
|
|
48769
|
+
.replace(BEARER, `Bearer ${REDACTED}`)
|
|
48770
|
+
.replace(JSON_STRING_PAIR, (pair, key, separator) => SENSITIVE_KEYS.has(key.toLowerCase()) ? `"${key}"${separator}"${REDACTED}"` : pair);
|
|
48735
48771
|
}
|
|
48736
48772
|
/**
|
|
48737
48773
|
* Returns a deep copy of `value` with sensitive object keys masked and any
|
|
@@ -48758,18 +48794,39 @@ function redactValue(value, seen = new WeakSet()) {
|
|
|
48758
48794
|
stack: value.stack ? redactString(value.stack) : undefined,
|
|
48759
48795
|
};
|
|
48760
48796
|
}
|
|
48797
|
+
const record = value;
|
|
48798
|
+
const secretProperty = typeof record['propertyName'] === 'string' && SECRET_NAME.test(record['propertyName']);
|
|
48761
48799
|
const out = {};
|
|
48762
|
-
for (const [key, entry] of Object.entries(
|
|
48763
|
-
|
|
48764
|
-
|
|
48765
|
-
|
|
48800
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
48801
|
+
if (SENSITIVE_KEYS.has(key.toLowerCase())) {
|
|
48802
|
+
out[key] = REDACTED;
|
|
48803
|
+
}
|
|
48804
|
+
else if (secretProperty && key === 'propertyValue') {
|
|
48805
|
+
out[key] = REDACTED;
|
|
48806
|
+
}
|
|
48807
|
+
else if (key.toLowerCase() === 'headers' && entry && typeof entry === 'object') {
|
|
48808
|
+
out[key] = redactHeaders(entry, seen);
|
|
48809
|
+
}
|
|
48810
|
+
else {
|
|
48811
|
+
out[key] = redactValue(entry, seen);
|
|
48812
|
+
}
|
|
48813
|
+
}
|
|
48814
|
+
return out;
|
|
48815
|
+
}
|
|
48816
|
+
function redactHeaders(headers, seen) {
|
|
48817
|
+
if (Array.isArray(headers))
|
|
48818
|
+
return redactValue(headers, seen);
|
|
48819
|
+
const out = {};
|
|
48820
|
+
for (const [name, entry] of Object.entries(headers)) {
|
|
48821
|
+
out[name] = SECRET_NAME.test(name) ? REDACTED : redactValue(entry, seen);
|
|
48766
48822
|
}
|
|
48767
48823
|
return out;
|
|
48768
48824
|
}
|
|
48769
48825
|
/**
|
|
48770
48826
|
* Strips auth tokens from an (possibly Axios) error IN PLACE and returns it, so it
|
|
48771
48827
|
* stays a throwable `Error` with its stack intact but no longer carries the token
|
|
48772
|
-
* in `config.headers`, `
|
|
48828
|
+
* in `config.headers`, `config.data` (the request body), their `response.config`
|
|
48829
|
+
* copies, or the raw request header string.
|
|
48773
48830
|
* Non-error / non-axios values are returned unchanged.
|
|
48774
48831
|
*
|
|
48775
48832
|
* Use this at the axios boundary (a response error interceptor) so every catch,
|
|
@@ -48784,9 +48841,14 @@ function sanitizeAxiosError(err) {
|
|
|
48784
48841
|
return err;
|
|
48785
48842
|
if (e.config?.headers)
|
|
48786
48843
|
e.config.headers = redactValue(e.config.headers);
|
|
48844
|
+
if (e.config?.data !== undefined)
|
|
48845
|
+
e.config.data = redactValue(e.config.data);
|
|
48787
48846
|
if (e.response?.config?.headers) {
|
|
48788
48847
|
e.response.config.headers = redactValue(e.response.config.headers);
|
|
48789
48848
|
}
|
|
48849
|
+
if (e.response?.config?.data !== undefined) {
|
|
48850
|
+
e.response.config.data = redactValue(e.response.config.data);
|
|
48851
|
+
}
|
|
48790
48852
|
// Node's ClientRequest keeps the raw request (incl. the Authorization line) in `_header`.
|
|
48791
48853
|
if (e.request && typeof e.request._header === 'string') {
|
|
48792
48854
|
e.request._header = redactString(e.request._header);
|