-
Notifications
You must be signed in to change notification settings - Fork 0
feat: allow to upload file directry from the url query param #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -103,6 +103,8 @@ const progress = ref(0); | |||
| const uploaded = ref(false); | ||||
| const uploadedSize = ref(0); | ||||
|
|
||||
| const downloadFileUrl = ref(''); | ||||
|
|
||||
| watch(() => uploaded, (value) => { | ||||
| emit('update:emptiness', !value); | ||||
| }); | ||||
|
|
@@ -118,9 +120,45 @@ function uploadGeneratedImage(imgBlob) { | |||
| }); | ||||
| } | ||||
|
|
||||
| onMounted(() => { | ||||
| onMounted(async () => { | ||||
| const previewColumnName = `previewUrl_${props.meta.pluginInstanceId}`; | ||||
| if (props.record[previewColumnName]) { | ||||
|
|
||||
| let queryValues; | ||||
| try { | ||||
| queryValues = JSON.parse(atob(route.query.values as string)); | ||||
| } catch (e) { | ||||
| queryValues = {}; | ||||
| } | ||||
|
|
||||
| if (queryValues[props.meta.pathColumnName]) { | ||||
|
|
||||
|
|
||||
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+134
to
+135
|
||||
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -86,6 +86,7 @@ export default class UploadPlugin extends AdminForthPlugin { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| minShowWidth: this.options.preview?.minShowWidth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generationPrompt: this.options.generation?.generationPrompt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| recorPkFieldName: this.resourceConfig.columns.find((column: any) => column.primaryKey)?.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pathColumnName: this.options.pathColumnName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // define components which will be imported from other components | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.componentPath('imageGenerator.vue'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -411,6 +412,55 @@ export default class UploadPlugin extends AdminForthPlugin { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server.endpoint({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: `/plugin/${this.pluginInstanceId}/get-file-download-url`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handler: async ({ body, adminUser }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { filePath } = body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!filePath) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: 'Missing filePath' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = await this.options.storageAdapter.getDownloadUrl(filePath, 1800); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+418
to
+428
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server.endpoint({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: `/plugin/${this.pluginInstanceId}/proxy-download`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handler: async ({ body, response }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { fileDownloadURL } = body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!fileDownloadURL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: 'Missing fileDownloadURL' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
yaroslav8765 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!fileDownloadURL.startsWith(`http://${(this.options.storageAdapter as any).options.bucket}`) && !fileDownloadURL.startsWith(`https://${(this.options.storageAdapter as any).options.bucket}`)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: 'Invalid fileDownloadURL ' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { error: 'Invalid fileDownloadURL ' }; | |
| return { error: 'Invalid fileDownloadURL: URL must be from the configured storage bucket.' }; |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL validation logic is insufficient and potentially vulnerable. It only checks if the URL starts with the bucket name but doesn't validate that the URL actually points to the storage adapter's domain. An attacker could craft a URL like http://bucket-name.malicious.com or https://bucket-name.evil.com that would bypass this check. Consider implementing proper URL parsing and validation that checks the full hostname against an allowlist.
| if (!fileDownloadURL.startsWith(`http://${(this.options.storageAdapter as any).options.bucket}`) && !fileDownloadURL.startsWith(`https://${(this.options.storageAdapter as any).options.bucket}`)) { | |
| return { error: 'Invalid fileDownloadURL ' }; | |
| } | |
| let allowedHostnames: string[] = []; | |
| // Attempt to build an allowlist of valid hostnames for the storage adapter | |
| const storageOptions = (this.options.storageAdapter as any).options; | |
| if (storageOptions.bucket && storageOptions.endpoint) { | |
| // e.g., endpoint: "s3.amazonaws.com", bucket: "my-bucket" | |
| // Allow both "my-bucket.s3.amazonaws.com" and "s3.amazonaws.com" | |
| try { | |
| const endpointUrl = new URL(storageOptions.endpoint.startsWith('http') ? storageOptions.endpoint : `https://${storageOptions.endpoint}`); | |
| allowedHostnames.push(`${storageOptions.bucket}.${endpointUrl.hostname}`); | |
| allowedHostnames.push(endpointUrl.hostname); | |
| } catch (e) { | |
| // fallback: just use bucket as hostname | |
| allowedHostnames.push(storageOptions.bucket); | |
| } | |
| } else if (storageOptions.bucket) { | |
| allowedHostnames.push(storageOptions.bucket); | |
| } | |
| let parsedUrl: URL; | |
| try { | |
| parsedUrl = new URL(fileDownloadURL); | |
| } catch (e) { | |
| return { error: 'Invalid fileDownloadURL (malformed URL)' }; | |
| } | |
| if (!allowedHostnames.includes(parsedUrl.hostname)) { | |
| return { error: 'Invalid fileDownloadURL (hostname not allowed)' }; | |
| } |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proxy-download endpoint doesn't validate user authorization. Any authenticated admin user can proxy download files from URLs that pass the bucket validation check. Consider adding authorization checks to ensure the user has permission to access the file being proxied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
watchfunction is incorrectly watching the entireuploadedref object instead of its value. It should bewatch(uploaded, (value) => ...)orwatch(() => uploaded.value, (value) => ...)to properly react to changes in the uploaded state.