-
Notifications
You must be signed in to change notification settings - Fork 9
Performance and minor fixes for prod release #138
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
Conversation
Performance indices and also updates for handling TG Task Submissions of URL only
Minor tweak for better support of the upload panel in CA
Use legacy scorecard ID as a fallback for legacy data
| 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
Show autofix suggestion
Hide autofix suggestion
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.urlis a string, parse it withnew 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.
-
Copy modified lines R1652-R1670
| @@ -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 |
No description provided.