Skip to content

Commit ce8e4fc

Browse files
authored
improve anonymization for accountId (#2523)
* improve anonymization for accountId * PR feedback
1 parent 9dced46 commit ce8e4fc

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

.changeset/stupid-coats-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/platform-core': patch
3+
---
4+
5+
improve anonymization for accountId

packages/platform-core/src/usage-data/account_id_fetcher.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,27 @@ void describe('AccountIdFetcher', async () => {
4848
assert.strictEqual(mockSend.mock.callCount(), 1);
4949
mockSend.mock.resetCalls();
5050
});
51+
52+
void test('returns different account UUID based on account buckets', async () => {
53+
const mockSend = mock.method(STSClient.prototype, 'send', () =>
54+
Promise.resolve({
55+
Account: '123456789012',
56+
} as GetCallerIdentityCommandOutput)
57+
);
58+
59+
// different accountIdFetcher to avoid returning cached account UUID
60+
const accountIdFetcher1 = new AccountIdFetcher(new STSClient({}));
61+
const accountIdFetcher2 = new AccountIdFetcher(new STSClient({}));
62+
63+
const accountId1 = await accountIdFetcher1.fetch();
64+
mock.method(STSClient.prototype, 'send', () =>
65+
Promise.resolve({
66+
Account: '123456789901', // should fall in different account id bucket
67+
} as GetCallerIdentityCommandOutput)
68+
);
69+
const accountId2 = await accountIdFetcher2.fetch();
70+
71+
assert.notStrictEqual(accountId1, accountId2);
72+
mockSend.mock.resetCalls();
73+
});
5174
});

packages/platform-core/src/usage-data/account_id_fetcher.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ export class AccountIdFetcher {
2424
new GetCallerIdentityCommand({})
2525
);
2626
if (stsResponse && stsResponse.Account) {
27-
const accountIdBucket = Number(stsResponse.Account) / 100;
28-
this.accountId = uuidV5(
29-
accountIdBucket.toString(),
30-
AMPLIFY_CLI_UUID_NAMESPACE
31-
);
27+
const accountIdBucket = stsResponse.Account.slice(0, -2);
28+
this.accountId = uuidV5(accountIdBucket, AMPLIFY_CLI_UUID_NAMESPACE);
3229
return this.accountId;
3330
}
3431
// We failed to get the account Id. Most likely the user doesn't have credentials

0 commit comments

Comments
 (0)