fix(web): [backport][OCISDEV-1183] stop logging OAuth tokens to the browser console (#13244)
fix(web): [OCISDEV-1183] stop logging OAuth tokens to the browser console (#13233) * fix(web): [OCISDEV-1183] stop logging OAuth tokens to the browser console On every login and silent token renewal, the web client wrote the user's raw access and refresh tokens to the browser console via console.debug. The userLoaded handler now logs a static message without any token or user data. * docs: [OCISDEV-1183] add PR link to changelog --------- Signed-off-by: Gaurav Soni <sonigaurav119@gmail.com>
This commit is contained in:
1 parent
5de8529700
commit
9332ddcc67
3 files changed
+72
-3
No files matched your search
@@ -0,0 +1,16 @@
|
||||
Bugfix: Stop logging OAuth tokens to the browser console
|
||||
|
||||
On every login and every silent token renewal, the web client wrote the
|
||||
signed-in user's raw OAuth `access_token` and `refresh_token` to the browser
|
||||
console via a `console.debug` call in the `userLoaded` handler of the auth
|
||||
service. Anyone with access to that browser's console or log buffer - a
|
||||
malicious or over-permissioned browser extension, a shared or kiosk terminal,
|
||||
a screen share or recording, or a session-replay tool that captures console
|
||||
output - could read and reuse those live credentials. The production build
|
||||
does not strip `console.debug`, so this shipped in the deployed bundle, not
|
||||
just local dev.
|
||||
|
||||
The debug line now confirms that a new user was loaded without logging the
|
||||
token, profile, or any other user field.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/13233
|
||||
@@ -233,9 +233,7 @@ export class AuthService implements AuthServiceInterface {
|
||||
expiryThreshold: this.accessTokenExpiryThreshold
|
||||
})
|
||||
|
||||
console.debug(
|
||||
`New User Loaded. access_token: ${user.access_token}, refresh_token: ${user.refresh_token}`
|
||||
)
|
||||
console.debug('[authService:userLoaded] - new user loaded')
|
||||
try {
|
||||
await this.userManager.updateContext(user.access_token, fetchUserData)
|
||||
} catch (e) {
|
||||
|
||||
@@ -171,6 +171,61 @@ describe('AuthService', () => {
|
||||
|
||||
expect(mockUpdateContext).toHaveBeenCalledWith('access-token', true)
|
||||
})
|
||||
|
||||
it('does not log the access_token or refresh_token when a new user is loaded', async () => {
|
||||
const authService = new AuthService()
|
||||
const addUserLoadedMock = vi.fn()
|
||||
|
||||
Object.defineProperty(authService, 'userManager', {
|
||||
value: mock<UserManager>({
|
||||
getAccessToken: vi.fn().mockResolvedValue('access-token'),
|
||||
getUser: vi.fn().mockResolvedValue(mock<User>({ expires_in: 3600 })),
|
||||
updateContext: mockUpdateContext,
|
||||
areEventHandlersRegistered: false,
|
||||
events: mock<UserManager['events']>({
|
||||
addUserLoaded: addUserLoadedMock
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
initAuthService({ authService })
|
||||
|
||||
await authService.initializeContext(mock<RouteLocation>({}))
|
||||
|
||||
const userLoadedHandler = addUserLoadedMock.mock.calls[0][0]
|
||||
|
||||
const accessToken = 'distinctive-access-token-value'
|
||||
const refreshToken = 'distinctive-refresh-token-value'
|
||||
|
||||
const consoleSpies = {
|
||||
debug: vi.spyOn(console, 'debug').mockImplementation(() => {}),
|
||||
log: vi.spyOn(console, 'log').mockImplementation(() => {}),
|
||||
info: vi.spyOn(console, 'info').mockImplementation(() => {}),
|
||||
warn: vi.spyOn(console, 'warn').mockImplementation(() => {}),
|
||||
error: vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
}
|
||||
|
||||
try {
|
||||
await userLoadedHandler(
|
||||
mock<User>({
|
||||
access_token: accessToken,
|
||||
refresh_token: refreshToken,
|
||||
expires_in: 3600
|
||||
})
|
||||
)
|
||||
|
||||
const loggedValues = Object.values(consoleSpies)
|
||||
.flatMap((spy) => spy.mock.calls)
|
||||
.flat()
|
||||
|
||||
loggedValues.forEach((value) => {
|
||||
expect(String(value)).not.toContain(accessToken)
|
||||
expect(String(value)).not.toContain(refreshToken)
|
||||
})
|
||||
} finally {
|
||||
Object.values(consoleSpies).forEach((spy) => spy.mockRestore())
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('handleDelegatedTokenUpdate', () => {
|
||||
|
||||
Reference in new issue
Block a user