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