Skip to content

Commit f196723

Browse files
authored
Merge pull request #2203 from kleros/fix/allow-wildcard-mimetypes
fix: wildcard MIME types validation
2 parents 2946c1e + d266a61 commit f196723

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kleros-app/src/lib/atlas/providers/AtlasProvider.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,16 @@ export const AtlasProvider: React.FC<{ config: AtlasConfig; children?: React.Rea
281281
const restrictions = roleRestrictions.find((supportedRoles) => Roles[supportedRoles.name] === role);
282282

283283
if (!restrictions) throw new Error("Unsupported role.");
284-
if (!restrictions.restriction.allowedMimeTypes.includes(file.type)) throw new Error("Unsupported file type.");
284+
285+
const isValidMimeType = restrictions.restriction.allowedMimeTypes.some((allowedType) => {
286+
if (allowedType.endsWith("/*")) {
287+
const prefix = allowedType.replace("/*", "/");
288+
return file.type.startsWith(prefix);
289+
}
290+
return allowedType === file.type;
291+
});
292+
293+
if (!isValidMimeType) throw new Error("Unsupported file type.");
285294
if (file.size > restrictions.restriction.maxSize)
286295
throw new Error(
287296
`File too big. Max allowed size : ${(restrictions.restriction.maxSize / (1024 * 1024)).toFixed(2)} mb.`

0 commit comments

Comments
 (0)