fix(06.2): CR-06 RFC 5987-encode Content-Disposition filename to prevent header injection
This commit is contained in:
@@ -21,6 +21,7 @@ to all handlers. The doc.user_id=None guard in /confirm is a Wave 2 placeholder.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import urllib.parse
|
||||||
import uuid
|
import uuid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -786,9 +787,10 @@ async def stream_document_content(
|
|||||||
) from exc
|
) from exc
|
||||||
file_size = len(file_bytes)
|
file_size = len(file_bytes)
|
||||||
|
|
||||||
|
safe_name = urllib.parse.quote(doc.filename, safe='')
|
||||||
headers = {
|
headers = {
|
||||||
"content-type": doc.content_type,
|
"content-type": doc.content_type,
|
||||||
"content-disposition": f'inline; filename="{doc.filename}"',
|
"content-disposition": f"inline; filename*=UTF-8''{safe_name}",
|
||||||
"accept-ranges": "bytes",
|
"accept-ranges": "bytes",
|
||||||
"content-length": str(file_size),
|
"content-length": str(file_size),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user