Multiple distinct Content-Disposition headers received from server in Jasperreports

↘锁芯ラ 提交于 2019-12-05 06:30:57

Google Chrome might display this error message if you are downloading a file which has a comma in the file name. Were you really using just "report.pdf" as filename?

Having read the HTTP specs the Content-Disposition header (which is not part of the HTTP spec itself) should not include a comma character, because it will be treated as a separator for two different headers.

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.

So if your filename were report,May2014.pdf then Chrome interprets

Content-Disposition: attachment; filename=report,May2014.pdf

as two values for the same http message header

Content-Disposition: attachment; filename=report

Content-Disposition: May2014.pdf

which in turn is interpreted as a HTTP response splitting attack, probably because there shall actually be no multiple Content-Disposition header values in a single HTTP response.

Other browsers does not seem to mind the comma in the file name.

There is a similar discussion here - http://productforums.google.com/forum/#!topic/chrome/hhZh_kpei8U

See if that helps

Rubén R

Incorrect:

response.setHeader("Content-Disposition","attachment;filename="+filename+);

Correct:

response.setHeader("Content-Disposition","attachment;filename=\""+filename+"\"");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!