mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
fix(backend): mask jwt token in log (#8737)
This commit is contained in:
parent
c9b429878a
commit
8ae4e309c3
@ -61,7 +61,7 @@ describe('apollo logger', () => {
|
||||
})
|
||||
|
||||
describe('login mutation', () => {
|
||||
it('logs the request and response', async () => {
|
||||
it('logs the request and response, masking password and token', async () => {
|
||||
await mutate({
|
||||
mutation: loginMutation,
|
||||
variables: {
|
||||
@ -81,7 +81,7 @@ describe('apollo logger', () => {
|
||||
}),
|
||||
)
|
||||
|
||||
expect(loggerSpy).toBeCalledWith('Apollo Response', expect.any(String), expect.any(String))
|
||||
expect(loggerSpy).toBeCalledWith('Apollo Response', expect.any(String), '{"login":"token"}')
|
||||
|
||||
expect(consoleSpy).toBeCalledTimes(2)
|
||||
})
|
||||
|
||||
@ -30,7 +30,14 @@ export const loggerPlugin = {
|
||||
ocelotLogger.error(...logResponse, JSON.stringify(requestContext.errors))
|
||||
return
|
||||
}
|
||||
if (requestContext.response.data.login) {
|
||||
// mask the token
|
||||
const data = cloneDeep(requestContext.response.data)
|
||||
data.login = 'token'
|
||||
logResponse.push(JSON.stringify(data))
|
||||
} else {
|
||||
logResponse.push(JSON.stringify(requestContext.response.data))
|
||||
}
|
||||
ocelotLogger.debug(...logResponse)
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user