Skip to content

settings/tokens: Delete plaintext tokens from memory after leaving API tokens settings page #6363

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

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions app/routes/settings/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ export default class TokenSettingsRoute extends AuthenticatedRoute {
let apiTokens = await this.store.findAll('api-token');
return TrackedArray.from(apiTokens.slice());
}

/**
* Ensure that all plaintext tokens are deleted from memory after leaving
* the API tokens settings page.
*/
resetController(controller) {
for (let token of controller.model) {
if (token.token) {
token.token = undefined;
}
}
}
}
19 changes: 19 additions & 0 deletions tests/acceptance/api-token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ module('Acceptance | api-tokens', function (hooks) {
assert.dom('[data-test-token]').hasText(token.token);
});

test('API tokens are only visible in plaintext until the page is left', async function (assert) {
prepare(this);

await visit('/settings/tokens');
await click('[data-test-new-token-button]');
await fillIn('[data-test-focused-input]', 'the new token');
await click('[data-test-save-token-button]');

let token = this.server.schema.apiTokens.findBy({ name: 'the new token' });
assert.dom('[data-test-token]').hasText(token.token);

// leave the API tokens page
await visit('/settings');

// and visit it again
await visit('/settings/tokens');
assert.dom('[data-test-token]').doesNotExist();
});

test('navigating away while creating a token does not keep it in the list', async function (assert) {
prepare(this);

Expand Down