Skip to content

Commit 64fc6c6

Browse files
committed
fix: Only allow URLs used by the website when forwarding to onshape API
1 parent 55b5afd commit 64fc6c6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

web/server/api/onshape/[...path].ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { FetchError } from 'ofetch';
22
import useExtendedNitroApp from '~/server/composables/useExtendedNitroApp';
33

4+
const ALLOWED_URL_REGEX = [
5+
/assemblies\/d\/[0-9a-z]+\/w\/[0-9a-z]+\/e\/[0-9a-z]+\/bom\?indented=false/,
6+
/documents\/[0-9a-z]+/,
7+
/parts\/d\/[0-9a-z]+\/[vw]\/[0-9a-z]+\/e\/[0-9a-z]+\/partid\/[a-zA-Z]{3}\/boundingboxes\?configuration=.*/,
8+
];
9+
410
export default defineEventHandler(async (event) => {
511
const { onshape } = useExtendedNitroApp();
612
const url = event.node.req.originalUrl!.replace('/api/onshape/', '');
713

14+
if (!ALLOWED_URL_REGEX.find((regex) => regex.test(url))) {
15+
setResponseStatus(event, 400);
16+
return {
17+
message: 'URL is not allowed',
18+
url,
19+
};
20+
}
21+
822
try {
923
return await onshape.fetch(url);
1024
} catch (err) {

0 commit comments

Comments
 (0)