Skip to content

Commit

Permalink
fix: password authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
alan16742 committed Oct 11, 2024
1 parent a109a86 commit 2801ec7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions back-end-cf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function handleRequest(request) {
const file = requestUrl.searchParams.get('file') || (requestUrl.pathname.split('/').filter(Boolean).length === 0 ? '' : decodeURIComponent(requestUrl.pathname));
if (file) {
const fileName = file.split('/').pop();
if (fileName.toLowerCase() === PASSWD_FILENAME.toLowerCase() || fileName.toLowerCase() === '.upload')
if (fileName.toLowerCase() === PASSWD_FILENAME.toLowerCase())
return Response.redirect(
'https://www.baidu.com/s?wd=%E6%80%8E%E6%A0%B7%E7%9B%97%E5%8F%96%E5%AF%86%E7%A0%81',
301
Expand All @@ -63,15 +63,14 @@ async function handleRequest(request) {
} else if (requestUrl.searchParams.get('upload')) {
requestPath = requestUrl.searchParams.get('upload');
const upload = await fetchFiles(requestPath, '.upload');
const uploadSecret = upload ? (await getContent(upload) || 'webupload') : '';
const uploadSecret = await fetchFiles(requestPath, PASSWD_FILENAME, null, true) || '';
const fileList = await request.json();
const uploadAttack = fileList['files'].some(
(file) =>
file.remotePath.split('/').pop().toLowerCase() ===
PASSWD_FILENAME.toLowerCase() ||
file.remotePath.split('/').pop().toLowerCase() === '.upload'
PASSWD_FILENAME.toLowerCase()
) || fileList['secret'] !== uploadSecret;
if (!uploadAttack) {
if (upload && !uploadAttack) {
const uploadLinks = await uploadFiles(fileList);
return new Response(uploadLinks, {
headers: returnHeaders,
Expand Down
3 changes: 2 additions & 1 deletion front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@
input.placeholder = '密码错误';
} else {
window.fileCache.set(newFiles.parent, newFiles);
window.fileCache.set(`${newFiles.parent}/.upload`, passwd);
fetchFileList(newFiles.parent);
}
}
Expand Down Expand Up @@ -1716,7 +1717,7 @@
sendRequest(
window.api.method,
window.api.url + '?upload=' + odPath,
JSON.stringify({ secret: 'webupload', files: currentPage }),
JSON.stringify({ secret: window.fileCache.get(`${odPath}/.upload`) || '', files: currentPage }),
window.api.headers,
(response) => {
const uploadLinks = JSON.parse(response).files;
Expand Down

0 comments on commit 2801ec7

Please sign in to comment.