using dialogs in file browser now (fix 2)
This commit is contained in:
@@ -155,7 +155,7 @@ function isSameOrigin(req) {
|
||||
const referer = req.get('referer');
|
||||
const header = origin || referer;
|
||||
if (!header) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const parsed = new URL(header);
|
||||
@@ -177,7 +177,7 @@ function csrfGuard(req, res, next) {
|
||||
}
|
||||
|
||||
const token = req.cookies[csrfCookieName];
|
||||
const provided = req.body?.csrfToken || req.get('x-csrf-token');
|
||||
const provided = req.body?.csrfToken || req.query?.csrfToken || req.get('x-csrf-token');
|
||||
if (!token || !provided || token !== provided) {
|
||||
if (req.path.startsWith(`${basePath}/api/`)) {
|
||||
res.status(403).json({ error: 'CSRF token mismatch' });
|
||||
@@ -1042,9 +1042,9 @@ app.get(`${basePath}/admin/files`, requireAdminPage, async (req, res) => {
|
||||
</div>
|
||||
<div>
|
||||
<h2>Datei hochladen</h2>
|
||||
<form method="post" action="${baseUrl('/admin/files/upload')}" enctype="multipart/form-data">
|
||||
${csrfField(res.locals.csrfToken)}
|
||||
<input type="hidden" name="path" value="${escapeHtml(relativePath)}" />
|
||||
<form method="post" action="${baseUrl(`/admin/files/upload?csrfToken=${encodeURIComponent(res.locals.csrfToken)}`)}" enctype="multipart/form-data">
|
||||
${csrfField(res.locals.csrfToken)}
|
||||
<input type="hidden" name="path" value="${escapeHtml(relativePath)}" />
|
||||
<label>
|
||||
Datei
|
||||
<input type="file" name="file" required />
|
||||
@@ -1356,6 +1356,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
|
||||
|
||||
<script>
|
||||
const uploadForm = document.getElementById('upload-form');
|
||||
const csrfToken = ${JSON.stringify(res.locals.csrfToken)};
|
||||
const progress = document.getElementById('upload-progress');
|
||||
const status = document.getElementById('upload-status');
|
||||
const copyButtons = document.querySelectorAll('.copy-link');
|
||||
@@ -1365,6 +1366,7 @@ app.get(`${basePath}/dashboard`, requireAuthPage, async (req, res) => {
|
||||
progress.value = 0;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', ${JSON.stringify(baseUrl('/api/upload'))});
|
||||
xhr.setRequestHeader('X-CSRF-Token', csrfToken);
|
||||
xhr.upload.addEventListener('progress', (e) => {
|
||||
if (e.lengthComputable) {
|
||||
progress.value = Math.round((e.loaded / e.total) * 100);
|
||||
|
||||
Reference in New Issue
Block a user