-
-
Notifications
You must be signed in to change notification settings - Fork 3
Task/multipart upload #32
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
resultMsg.innerHTML = `<b>File:</b> ${file.name}<br> | ||
<b>Size:</b> ${(file.size / 1024 / 1024).toFixed(2)} MB<br> | ||
<b>SHA-256:</b> ${fileHash}<br> | ||
<b>UploadId:</b> ${uploadId}<br> | ||
<b>Key:</b> ${key}<br> | ||
<b>Chunks uploaded:</b> ${parts.length}<br> | ||
<b>Final ETag:</b> ${completeResult.etag || 'N/A'}`; |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium test
DOM text
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 6 days ago
To fix the issue, the file name (file.name
) and other dynamic data should be safely escaped before being inserted into the DOM using innerHTML
. Escaping ensures that special characters in the file name (like <
, >
, &
, etc.) are treated as plain text rather than HTML or JavaScript.
The best way to fix this is to use textContent
instead of innerHTML
, as textContent
safely inserts text into the DOM without interpreting it as HTML. Alternatively, you can sanitize the dynamic data before using innerHTML
, but using textContent
is simpler and avoids the risk of improper sanitization.
Changes to be made:
- Replace all instances of
innerHTML
where untrusted data is interpolated withtextContent
. - Specifically, update line 151 to ensure
file.name
and other interpolated values are safely added to the DOM as plain text.
-
Copy modified lines R151-R157
@@ -148,13 +148,13 @@ | ||
// --- Done --- | ||
statusMsg.textContent = 'Upload complete!'; | ||
progressBar.style.width = '100%'; | ||
resultMsg.innerHTML = `<b>File:</b> ${file.name}<br> | ||
<b>Size:</b> ${(file.size / 1024 / 1024).toFixed(2)} MB<br> | ||
<b>SHA-256:</b> ${fileHash}<br> | ||
<b>UploadId:</b> ${uploadId}<br> | ||
<b>Key:</b> ${key}<br> | ||
<b>Chunks uploaded:</b> ${parts.length}<br> | ||
<b>Final ETag:</b> ${completeResult.etag || 'N/A'}`; | ||
resultMsg.textContent = `File: ${file.name}\n` + | ||
`Size: ${(file.size / 1024 / 1024).toFixed(2)} MB\n` + | ||
`SHA-256: ${fileHash}\n` + | ||
`UploadId: ${uploadId}\n` + | ||
`Key: ${key}\n` + | ||
`Chunks uploaded: ${parts.length}\n` + | ||
`Final ETag: ${completeResult.etag || 'N/A'}`; | ||
} catch (err) { | ||
showError(err.message || err); | ||
} |
Experiment with multipart upload