Skip to content

Commit f19e76f

Browse files
committed
adds file extension blacklist logic
1 parent 7c806e0 commit f19e76f

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

api/src/controllers/torrent.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ export const uploadTorrent = async (req, res, next) => {
9797
];
9898
}
9999

100+
const hasBlackListedFiles = files.some((file) =>
101+
(process.env.SQ_EXTENSION_BLACKLIST ?? []).some((ext) =>
102+
file.path.endsWith(`.${ext}`)
103+
)
104+
);
105+
106+
if (hasBlackListedFiles) {
107+
res
108+
.status(403)
109+
.send("One or more files have blacklisted file extensions");
110+
return;
111+
}
112+
100113
let groupId;
101114

102115
if (req.body.groupWith) {

api/src/utils/validateConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const configSchema = yup
4949
text: yup.string().matches(hexRegex),
5050
grey: yup.string().matches(hexRegex),
5151
}),
52+
SQ_EXTENSION_BLACKLIST: yup.array().of(yup.string()).min(0),
5253
SQ_BASE_URL: yup.string().matches(httpRegex).required(),
5354
SQ_API_URL: yup.string().matches(httpRegex).required(),
5455
SQ_MONGO_URL: yup.string().matches(mongoRegex).required(),

client/pages/upload.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const FileUpload = styled(Box)(() =>
3333
borderColor: "border",
3434
borderRadius: 2,
3535
cursor: "pointer",
36-
p: 5,
36+
p: 6,
3737
"&:hover": {
3838
bg: "sidebar",
3939
},
@@ -191,6 +191,7 @@ const Upload = ({ token, userId }) => {
191191
SQ_API_URL,
192192
SQ_TORRENT_CATEGORIES,
193193
SQ_ALLOW_ANONYMOUS_UPLOAD,
194+
SQ_EXTENSION_BLACKLIST,
194195
},
195196
} = getConfig();
196197

@@ -322,6 +323,26 @@ const Upload = ({ token, userId }) => {
322323
</Text>
323324
</Text>
324325
</Box>
326+
{!!SQ_EXTENSION_BLACKLIST.length && (
327+
<Infobox mb={5}>
328+
<Text mb={3}>
329+
The following file extensions are blacklisted. Any torrent
330+
containing files of these types will not be uploaded.
331+
</Text>
332+
<Text
333+
fontFamily="mono"
334+
display="inline-block"
335+
bg="background"
336+
border="1px solid"
337+
borderColor="border"
338+
borderRadius={1}
339+
px={3}
340+
py={1}
341+
>
342+
{SQ_EXTENSION_BLACKLIST.join(", ")}
343+
</Text>
344+
</Infobox>
345+
)}
325346
<form onSubmit={handleUpload}>
326347
<Box mb={4}>
327348
<WrapLabel label="Torrent file" as="div">

config.example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ module.exports = {
7070
// Enable if you want torrents to be indexed to help search traffic.
7171
SQ_ALLOW_UNREGISTERED_VIEW: false,
7272

73+
// An array of blacklisted file extensions. Torrents containing files with these extensions will fail to upload.
74+
SQ_EXTENSION_BLACKLIST: ["exe"],
75+
7376
// The URL of your tracker site.
7477
SQ_BASE_URL: "https://sqtracker.dev",
7578

0 commit comments

Comments
 (0)