Skip to content

Commit 8faec23

Browse files
committed
refactor(security): obfuscate token only before debug logging
Ensure token obfuscation occurs just before emitting debug logs. This preserves the full token for request handling while keeping debug output secure by masking the token.
1 parent 3aabd94 commit 8faec23

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/clients/transporter.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,9 @@ const defaultTransportConfig = {
2424
},
2525
};
2626

27-
const obfuscateToken = (options) => {
28-
if (!options.token) return options;
29-
30-
return {
31-
...options,
32-
token: options.token.slice(0, 5) + '**********',
33-
};
34-
};
35-
3627
class Transporter {
3728
constructor(options, sideLoad = [], useDotJson = true) {
38-
this.options = obfuscateToken(options);
29+
this.options = options;
3930
this.sideLoad = sideLoad;
4031
this.useDotJson = useDotJson;
4132
this.authHandler = new AuthorizationHandler(this.options);
@@ -88,8 +79,16 @@ class Transporter {
8879
return this.sendRequest(options);
8980
}
9081

82+
obfuscateToken(options) {
83+
if (!options.token) return {...options};
84+
return {
85+
...options,
86+
token: options.token.slice(0, 5) + '**********',
87+
};
88+
}
89+
9190
async sendRequest(options) {
92-
this.emit('debug::request', options); // Emit before the request
91+
this.emit('debug::request', this.obfuscateToken(options)); // Emit before the request
9392

9493
const rawResponse = await this.transportFn(options.uri, options);
9594
const response = this.responseAdapter(rawResponse);

0 commit comments

Comments
 (0)