Skip to content

Conversation

@jmgasper
Copy link
Collaborator

@jmgasper jmgasper commented Nov 1, 2025

No description provided.

const isFileSubmission = hasUploadedFile;
const hasS3Url =
typeof body.url === 'string' &&
body.url.includes('https://s3.amazonaws.com');

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
https://s3.amazonaws.com
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

Copilot Autofix

AI 13 days ago

The fix is to properly parse body.url and check its host rather than searching for a substring. Use the standard Node.js URL class to parse the URL. Then, check whether the host is one of the allowed hosts for S3 (e.g., s3.amazonaws.com or region-specific variants like s3.<region>.amazonaws.com).

In this code, to replace the substring check, introduce host checks such as:

  • host exactly equals s3.amazonaws.com
  • host ends with .s3.amazonaws.com
  • host matches common region patterns (e.g., my-bucket.s3.eu-west-1.amazonaws.com)

To implement this:

  • Replace line 1654 with: check that body.url is a string, parse it with new URL(body.url), and test the host.
  • Add try/catch to guard against invalid URLs.
  • Use a helper function or inline code for host matching; avoid changing broader logic outside this region.

No external packages are needed, as the built-in URL class suffices.

Suggested changeset 1
src/api/submission/submission.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/api/submission/submission.service.ts b/src/api/submission/submission.service.ts
--- a/src/api/submission/submission.service.ts
+++ b/src/api/submission/submission.service.ts
@@ -1649,9 +1649,25 @@
         !!file &&
         ((typeof file.size === 'number' && file.size > 0) ||
           (file.buffer && file.buffer.length > 0));
-      const hasS3Url =
-        typeof body.url === 'string' &&
-        body.url.includes('https://s3.amazonaws.com');
+      let hasS3Url = false;
+      if (typeof body.url === 'string') {
+        try {
+          const urlObj = new URL(body.url);
+          // Accept s3.amazonaws.com and any subdomain of s3.amazonaws.com
+          const s3Hosts = [
+            's3.amazonaws.com',
+          ];
+          // Accept region pattern: *.s3.amazonaws.com or *.s3.<region>.amazonaws.com
+          const host = urlObj.host;
+          hasS3Url =
+            s3Hosts.includes(host) ||
+            host.endsWith('.s3.amazonaws.com') ||
+            /^s3\.[a-z0-9-]+\.amazonaws\.com$/.test(host) ||
+            /^[^\.]+\.s3\.[a-z0-9-]+\.amazonaws\.com$/.test(host);
+        } catch (e) {
+          hasS3Url = false;
+        }
+      }
       const isFileSubmission = hasUploadedFile || hasS3Url;
 
       // Derive common metadata if available
EOF
@@ -1649,9 +1649,25 @@
!!file &&
((typeof file.size === 'number' && file.size > 0) ||
(file.buffer && file.buffer.length > 0));
const hasS3Url =
typeof body.url === 'string' &&
body.url.includes('https://s3.amazonaws.com');
let hasS3Url = false;
if (typeof body.url === 'string') {
try {
const urlObj = new URL(body.url);
// Accept s3.amazonaws.com and any subdomain of s3.amazonaws.com
const s3Hosts = [
's3.amazonaws.com',
];
// Accept region pattern: *.s3.amazonaws.com or *.s3.<region>.amazonaws.com
const host = urlObj.host;
hasS3Url =
s3Hosts.includes(host) ||
host.endsWith('.s3.amazonaws.com') ||
/^s3\.[a-z0-9-]+\.amazonaws\.com$/.test(host) ||
/^[^\.]+\.s3\.[a-z0-9-]+\.amazonaws\.com$/.test(host);
} catch (e) {
hasS3Url = false;
}
}
const isFileSubmission = hasUploadedFile || hasS3Url;

// Derive common metadata if available
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
@jmgasper jmgasper merged commit 2933666 into master Nov 1, 2025
9 of 11 checks passed
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