elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.64k stars 8.23k forks source link

CSV export crashes on download when query contains non-ascii character in query name (TypeError [ERR_INVALID_CHAR]: Invalid character in header content content-disposition) #34729

Closed Mekk closed 4 years ago

Mekk commented 5 years ago

Kibana version: 6.6.2

Describe the bug:

Attempt to make CSV export from query which has non-ascii (in my case: Polish accented) character in it's name results in report which generates Internal Server Error on download.

According to logs content dispositon header is incorrectly generated - from kibana.log:

{"type":"error","@timestamp":"2019-04-08T16:44:29Z","tags":[],"pid":11689,"level":"error","error":{"message":"Invalid character in header content [\"content-disposition\"]","name":"TypeError [ERR_INVALID_CHAR]","stack":"TypeError [ERR_INVALID_CHAR]: Invalid character in header content [\"content-disposition\"]\n    at ServerResponse.setHeader (_http_outgoing.js:473:3)\n    at Object.internals.writeHead (/usr/share/kibana/node_modules/hapi/lib/transmit.js:323:21)\n    at Object.internals.transmit (/usr/share/kibana/node_modules/hapi/lib/transmit.js:105:15)\n    at Object.exports.send (/usr/share/kibana/node_modules/hapi/lib/transmit.js:32:25)","code":"ERR_INVALID_CHAR"},"url":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":{},"pathname":"/api/reporting/jobs/download/ju8kr2up090p3a601c5zcfyy","path":"/api/reporting/jobs/download/ju8kr2up090p3a601c5zcfyy","href":"/api/reporting/jobs/download/ju8kr2up090p3a601c5zcfyy"},"message":"Invalid character in header content [\"content-disposition\"]"}
{"type":"response","@timestamp":"2019-04-08T16:44:29Z","tags":["api"],"pid":11689,"method":"get","statusCode":500,"req":{"url":"/api/reporting/jobs/download/ju8kr2up090p3a601c5zcfyy","method":"get","headers":{"connection":"Keep-Alive","proxy-connection":"Keep-Alive","host":"kibana","user-agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","accept-language":"pl,en-US;q=0.7,en;q=0.3","accept-encoding":"gzip, deflate","referer":"http://cauchy.softax.local:90/app/kibana","upgrade-insecure-requests":"1"},"remoteAddress":"127.0.0.1","userAgent":"127.0.0.1","referer":"http://cauchy.softax.local:90/app/kibana"},"res":{"statusCode":500,"responseTime":8,"contentLength":9},"message":"GET /api/reporting/jobs/download/ju8kr2up090p3a601c5zcfyy 500 8ms - 9.0B"}

Steps to reproduce:

  1. Define some query and save it using non-english accented character in the query name. In my case I observed problem while exporting queries named Niedawne ślady or Wyszukiwanie błędu, where presence of letters like ś, ł or ę triggers the problem, but i also googled some chinese page mentioning the same error: https://elasticsearch.cn/question/7213 )

  2. Click Share / CSV Reports / Generate CSV

  3. Try downloading the report (from popup notification or from Management/Reporting)

As a result, I get

{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"}

on every download attempt.

Changing query name to ascii-only resolves the issue.

Expected behavior:

Allow proper download whatever the query name is. This probably means escaping or mayhaps ASCII-izing Content disposition header.

Mekk commented 5 years ago

Naively grep-ping around the code, I suppose this function may be related to the problem: https://github.com/elastic/kibana/blob/7a8301e43bee0ff9cab88b39147365f33c5a4501/x-pack/plugins/reporting/server/routes/lib/get_document_payload.ts#L29 (probably title can't be used as filename straight away)

Mekk commented 5 years ago

I just upgraded to kibana 7.0.0 and it seems that the problem is resolved, I generated some reports with ąęł in name and they download properly.

So this case can be closed (maybe it would make sense to verify whether there exist some testcase for the behaviour).

sugimoccos commented 5 years ago

I think the problem is still there. Kibana version:

Steps to reproduce: After saving search with japanese title such as "csvテスト", 500 error would appear in the download response.

elasticmachine commented 4 years ago

Pinging @elastic/kibana-reporting-services (Team:Reporting Services)

tsullivan commented 4 years ago

I checked in 7.8.1 and can not reproduce this issue. If this needs to be re-opened, let's get more details about the server OS.

Mekk commented 1 year ago

I just observed this problem in Kibana 8.6.2:

Changing query name helps (after renaming query to Podglad zlozonych zlecen everything works fine).

Mekk commented 1 year ago

Not sure whether it is relevant, but kibana runs on Debian 9.13 and system is generally set to en_US.UTF-8 locale.