Skip to content

Conversation

@yaroslav8765
Copy link
Contributor

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds functionality to upload files directly from URL query parameters. When creating or editing a record, users can now specify a file path in the URL query string, which will be automatically downloaded and uploaded to the file field. The implementation includes backend endpoints for generating download URLs and proxying file downloads, plus frontend logic to parse query parameters and handle the file download/upload flow.

Key Changes

  • Added two new backend endpoints: one for generating file download URLs and another for proxying file downloads through the server
  • Modified the Vue uploader component to read file paths from URL query parameters and automatically trigger file upload on mount
  • Added pathColumnName configuration to support the new URL-based upload feature

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
index.ts Added two new endpoints for file URL generation and download proxying, plus pathColumnName configuration
custom/uploader.vue Enhanced onMounted hook to parse query parameters and trigger automatic file downloads/uploads, added downloadAsFile helper function
Comments suppressed due to low confidence (1)

index.ts:6

  • Unused import url.
import { url } from 'inspector/promises';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +441 to +444
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 ' };
}

Copy link

Copilot AI Nov 24, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
}

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 ' };
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message 'Invalid fileDownloadURL ' has a trailing space and doesn't provide helpful information about why the URL is invalid or what format is expected. Consider improving it to something like: 'Invalid fileDownloadURL: URL must be from the configured storage bucket'.

Suggested change
return { error: 'Invalid fileDownloadURL ' };
return { error: 'Invalid fileDownloadURL: URL must be from the configured storage bucket.' };

Copilot uses AI. Check for mistakes.
Comment on lines +434 to +462
handler: async ({ body, response }) => {
const { fileDownloadURL } = body;

if (!fileDownloadURL) {
return { error: 'Missing fileDownloadURL' };
}

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 ' };
}

const upstream = await fetch(fileDownloadURL);
if (!upstream.ok || !upstream.body) {
return { error: `Failed to download file (status ${upstream.status})` };
}

const contentType = upstream.headers.get('content-type') || 'application/octet-stream';
const contentLength = upstream.headers.get('content-length');
const contentDisposition = upstream.headers.get('content-disposition');

response.setHeader('Content-Type', contentType);
if (contentLength) response.setHeader('Content-Length', contentLength);
if (contentDisposition) response.setHeader('Content-Disposition', contentDisposition);

//@ts-ignore Node 18+: convert Web stream to Node stream and pipe to response
Readable.fromWeb(upstream.body).pipe(response.blobStream());
return null;
},
});
Copy link

Copilot AI Nov 24, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +134 to +135
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty lines (134-135) should be removed to maintain consistent code formatting.

Suggested change

Copilot uses AI. Check for mistakes.
const downloadFileUrl = ref('');
watch(() => uploaded, (value) => {
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watch function is incorrectly watching the entire uploaded ref object instead of its value. It should be watch(uploaded, (value) => ...) or watch(() => uploaded.value, (value) => ...) to properly react to changes in the uploaded state.

Suggested change
watch(() => uploaded, (value) => {
watch(uploaded, (value) => {

Copilot uses AI. Check for mistakes.
Comment on lines +418 to +428
handler: async ({ body, adminUser }) => {
const { filePath } = body;
if (!filePath) {
return { error: 'Missing filePath' };
}
const url = await this.options.storageAdapter.getDownloadUrl(filePath, 1800);

return {
url,
};
},
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint doesn't validate user authorization to access the specific file. Any authenticated admin user can request a download URL for any file path. Consider adding authorization checks to ensure the user has permission to access the file, or at least verify the file belongs to a resource the user can access.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants