Skip to content

Commit 2330f0e

Browse files
authored
fix: hide new include-ims-annotation secrets (#83)
* fix: hide new include-ims-annotation secrets * fix review comments * add a test
1 parent 21896de commit 2330f0e

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

lib/common-templates/utils.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ governing permissions and limitations under the License.
2424
*
2525
*/
2626
function stringParameters (params) {
27-
// hide authorization token without overriding params
28-
let headers = params.__ow_headers || {}
29-
if (headers.authorization) {
30-
headers = { ...headers, authorization: '<hidden>' }
27+
// shallow copy to not override first level references
28+
const paramsShallowCopy = { ...params }
29+
// hide credentials from the include-ims-credentials annotation without
30+
// overriding fields in __ims_oauth_s2s
31+
if (params.__ims_oauth_s2s?.client_secret) {
32+
paramsShallowCopy.__ims_oauth_s2s = {
33+
...params.__ims_oauth_s2s,
34+
client_secret: '<hidden>'
35+
}
36+
}
37+
// hide authorization token without overriding fields in __ow_headers
38+
if (params.__ow_headers?.authorization) {
39+
paramsShallowCopy.__ow_headers = {
40+
...params.__ow_headers,
41+
authorization: '<hidden>'
42+
}
3143
}
32-
return JSON.stringify({ ...params, __ow_headers: headers })
44+
return JSON.stringify(paramsShallowCopy)
3345
}
3446

3547
/**

lib/common-templates/utils.test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,25 @@ describe('stringParameters', () => {
5555
})
5656
test('with auth header', () => {
5757
const params = {
58-
a: 1, b: 2, __ow_headers: { 'x-api-key': 'fake-api-key', authorization: 'secret' }
58+
a: 1, b: 2, __ow_headers: { 'x-api-key': 'fake-api-key', authorization: 'thesecret' }
5959
}
6060
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"authorization":"<hidden>"'))
61-
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('secret'))
61+
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
62+
})
63+
test('with ims credentials', () => {
64+
const params = {
65+
a: 1, b: 2, __ims_oauth_s2s: { client_id: 'fake-client-id', client_secret: 'thesecret', org_id: 'fake@AdobeOrg' }
66+
}
67+
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"client_secret":"<hidden>"'))
68+
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
69+
})
70+
test('with ims credentials and authorization header', () => {
71+
const params = {
72+
a: 1, b: 2, __ims_oauth_s2s: { client_id: 'fake-client-id', client_secret: 'thesecret', org_id: 'fake@AdobeOrg' }, __ow_headers: { authorization: 'thesecret' }
73+
}
74+
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"client_secret":"<hidden>"'))
75+
expect(utils.stringParameters(params)).toEqual(expect.stringContaining('"authorization":"<hidden>"'))
76+
expect(utils.stringParameters(params)).not.toEqual(expect.stringContaining('thesecret'))
6277
})
6378
})
6479

0 commit comments

Comments
 (0)