Skip to content

Commit 19d84a2

Browse files
committed
Do not allow creation of not allowed extensions
1 parent 5fcdcf5 commit 19d84a2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

site/src/components/TemplateVersionEditor/FileDialog.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
33
import { Stack } from "components/Stack/Stack"
44
import { ChangeEvent, FC, useState } from "react"
55
import Typography from "@material-ui/core/Typography"
6+
import { allowedExtensions, isAllowedFile } from "util/templateVersion"
67

78
export const CreateFileDialog: FC<{
89
onClose: () => void
@@ -24,6 +25,14 @@ export const CreateFileDialog: FC<{
2425
setError("File already exists")
2526
return
2627
}
28+
if (!isAllowedFile(pathValue)) {
29+
setError(
30+
`This is not an allowed extension. Valid extensions are: ${allowedExtensions.join(
31+
", ",
32+
)}.`,
33+
)
34+
return
35+
}
2736
onConfirm(pathValue)
2837
setPathValue("")
2938
}

site/src/util/templateVersion.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const getTemplateVersionFiles = async (
2323
return files
2424
}
2525

26-
const allowedExtensions = ["tf", "md", "Dockerfile"]
26+
export const allowedExtensions = ["tf", "md", "Dockerfile"]
2727

2828
export const isAllowedFile = (name: string) => {
2929
return allowedExtensions.some((ext) => name.endsWith(ext))

0 commit comments

Comments
 (0)