Skip to content

Conversation

@nishizoe
Copy link
Contributor

@nishizoe nishizoe commented Sep 5, 2016

@upsilon upsilon added this to the master milestone Sep 7, 2016
…... にURL エンコードされた UTF-8 のファイル名 を設定するよう修正
$original_filename = str_replace(array("\r", "\n"), '', $original_filename);
$filename = str_replace(array("\r", "\n"), '', $filename);

$encoded_filename = rawurlencode($original_filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$encoded_filename について、ファイル名に含まれる改行文字が除去されていません。header 関数に渡す文字列に改行文字を許容すると HTTP ヘッダインジェクションが可能になる場合があるため、$filename$encoded_filename の両方とも改行文字が含まれないように修正して下さい。
参考: http://blog.tokumaru.org/2015/12/phphttp.html

Copy link
Member

@upsilon upsilon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IE8 での挙動について、filename に URL エンコードされた UTF-8 の文字列を渡すことでマルチバイト文字を含むファイル名でも文字化けせずに表示されることを確認したため、Content-Disposition ヘッダについてはリクエストの User-Agent に関わらず常に下記のようなヘッダを返すように修正して下さい。

Content-Disposition: attachment; filename="%E6%97%A5%E6%9C%AC%E8%AA%9E.txt"; filename*=utf-8''%E6%97%A5%E6%9C%AC%E8%AA%9E.txt

@upsilon upsilon changed the base branch from master to old-master March 15, 2017 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants