Skip to content
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
22 changes: 17 additions & 5 deletions lib/common-templates/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ governing permissions and limitations under the License.
*
*/
function stringParameters (params) {
// hide authorization token without overriding params
let headers = params.__ow_headers || {}
if (headers.authorization) {
headers = { ...headers, authorization: '<hidden>' }
// shallow copy to not override first level references
const paramsShallowCopy = { ...params }
// hide credentials from the include-ims-credentials annotation without
// overriding fields in __ims_oauth_s2s
if (params.__ims_oauth_s2s?.client_secret) {
paramsShallowCopy.__ims_oauth_s2s = {
...params.__ims_oauth_s2s,
client_secret: '<hidden>'
}
}
// hide authorization token without overriding fields in __ow_headers
if (params.__ow_headers?.authorization) {
paramsShallowCopy.__ow_headers = {
...params.__ow_headers,
authorization: '<hidden>'
}
}
return JSON.stringify({ ...params, __ow_headers: headers })
return JSON.stringify(paramsShallowCopy)
}

/**
Expand Down
19 changes: 17 additions & 2 deletions lib/common-templates/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,25 @@ describe('stringParameters', () => {
})
test('with auth header', () => {
const params = {
a: 1, b: 2, __ow_headers: { 'x-api-key': 'fake-api-key', authorization: 'secret' }
a: 1, b: 2, __ow_headers: { 'x-api-key': 'fake-api-key', authorization: 'thesecret' }
}
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"authorization":"<hidden>"'))
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('secret'))
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
})
test('with ims credentials', () => {
const params = {
a: 1, b: 2, __ims_oauth_s2s: { client_id: 'fake-client-id', client_secret: 'thesecret', org_id: 'fake@AdobeOrg' }
}
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"client_secret":"<hidden>"'))
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
})
test('with ims credentials and authorization header', () => {
const params = {
a: 1, b: 2, __ims_oauth_s2s: { client_id: 'fake-client-id', client_secret: 'thesecret', org_id: 'fake@AdobeOrg' }, __ow_headers: { authorization: 'thesecret' }
}
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"client_secret":"<hidden>"'))
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"authorization":"<hidden>"'))
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
})
})

Expand Down