Skip to content
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

Resolve XSS vulnerability #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/utils/handlersUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const handlersUtil = {
<button aria-label="Copy file contents to clipboard" class="js-file-clipboard btn btn-sm BtnGroup-item file-clipboard-button tooltipped tooltipped-s js-enhanced-github-copy-btn" data-copied-hint="Copied!" type="button" click="selectText()" data-clipboard-target="tbody">
Copy File
</button>
<a href="${data.download_url}" download="${data.name}"
<a href="${data.download_url}" download="${encodeURIComponent(data.name)}"
aria-label="(Alt/Option/Ctrl + Click) to download File" class="js-file-download btn btn-sm BtnGroup-item file-download-button tooltipped tooltipped-s">
<span style="margin-right: 5px;">${formattedFileSize}</span>
<svg class="octicon octicon-cloud-download" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16">
Expand Down Expand Up @@ -73,23 +73,24 @@ const handlersUtil = {

for (var i = startIndex; i < containerItems.length; i++) {
const commitElem = containerItems[i].querySelector('div:nth-of-type(3)');
const isValidFile = data[actualDataIndex].type === 'file' && data[actualDataIndex].size !== 0;
const fileMetadata = data[actualDataIndex];
const isValidFile = fileMetadata.type === 'file' && fileMetadata.size !== 0;

if (commitElem) {
containerItems[i].querySelector('div:nth-of-type(2)').classList.remove('col-md-2', 'mr-3');
containerItems[i].querySelector('div:nth-of-type(2)').classList.add('col-md-1', 'mr-2');

if (isValidFile || data[actualDataIndex].type === 'symlink') {
const formattedFileSize = commonUtil.getFileSizeAndUnit(data[actualDataIndex]);
if (isValidFile || fileMetadata.type === 'symlink') {
const formattedFileSize = commonUtil.getFileSizeAndUnit(fileMetadata);

const html = `
<div role="gridcell" class="mr-1 text-gray-light eg-download" style="width: 95px;">
<span class="css-truncate css-truncate-target d-block">
<span style="margin-right: 5px;">
${formattedFileSize}
</span>
<a style="float: right" href="${data[actualDataIndex].download_url}" title="(Alt/Option/Ctrl + Click) to download File" aria-label="(Alt/Option/Ctrl + Click) to download File" class="tooltipped tooltipped-s"
download="${data[actualDataIndex].name}">
<a style="float: right" href="${fileMetadata.download_url}" title="(Alt/Option/Ctrl + Click) to download File" aria-label="(Alt/Option/Ctrl + Click) to download File" class="tooltipped tooltipped-s"
download="${encodeURIComponent(fileMetadata.name)}">
<svg class="octicon octicon-cloud-download" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16">
<path d="M9 12h2l-3 3-3-3h2V7h2v5zm3-8c0-.44-.91-3-4.5-3C5.08 1 3 2.92 3 5 1.02 5 0 6.52 0 8c0 1.53 1 3 3 3h3V9.7H3C1.38 9.7 1.3 8.28 1.3 8c0-.17.05-1.7 1.7-1.7h1.3V5c0-1.39 1.56-2.7 3.2-2.7 2.55 0 3.13 1.55 3.2 1.8v1.2H12c.81 0 2.7.22 2.7 2.2 0 2.09-2.25 2.2-2.7 2.2h-2V11h2c2.08 0 4-1.16 4-3.5C16 5.06 14.08 4 12 4z"></path>
</svg>
Expand Down