Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit a197043

Browse files
committed
fix(styles api): check custom preview file extension
1 parent e154638 commit a197043

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

api/styles.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,14 @@ function editStyle(req, res) {
192192

193193
if (customData.customPreview) {
194194
try {
195-
const previewURL = new URL(customData.customPreview);
196-
if (!previewURL.protocol.includes("https:")) {
195+
const previewUrl = new URL(customData.customPreview);
196+
const imagePattern = /\.(png|gif|jpg|svg|bmp|icns|ico|sketch)$/i;
197+
if (!previewUrl.protocol.includes("https:")) {
197198
return res.status(400).json({ error: "Preview must be from a secure source" });
198199
}
200+
if (!imagePattern.test(previewUrl.pathname)) {
201+
return res.status(415).json({ error: "Preview file must be an image" });
202+
}
199203
} catch (error) {
200204
return res.status(400).json({ error: "Invalid preview URL" });
201205
}

0 commit comments

Comments
 (0)