Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
import { executeAccess } from '../auth/executeAccess.js';
|
|
import { Forbidden } from '../errors/Forbidden.js';
|
|
export const checkFileAccess = async ({ collection, filename, req })=>{
|
|
if (filename.includes('../') || filename.includes('..\\')) {
|
|
throw new Forbidden(req.t);
|
|
}
|
|
const { config } = collection;
|
|
const accessResult = await executeAccess({
|
|
data: {
|
|
filename
|
|
},
|
|
isReadingStaticFile: true,
|
|
req
|
|
}, config.access.read);
|
|
if (typeof accessResult === 'object') {
|
|
const queryToBuild = {
|
|
and: [
|
|
{
|
|
or: [
|
|
{
|
|
filename: {
|
|
equals: filename
|
|
}
|
|
}
|
|
]
|
|
},
|
|
accessResult
|
|
]
|
|
};
|
|
if (config.upload.imageSizes) {
|
|
config.upload.imageSizes.forEach(({ name })=>{
|
|
queryToBuild.and?.[0]?.or?.push({
|
|
[`sizes.${name}.filename`]: {
|
|
equals: filename
|
|
}
|
|
});
|
|
});
|
|
}
|
|
const doc = await req.payload.db.findOne({
|
|
collection: config.slug,
|
|
req,
|
|
where: queryToBuild
|
|
});
|
|
if (!doc) {
|
|
throw new Forbidden(req.t);
|
|
}
|
|
return doc;
|
|
}
|
|
};
|
|
|
|
//# sourceMappingURL=checkFileAccess.js.map |