Skip to content

Commit 98ff1e3

Browse files
hugopeixotogr2m
authored andcommitted
fix: do not uppercase quoted escape sequences (#96)
If the payload contains text that starts with "\u", the replacer kicks in and signature validation fails.
1 parent 02a41a6 commit 98ff1e3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sign/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function sign (secret, payload) {
1212
}
1313

1414
function toNormalizedJsonString (payload) {
15-
return JSON.stringify(payload).replace(/\\u[\da-f]{4}/g, s => {
16-
return s.substr(0, 2) + s.substr(2).toUpperCase()
15+
return JSON.stringify(payload).replace(/[^\\]\\u[\da-f]{4}/g, s => {
16+
return s.substr(0, 3) + s.substr(3).toUpperCase()
1717
})
1818
}

test/integration/verify-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ test('verify(secret, eventPayload, signature) returns true if eventPayload conta
5959
foo: 'Foo\n\u001B[34mbar: ♥♥♥♥♥♥♥♥\nthis-is-lost\u001B[0m\u001B[2K'
6060
}, 'sha1=7316ec5e7866e42e4aba4af550d21a5f036f949d')
6161
t.is(signatureMatchesUpperCaseSequence, true)
62+
const signatureMatchesEscapedSequence = verify('development', {
63+
foo: '\\u001b'
64+
}, 'sha1=2c440a176f4cb84c8c921dfee882d594c2465097')
65+
t.is(signatureMatchesEscapedSequence, true)
6266

6367
t.end()
6468
})

0 commit comments

Comments
 (0)