Serve attachments using URL-encoded relative paths
- Read attachment route paths without URI decoding before normalization - Align test fixture paths with encoded thread/message/file names
This commit is contained in:
1 parent
7d4b02689e
commit
3e99019af8
2 files changed
+4
-11
No files matched your search
@@ -492,9 +492,9 @@ describe("WebSocket Server", () => {
|
||||
const attachmentPath = path.join(
|
||||
stateDir,
|
||||
"attachments",
|
||||
"thread folder",
|
||||
"message folder",
|
||||
"file name.png",
|
||||
"thread%20folder",
|
||||
"message%20folder",
|
||||
"file%20name.png",
|
||||
);
|
||||
fs.mkdirSync(path.dirname(attachmentPath), { recursive: true });
|
||||
fs.writeFileSync(attachmentPath, Buffer.from("hello-encoded-attachment"));
|
||||
|
||||
@@ -251,14 +251,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
|
||||
if (url.pathname.startsWith(ATTACHMENTS_ROUTE_PREFIX)) {
|
||||
const attachmentsRoot = path.resolve(path.join(serverConfig.stateDir, "attachments"));
|
||||
const encodedRelativePath = url.pathname.slice(ATTACHMENTS_ROUTE_PREFIX.length);
|
||||
let rawRelativePath: string;
|
||||
try {
|
||||
rawRelativePath = decodeURIComponent(encodedRelativePath);
|
||||
} catch {
|
||||
respond(400, { "Content-Type": "text/plain" }, "Invalid attachment path");
|
||||
return;
|
||||
}
|
||||
const rawRelativePath = url.pathname.slice(ATTACHMENTS_ROUTE_PREFIX.length);
|
||||
const normalizedRelativePath = path.normalize(rawRelativePath).replace(/^[/\\]+/, "");
|
||||
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user