Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/plane/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ def _retention_days(env_var, default):
"text/css",
"text/javascript",
"application/json",
"application/yaml",
"text/xml",
"text/csv",
"application/xml",
Expand Down
4 changes: 3 additions & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"scripts": {
"build": "tsdown",
"dev": "tsdown --watch --no-clean",
"test": "vitest run",
"check:lint": "oxlint --max-warnings=6 .",
"check:types": "tsc --noEmit",
"check:format": "oxfmt --check .",
Expand All @@ -30,6 +31,7 @@
"devDependencies": {
"@plane/typescript-config": "workspace:*",
"tsdown": "catalog:",
"typescript": "catalog:"
"typescript": "catalog:",
"vitest": "catalog:"
}
}
48 changes: 48 additions & 0 deletions packages/services/src/file/helper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/

import { describe, expect, it, vi } from "vitest";

import { getFileMetaDataForUpload } from "./helper";

const metadata = (name: string, type = "", contents: BlobPart[] = ["key: value"]) =>
getFileMetaDataForUpload(new File(contents, name, { type }));

describe("getFileMetaDataForUpload", () => {
it.each([
["program.txt", "text/plain"],
["program.md", "text/markdown"],
["program.markdown", "text/markdown"],
["program.csv", "text/csv"],
["program.yaml", "application/yaml"],
["program.yml", "application/yaml"],
])("detects %s without browser MIME", async (name, expected) => {
expect((await metadata(name)).type).toBe(expected);
});

it("falls back to browser MIME", async () => {
expect((await metadata("program.log", "text/plain")).type).toBe("text/plain");
});

it("prefers signature detection", async () => {
const pngHeader = new Uint8Array([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, 0x89,
]);

expect((await metadata("image.yaml", "application/yaml", [pngHeader])).type).toBe("image/png");
});

it("does not apply fallback to an unsafe filename", async () => {
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);

try {
expect((await metadata("payload.exe.yaml")).type).toBe("");
} finally {
warnSpy.mockRestore();
}
});
});
14 changes: 12 additions & 2 deletions packages/services/src/file/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import { fileTypeFromBuffer } from "file-type";
import type { TFileMetaDataLite, TFileSignedURLResponse } from "@plane/types";
import { DANGEROUS_EXTENSIONS } from "@plane/constants";

const TEXT_MIME_TYPES_BY_EXTENSION: Record<string, string> = {
txt: "text/plain",
md: "text/markdown",
markdown: "text/markdown",
csv: "text/csv",
yaml: "application/yaml",
yml: "application/yaml",
};

/**
* @description Filename validation - checks for double extensions and dangerous patterns
* @param {string} filename
Expand Down Expand Up @@ -92,6 +101,7 @@ const validateAndDetectFileType = async (file: File): Promise<string> => {
const filenameError = validateFilename(file.name);
if (filenameError) {
console.warn(`File validation warning: ${filenameError}`);
return "";
}

try {
Expand All @@ -103,8 +113,8 @@ const validateAndDetectFileType = async (file: File): Promise<string> => {
console.warn("Error detecting file type from signature:", _error);
}

// fallback for unknown files
return "";
const extension = file.name.split(".").pop()?.toLowerCase() ?? "";
return TEXT_MIME_TYPES_BY_EXTENSION[extension] || file.type || "";
};

/**
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.