Skip to content

Commit 26edb76

Browse files
Merge pull request #5769 from Countly/SER-1568
[SER-1568] Exporting incoming data logs results in "Incorrect parameter \"data\" error
2 parents a800e0b + 7aea330 commit 26edb76

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Fixes:
33
- [script] Fixing bug with "delete_old_members" script that led to malformed requests
44
- [core] Fixed bug where changing passwords results in the loss of the "Global Admin" role
55
- [crash] Fixed bug in crash ingestion for scenarios where the "app version" is not a string.
6+
- [core] Fixed bug where exporting incoming data logs could result in "Incorrect parameter \"data\" error
67

78
## Version 24.05.17
89
Fixes:

plugins/logger/frontend/public/javascripts/countly.views.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,44 @@
130130
formatExportFunction: function() {
131131
var tableData = this.logsData;
132132
var table = [];
133+
var sanitizeQueryData = function(data) {
134+
try {
135+
// If data is already a string, parse it first
136+
let queryObject = typeof data === 'string' ? JSON.parse(data) : data;
137+
138+
// Handle nested JSON strings within the object
139+
Object.keys(queryObject).forEach(key => {
140+
if (typeof queryObject[key] === 'string') {
141+
// Try to parse if it looks like JSON
142+
if (queryObject[key].startsWith('{') || queryObject[key].startsWith('[')) {
143+
try {
144+
queryObject[key] = JSON.parse(queryObject[key]);
145+
if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
146+
queryObject[key] = sanitizeQueryData(queryObject[key]);
147+
}
148+
}
149+
catch (e) {
150+
// If parsing fails, keep decoded string
151+
}
152+
}
153+
queryObject[key] = countlyCommon.unescapeHtml(queryObject[key]);
154+
}
155+
else if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
156+
// Recursively handle nested objects
157+
Object.keys(queryObject[key]).forEach(nestedKey => {
158+
if (typeof queryObject[key][nestedKey] === 'string') {
159+
queryObject[key][nestedKey] = countlyCommon.unescapeHtml(queryObject[key][nestedKey]);
160+
}
161+
});
162+
}
163+
});
164+
return JSON.stringify(queryObject);
165+
}
166+
catch (err) {
167+
return data; // Return original data if processing fails
168+
}
169+
};
170+
133171
for (var i = 0; i < tableData.length; i++) {
134172
var item = {};
135173
item[CV.i18n('logger.requests').toUpperCase()] = countlyCommon.formatTimeAgoText(tableData[i].reqts).text;
@@ -152,16 +190,15 @@
152190
}
153191
if (tableData[i].q) {
154192
try {
155-
item[CV.i18n('logger.request-query').toUpperCase()] = JSON.stringify(tableData[i].q);
193+
item[CV.i18n('logger.request-query').toUpperCase()] = sanitizeQueryData(tableData[i].q);
156194
}
157195
catch (err) {
158196
item[CV.i18n('logger.request-header').toUpperCase()] = "-";
159197
}
160198
}
161199
if (tableData[i].h) {
162200
try {
163-
var stringifiedHeader = JSON.stringify(tableData[i].h);
164-
item["REQUEST HEADER"] = stringifiedHeader.replace(/&quot;/g, '"');
201+
item["REQUEST HEADER"] = sanitizeQueryData(tableData[i].h);
165202
}
166203
catch (err) {
167204
item["REQUEST HEADER"] = "-";

0 commit comments

Comments
 (0)