Filter out non-printable characters, control characters and ZWNBSP character from the response body (#2346)

* fix(#1003): content type for client_credentials & password grant types

* feature(#1003): added client is & secret for password credentials grant type

* fix: filter out non-printable control character and ZWNBSP character

* fix: filter out non-printable control character and ZWNBSP character
This commit is contained in:
lohit 2024-05-22 14:16:09 +05:30 committed by GitHub
parent f05389ca72
commit e56fb74801
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -265,7 +265,9 @@ const parseDataFromResponse = (response) => {
let data = dataBuffer.toString(charset || 'utf-8');
// Try to parse response to JSON, this can quietly fail
try {
data = JSON.parse(response.data);
// Filter out control characters and ZWNBSP character
data = data.replace(/[\x00-\x08\x0E-\x1F\x7F\uFEFF]/g, '');
data = JSON.parse(data);
} catch {}
return { data, dataBuffer };

View File

@ -0,0 +1,11 @@
meta {
name: echo bom json
type: http
seq: 1
}
get {
url: {{host}}/api/echo/bom-json-test
body: none
auth: none
}

View File

@ -19,4 +19,16 @@ router.post('/xml-raw', (req, res) => {
return res.send(req.rawBody);
});
router.get('/bom-json-test', (req, res) => {
const jsonData = {
message: 'Hello!',
success: true
};
const jsonString = JSON.stringify(jsonData);
const bom = '\uFEFF';
const jsonWithBom = bom + jsonString;
res.set('Content-Type', 'application/json; charset=utf-8');
return res.send(jsonWithBom);
});
module.exports = router;