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

fix(logs/azure): redact sensitive header when DEBUG is set #1218

Merged
merged 19 commits into from
Jan 13, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update lint
minhanh-phan committed Dec 11, 2024

Verified

This commit was signed with the committer’s verified signature.
commit f3d685567e1cd0150638a816a827347d25ab0ae9
10 changes: 5 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1150,20 +1150,20 @@ export function debug(action: string, ...args: any[]) {
const modifiedArg = { ...arg };
// Check for sensitive headers in request body 'headers' object
if (modifiedArg['headers']) {
for (const header in modifiedArg['headers']){
if (SENSITIVE_HEADERS.has(header.toLowerCase())){
for (const header in modifiedArg['headers']) {
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
modifiedArg['headers'][header] = 'REDACTED';
}
}
}
// Check for sensitive headers in headers object
for (const header in modifiedArg){
if (SENSITIVE_HEADERS.has(header.toLowerCase())){
for (const header in modifiedArg) {
if (SENSITIVE_HEADERS.has(header.toLowerCase())) {
modifiedArg[header] = 'REDACTED';
}
}
return modifiedArg;
})
});
console.log(`OpenAI:DEBUG:${action}`, ...modifiedArgs);
}
}
41 changes: 20 additions & 21 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -419,52 +419,51 @@ describe('Debug', () => {
beforeEach(() => {
jest.resetModules();
process.env = { ...env };
process.env['DEBUG']= 'true';
process.env['DEBUG'] = 'true';
});

afterEach(() => {
process.env = env;
});

test('body request object with Authorization header', function(){
test('body request object with Authorization header', function () {
// Test request body includes headers object with Authorization
const headersTest = {
headers: {
Authorization: 'fakeAuthorization'
}
}
Authorization: 'fakeAuthorization',
},
};
debug('request', headersTest);
expect(spy).toHaveBeenCalledWith('OpenAI:DEBUG:request', {
headers: {
Authorization: 'REDACTED'
}
Authorization: 'REDACTED',
},
});
});
test('body request object with api-key header', function(){

test('body request object with api-key header', function () {
// Test request body includes headers object with api-ley
const apiKeyTest = {
headers: {
'api-key': 'fakeKey'
}
}
'api-key': 'fakeKey',
},
};
debug('request', apiKeyTest);
expect(spy).toHaveBeenCalledWith('OpenAI:DEBUG:request', {
headers: {
'api-key': 'REDACTED'
}
'api-key': 'REDACTED',
},
});
});
test('header object with Authorization header', function(){

test('header object with Authorization header', function () {
// Test headers object with authorization header
const authorizationTest = {
authorization: 'fakeValue'
}
authorization: 'fakeValue',
};
debug('request', authorizationTest);
expect(spy).toHaveBeenCalledWith('OpenAI:DEBUG:request', {
authorization: 'REDACTED'
authorization: 'REDACTED',
});
});

});
});