added csp directives

This commit is contained in:
Danny Coates 2017-07-12 10:56:04 -07:00
parent b32e63c305
commit 9234bce75d
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
5 changed files with 37 additions and 12 deletions

View File

@ -9,7 +9,8 @@ $(document).ready(function() {
$('#send-file').click(() => { $('#send-file').click(() => {
window.location.replace(`${window.location.origin}`); window.location.replace(`${window.location.origin}`);
}); });
const download = () => { $('#download-btn').click(download);
function download() {
const fileReceiver = new FileReceiver(); const fileReceiver = new FileReceiver();
const name = document.createElement('p'); const name = document.createElement('p');
const $btn = $('#download-btn'); const $btn = $('#download-btn');
@ -84,7 +85,5 @@ $(document).ready(function() {
Raven.captureException(err); Raven.captureException(err);
return Promise.reject(err); return Promise.reject(err);
}); });
}; }
window.download = download;
}); });

View File

@ -10,6 +10,8 @@ $(document).ready(function() {
$('#compliance-error').show(); $('#compliance-error').show();
}); });
$('#file-upload').change(onUpload);
$('#page-one').on('dragover', allowDrop).on('drop', onUpload);
// reset copy button // reset copy button
const $copyBtn = $('#copy-btn'); const $copyBtn = $('#copy-btn');
$copyBtn.attr('disabled', false); $copyBtn.attr('disabled', false);
@ -61,11 +63,11 @@ $(document).ready(function() {
}); });
// on file upload by browse or drag & drop // on file upload by browse or drag & drop
window.onUpload = event => { function onUpload(event) {
event.preventDefault(); event.preventDefault();
let file = ''; let file = '';
if (event.type === 'drop') { if (event.type === 'drop') {
file = event.dataTransfer.files[0]; file = event.originalEvent.dataTransfer.files[0];
} else { } else {
file = event.target.files[0]; file = event.target.files[0];
} }
@ -143,11 +145,11 @@ $(document).ready(function() {
$('#page-one').hide(); $('#page-one').hide();
$('#upload-error').show(); $('#upload-error').show();
}); });
}; }
window.allowDrop = function(ev) { function allowDrop(ev) {
ev.preventDefault(); ev.preventDefault();
}; }
function checkExistence(id, populate) { function checkExistence(id, populate) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();

View File

@ -32,6 +32,30 @@ app.engine(
app.set('view engine', 'handlebars'); app.set('view engine', 'handlebars');
app.use(helmet()); app.use(helmet());
app.use(
helmet.contentSecurityPolicy({
directives: {
defaultSrc: ['\'self\''],
connectSrc: [
'\'self\'',
'https://sentry.prod.mozaws.net',
'https://www.google-analytics.com',
'https://ssl.google-analytics.com'
],
imgSrc: [
'\'self\'',
'https://www.google-analytics.com',
'https://ssl.google-analytics.com'
],
scriptSrc: ['\'self\'', 'https://ssl.google-analytics.com'],
styleSrc: ['\'self\'', 'https://code.cdn.mozilla.net'],
fontSrc: ['\'self\'', 'https://code.cdn.mozilla.net'],
formAction: ['\'none\''],
frameAncestors: ['\'none\''],
objectSrc: ['\'none\'']
}
})
);
app.use(busboy()); app.use(busboy());
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(express.static(STATIC_PATH)); app.use(express.static(STATIC_PATH));

View File

@ -23,7 +23,7 @@
</div> </div>
<div id="download-page-one"> <div id="download-page-one">
<div> <div>
<button id="download-btn" onclick="download()">Download File</button> <button id="download-btn">Download File</button>
</div> </div>
<div id='expired-img'> <div id='expired-img'>
<img src='/resources/link_expired.png' /> <img src='/resources/link_expired.png' />

View File

@ -19,7 +19,7 @@
<div class="title"> <div class="title">
Share your files quickly, privately and securely. Share your files quickly, privately and securely.
</div> </div>
<div class="upload-window" ondrop="onUpload(event)" ondragover="allowDrop(event)"> <div class="upload-window">
<div id="upload-img"><img src="/resources/upload.svg" alt="Upload"/></div> <div id="upload-img"><img src="/resources/upload.svg" alt="Upload"/></div>
<div> <div>
DRAG &amp; DROP DRAG &amp; DROP
@ -31,7 +31,7 @@
<div id="browse"> <div id="browse">
<form method="post" action="upload" enctype="multipart/form-data"> <form method="post" action="upload" enctype="multipart/form-data">
<label for="file-upload" class="file-upload">browse</label> <label for="file-upload" class="file-upload">browse</label>
<input id="file-upload" type="file" onchange="onUpload(event)" name="fileUploaded" /> <input id="file-upload" type="file" name="fileUploaded" />
</form> </form>
</div> </div>
</div> </div>