mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-12 21:58:57 +02:00
fix: enforce content policies using original file types
This commit is contained in:
@@ -343,7 +343,7 @@ export default class AnonymizedFile {
|
||||
|
||||
async anonymizedContent() {
|
||||
const anonymizer = this.repository.generateAnonymizeTransformer(
|
||||
this.anonymizedPath
|
||||
await this.originalPath()
|
||||
);
|
||||
if (!config.STREAMER_ENTRYPOINT) {
|
||||
// collect the content locally
|
||||
@@ -385,7 +385,7 @@ export default class AnonymizedFile {
|
||||
|
||||
async send(res: Response): Promise<void> {
|
||||
const anonymizer = this.repository.generateAnonymizeTransformer(
|
||||
this.anonymizedPath
|
||||
await this.originalPath()
|
||||
);
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
|
||||
@@ -149,7 +149,7 @@ export async function streamAnonymizedZip(
|
||||
entry.path.substring(entry.path.indexOf("/") + 1),
|
||||
compiledTerms
|
||||
);
|
||||
if (!isEntryAllowed(fileName, opt.contentOptions)) {
|
||||
if (!isEntryAllowed(entry.path, opt.contentOptions)) {
|
||||
entry.autodrain();
|
||||
return;
|
||||
}
|
||||
@@ -159,7 +159,7 @@ export async function streamAnonymizedZip(
|
||||
// isText=false for every file, so the zip ships unanonymized.
|
||||
const anonymizer = new AnonymizeTransformer({
|
||||
...opt.anonymizerOptions,
|
||||
filePath: fileName,
|
||||
filePath: entry.path,
|
||||
});
|
||||
const st = entry.pipe(anonymizer);
|
||||
archive.append(st, { name: fileName });
|
||||
|
||||
@@ -105,6 +105,7 @@ router.get(
|
||||
repository: repo,
|
||||
anonymizedPath,
|
||||
});
|
||||
const originalPath = await f.originalPath();
|
||||
if (!f.isFileSupported()) {
|
||||
throw new AnonymousError("file_not_supported", {
|
||||
httpStatus: 403,
|
||||
@@ -115,7 +116,7 @@ router.get(
|
||||
res.attachment(
|
||||
anonymizedPath.substring(anonymizedPath.lastIndexOf("/") + 1)
|
||||
);
|
||||
} else if (isScriptableDocument(anonymizedPath)) {
|
||||
} else if (isScriptableDocument(originalPath) || isScriptableDocument(anonymizedPath)) {
|
||||
// A repository's own .html/.svg is untrusted content served from our
|
||||
// origin: opening it renders it as a document, and any script in it
|
||||
// would run as the site itself (session cookie, same-origin fetches
|
||||
|
||||
@@ -151,6 +151,7 @@ async function webView(req: express.Request, res: express.Response) {
|
||||
}
|
||||
}
|
||||
|
||||
await f.originalPath();
|
||||
if (!f.isFileSupported()) {
|
||||
throw new AnonymousError("file_not_supported", {
|
||||
httpStatus: 400,
|
||||
|
||||
Reference in New Issue
Block a user