diff --git a/packages/debug/README.md b/packages/debug/README.md
index a4070b68..e64445cd 100644
--- a/packages/debug/README.md
+++ b/packages/debug/README.md
@@ -2,7 +2,7 @@
Prints logs and debug information to the console for an entity.
-Sensitive information (authentication) is replaced with ``
+⚠️ debug makes a best effort to replace sensitive information with `` but be careful not to share secrets when sharing logs.
## Install
diff --git a/packages/debug/index.js b/packages/debug/index.js
index 59a30957..0c182163 100644
--- a/packages/debug/index.js
+++ b/packages/debug/index.js
@@ -5,6 +5,7 @@ import clone from "ltx/lib/clone.js";
/* eslint no-console: 0 */
const NS_SASL = "urn:ietf:params:xml:ns:xmpp-sasl";
+const NS_SASL2 = "urn:xmpp:sasl:2";
const NS_COMPONENT = "jabber:component:accept";
const SENSITIVES = [
@@ -13,6 +14,8 @@ const SENSITIVES = [
["challenge", NS_SASL],
["response", NS_SASL],
["success", NS_SASL],
+ ["challenge", NS_SASL2],
+ ["response", NS_SASL2],
];
function isSensitive(element) {
@@ -22,17 +25,27 @@ function isSensitive(element) {
});
}
-export function hideSensitive(element) {
- if (isSensitive(element)) {
+function hide(element) {
+ if (element) {
element.children = [];
element.append(xml("hidden", { xmlns: "xmpp.js" }));
}
+}
+
+export function hideSensitive(element) {
+ if (isSensitive(element)) {
+ hide(element);
+ } else if (element.is("authenticate", NS_SASL2)) {
+ hide(element.getChild("initial-response"));
+ } else if (element.getNS() === NS_SASL2) {
+ hide(element.getChild("additional-data"));
+ }
return element;
}
function format(element) {
- return stringify(hideSensitive(clone(element), 2));
+ return stringify(hideSensitive(clone(element)), 2);
}
export default function debug(entity, force) {
diff --git a/packages/debug/test.js b/packages/debug/test.js
index 45453205..a701ffad 100644
--- a/packages/debug/test.js
+++ b/packages/debug/test.js
@@ -40,6 +40,62 @@ test("SASL", () => {
);
});
+test("SASL2", () => {
+ expect(
+ hideSensitive(
+
+
+ cD10bHMtZXhwb3J0ZXIsLG49dXNlcixyPTEyQzRDRDVDLUUzOEUtNEE5OC04RjZELTE1QzM4RjUxQ0NDNg==
+
+ ,
+ ),
+ ).toEqual(
+
+
+
+
+ ,
+ );
+
+ expect(
+ hideSensitive(
+
+ cj0xMkM0Q0Q1Qy1FMzhFLTRBOTgtOEY2RC0xNUMzOEY1MUNDQzZhMDkxMTdhNi1hYzUwLTRmMmYtOTNmMS05Mzc5OWMyYmRkZjYscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==
+ ,
+ ),
+ ).toEqual(
+
+
+ ,
+ );
+
+ expect(
+ hideSensitive(
+
+ Yz1jRDEwYkhNdFpYaHdiM0owWlhJc0xNY29Rdk9kQkRlUGQ0T3N3bG1BV1YzZGcxYTFXaDF0WVBUQndWaWQxMFZVLHI9MTJDNENENUMtRTM4RS00QTk4LThGNkQtMTVDMzhGNTFDQ0M2YTA5MTE3YTYtYWM1MC00ZjJmLTkzZjEtOTM3OTljMmJkZGY2LHA9VUFwbzd4bzZQYTlKK1ZhZWpmei9kRzdCb21VPQ==
+ ,
+ ),
+ ).toEqual(
+
+
+ ,
+ );
+
+ expect(
+ hideSensitive(
+
+ SSdtIGJvcmVkIG5vdy4=
+ ,
+ ),
+ ).toEqual(
+
+
+
+
+ ,
+ );
+});
+
test("component handshake", () => {
expect(
hideSensitive(foo),