Skip to content

Commit b858037

Browse files
Merge pull request #4854 from Countly/SER-1096
[SER-1096] Checksum not working for form data
2 parents 9a1cc48 + 442769d commit b858037

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

api/api.js

100644100755
+18-2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ plugins.connectToAllDatabases().then(function() {
348348
req.body += data;
349349
});
350350

351+
let multiFormData = false;
352+
// Check if we have 'multipart/form-data'
353+
if (req.headers['content-type']?.startsWith('multipart/form-data')) {
354+
multiFormData = true;
355+
}
356+
351357
form.parse(req, (err, fields, files) => {
352358
//handle bakcwards compatability with formiddble v1
353359
for (let i in files) {
@@ -362,8 +368,18 @@ plugins.connectToAllDatabases().then(function() {
362368
}
363369
}
364370
params.files = files;
365-
for (const i in fields) {
366-
params.qstring[i] = fields[i];
371+
if (multiFormData) {
372+
let formDataUrl = [];
373+
for (const i in fields) {
374+
params.qstring[i] = fields[i];
375+
formDataUrl.push(`${i}=${fields[i]}`);
376+
}
377+
params.formDataUrl = formDataUrl.join('&');
378+
}
379+
else {
380+
for (const i in fields) {
381+
params.qstring[i] = fields[i];
382+
}
367383
}
368384
if (!params.apiPath) {
369385
processRequest(params);

api/utils/requestProcessor.js

100644100755
+7-1
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,13 @@ const checksumSaltVerification = (params) => {
30983098
payloads.push(params.href.substr(params.fullPath.length + 1));
30993099

31003100
if (params.req.method.toLowerCase() === 'post') {
3101-
payloads.push(params.req.body);
3101+
// Check if we have 'multipart/form-data'
3102+
if (params.formDataUrl) {
3103+
payloads.push(params.formDataUrl);
3104+
}
3105+
else {
3106+
payloads.push(params.req.body);
3107+
}
31023108
}
31033109
if (typeof params.qstring.checksum !== "undefined") {
31043110
for (let i = 0; i < payloads.length; i++) {

0 commit comments

Comments
 (0)