Skip to content

Task/multipart upload#32

Merged
tirthbodawala merged 4 commits intomainfrom
task/multipart-upload
Jul 11, 2025
Merged

Task/multipart upload#32
tirthbodawala merged 4 commits intomainfrom
task/multipart-upload

Conversation

@tirthbodawala
Copy link
Member

Experiment with multipart upload

Comment on lines +151 to +157
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 failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High test

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 8 months 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 with textContent.
  • Specifically, update line 151 to ensure file.name and other interpolated values are safely added to the DOM as plain text.

Suggested changeset 1
test.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test.html b/test.html
--- a/test.html
+++ b/test.html
@@ -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);
         }
EOF
@@ -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);
}
Copilot is powered by AI and may make mistakes. Always verify output.
@tirthbodawala tirthbodawala merged commit 5aa7e08 into main Jul 11, 2025
5 of 6 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.

1 participant