Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Ensure JWT redaction for error messages #1768

Merged
merged 23 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
813f1e8
Revert "Add showWorkspaceFolderPick to AzExtUserInput"
MicroFish91 May 29, 2024
033006b
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 May 29, 2024
497b33d
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 May 31, 2024
6d410f5
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jun 3, 2024
76d1342
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jun 5, 2024
3a98aad
tMerge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jun 6, 2024
b4baf0f
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jul 5, 2024
5f9491f
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jul 8, 2024
992c318
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jul 9, 2024
81cc3b0
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Jul 25, 2024
a76bb12
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Aug 2, 2024
4cba67b
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Aug 5, 2024
5cc6088
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Aug 6, 2024
6d05c54
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools
MicroFish91 Aug 13, 2024
8e57b3b
Add jwt redactions from error messages
MicroFish91 Aug 13, 2024
4d08a67
Amend test message
MicroFish91 Aug 13, 2024
431f1e9
Don't make async
MicroFish91 Aug 14, 2024
3fca9d6
Add jwt comment
MicroFish91 Aug 14, 2024
86e8359
Improve comment some more
MicroFish91 Aug 14, 2024
e07cada
Merge branch 'main' of https://github.com/microsoft/vscode-azuretools…
MicroFish91 Aug 14, 2024
f64426c
Bump version
MicroFish91 Aug 14, 2024
462a1f0
Add empty payload jwt test
MicroFish91 Aug 14, 2024
55aed44
Improve comment
MicroFish91 Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions utils/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-utils",
"author": "Microsoft Corporation",
"version": "2.5.5",
"version": "2.5.6",
"description": "Common UI tools for developing Azure extensions for VS Code",
"tags": [
"azure",
Expand Down
4 changes: 4 additions & 0 deletions utils/src/masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export function maskUserInfo(unknownArg: unknown, actionValuesToMask: string[],
data = maskValue(data, value);
}

// Loose pattern matching to identify any JWT-like character sequences; prevents any accidental inclusions to telemetry
// The first and second JWT sections begin with "e" since the header and payload represent encoded json values that always begin with "{"
data = data.replace(/e[^\.\s]*\.e[^\.\s]*\.[^\.\s]+/gi, getRedactedLabel('jwt'));

if (!lessAggressive) {
data = data.replace(/\S+@\S+/gi, getRedactedLabel('email'));
data = data.replace(/\b[0-9a-f\-\:\.]{4,}\b/gi, getRedactedLabel('id')); // should cover guids, ip addresses, etc.
Expand Down
11 changes: 11 additions & 0 deletions utils/test/masking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ suite("masking", () => {
assert.strictEqual(maskUserInfo('pwd: "ddddddd!@#$%^&*()_+"', []), 'redacted:key');
});

test('jwt', () => {
const mockJwtOne: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
const mockJwtTwo: string = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkphbmUgRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.bmgFNnfHiZ1my09OnrZaconwIkp2RH94jjJWXavLTugEsxvwCM-3IJPakw7y5-3aLLZq1eA9NxEZK0a3ZjHc2A';
const mockEmptyPayloadJwt: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.Et9HFtf9R3GEMA0IICOfFMVXY7kkTX1wr4qCyhIf58U';

assert.strictEqual(maskUserInfo(`Bearer ${mockJwtOne}`, []), 'Bearer redacted:jwt');
assert.strictEqual(maskUserInfo(`Empty payload jwt: ${mockEmptyPayloadJwt}`, []), 'Empty payload jwt: redacted:jwt');
assert.strictEqual(maskUserInfo(`redacted:url ${mockJwtTwo}`, []), 'redacted:url redacted:jwt');
assert.strictEqual(maskUserInfo(`This message references two jwt's: ${mockJwtOne} and ${mockJwtTwo}.`, []), 'This message references two jwt\'s: redacted:jwt and redacted:jwt.');
});

test('lessAggressive', async () => {
const valueToMask = 'valueToMask';
assert.strictEqual(maskUserInfo('https://microsoft.com c35d6342-5917-46f8-953e-9d3faffd1c72 hello@world accountkey=1234 valueToMask', [valueToMask], true /* lessAggressive */), 'redacted:url c35d6342-5917-46f8-953e-9d3faffd1c72 hello@world redacted:key ---');
Expand Down
Loading