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

[SER-1568] Exporting incoming data logs results in "Incorrect parameter \"data\" error #5769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 40 additions & 3 deletions plugins/logger/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,44 @@
formatExportFunction: function() {
var tableData = this.logsData;
var table = [];
var sanitizeQueryData = function(data) {
try {
// If data is already a string, parse it first
let queryObject = typeof data === 'string' ? JSON.parse(data) : data;

// Handle nested JSON strings within the object
Object.keys(queryObject).forEach(key => {
if (typeof queryObject[key] === 'string') {
// Try to parse if it looks like JSON
if (queryObject[key].startsWith('{') || queryObject[key].startsWith('[')) {
try {
queryObject[key] = JSON.parse(queryObject[key]);
if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
queryObject[key] = sanitizeQueryData(queryObject[key]);
}
}
catch (e) {
// If parsing fails, keep decoded string
}
}
queryObject[key] = countlyCommon.unescapeHtml(queryObject[key]);
}
else if (typeof queryObject[key] === 'object' && queryObject[key] !== null) {
// Recursively handle nested objects
Object.keys(queryObject[key]).forEach(nestedKey => {
if (typeof queryObject[key][nestedKey] === 'string') {
queryObject[key][nestedKey] = countlyCommon.unescapeHtml(queryObject[key][nestedKey]);
}
});
}
});
return JSON.stringify(queryObject);
}
catch (err) {
return data; // Return original data if processing fails
}
};

for (var i = 0; i < tableData.length; i++) {
var item = {};
item[CV.i18n('logger.requests').toUpperCase()] = countlyCommon.formatTimeAgoText(tableData[i].reqts).text;
Expand All @@ -152,16 +190,15 @@
}
if (tableData[i].q) {
try {
item[CV.i18n('logger.request-query').toUpperCase()] = JSON.stringify(tableData[i].q);
item[CV.i18n('logger.request-query').toUpperCase()] = sanitizeQueryData(tableData[i].q);
}
catch (err) {
item[CV.i18n('logger.request-header').toUpperCase()] = "-";
}
}
if (tableData[i].h) {
try {
var stringifiedHeader = JSON.stringify(tableData[i].h);
item["REQUEST HEADER"] = stringifiedHeader.replace(/&quot;/g, '"');
item["REQUEST HEADER"] = sanitizeQueryData(tableData[i].h);
}
catch (err) {
item["REQUEST HEADER"] = "-";
Expand Down
Loading