Skip to content

Commit f042b09

Browse files
committed
Fix 8688gxkuj
1 parent b68873c commit f042b09

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

packages/backend/src/routers/down.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { HLRead } = require('../filesystem/hl_operations/hl_read.js');
1111
// -----------------------------------------------------------------------//
1212
// GET /down
1313
// -----------------------------------------------------------------------//
14-
router.get('/down', auth, fs, express.json(), async (req, res, next)=>{
14+
router.post('/down', auth, fs, express.json(), async (req, res, next)=>{
1515
// check subdomain
1616
if(require('../helpers').subdomain(req) !== 'api')
1717
next();
@@ -20,6 +20,12 @@ router.get('/down', auth, fs, express.json(), async (req, res, next)=>{
2020
if((config.strict_email_verification_required || req.user.requires_email_confirmation) && !req.user.email_confirmed)
2121
return res.status(400).send({code: 'account_is_not_verified', message: 'Account is not verified'});
2222

23+
// check anti-csrf token
24+
const svc_antiCSRF = req.services.get('anti-csrf');
25+
if ( ! svc_antiCSRF.consume_token(req.user.uuid, req.body.anti_csrf) ) {
26+
return res.status(400).json({ message: 'incorrect anti-CSRF token' });
27+
}
28+
2329
// validation
2430
if(!req.query.path)
2531
return res.status(400).send('path is required')

src/helpers.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1542,12 +1542,26 @@ window.trigger_download = (paths)=>{
15421542
});
15431543
}
15441544

1545-
urls.forEach(function (e) {
1546-
fetch(e.download)
1547-
.then(res => res.blob())
1548-
.then(blob => {
1549-
saveAs(blob, e.filename);
1550-
});
1545+
urls.forEach(async function (e) {
1546+
const anti_csrf = await (async () => {
1547+
const resp = await fetch(`${window.gui_origin}/get-anticsrf-token`);
1548+
const { token } = await resp.json();
1549+
return token;
1550+
})();
1551+
fetch(e.download, {
1552+
method: 'POST',
1553+
headers: {
1554+
'Content-Type': 'application/json',
1555+
'Authorization': 'Bearer ' + puter.authToken,
1556+
},
1557+
body: JSON.stringify({
1558+
anti_csrf,
1559+
}),
1560+
})
1561+
.then(res => res.blob())
1562+
.then(blob => {
1563+
saveAs(blob, e.filename);
1564+
});
15511565
});
15521566
}
15531567

0 commit comments

Comments
 (0)