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: webhook validation with array parameter sorting Fixes #722 #723

Merged
merged 3 commits into from
Aug 26, 2022
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
1 change: 1 addition & 0 deletions lib/webhooks/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function removePort(parsedUrl) {
function toFormUrlEncodedParam(paramName, paramValue) {
if (paramValue instanceof Array) {
return paramValue
.sort()
.map(val => toFormUrlEncodedParam(paramName, val))
.reduce((acc, val) => acc + val, '');
}
Expand Down
8 changes: 8 additions & 0 deletions spec/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ describe('Request validation', () => {

expect(isValid).toBeTruthy();
});

it('should validate request body with an array parameter regardless of the position of values in the array', () => {
const paramsWithArray = { 'MessagingBinding.Address': ['+1415xxxxxxx', '+1325xxxxxxx'] };
const signature = '83O6e2vORAoJHUNzJjDWN1jz+BA=';
const isValid = validateRequest(token, signature, requestUrl, paramsWithArray);

expect(isValid).toBeTruthy();
});
});

describe('Request validation middleware', () => {
Expand Down