I have the following problem: When a client enters a certain URL it receives an .mp3 file back via sendFile() from Express. The name of the file is defined in the response header as follow:
var fileName = (JSON.stringify(data.videoTitle).replace(/["']/g, "") + fileType);
headers: {
'x-timestamp': Date.now(),
'x-sent': true,
'Content-type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename="' + fileName + '"'
}
The problem is that fileName is fetched from another website and I have no control over what the title of the file will be. So far it was no problem but it just happened to me that a file contained the character ú which lead to the following error:
throw new TypeError('The header content contains invalid characters');
This could potentially happen very often as there are many characters that the headers might not like. Is there any possibility that I only keep valid characters before setting the header? I assume a whitelist approach would be better than a blacklist approach as there are nearly infinite possibilities of invalid characters.
Thank you very much in advance