Fix .bat anonymization, truncated-tree misses, submodule warning, account deletion (#742)

* fix: anonymize Windows batch scripts (#735)

mime-types maps .bat to application/x-msdownload, the same MIME type as
.exe/.dll, so batch scripts were classified as binary and streamed
through without any anonymization. Special-case .bat/.cmd as text before
the MIME lookup, keeping .exe/.dll binary.

* fix: recover files missing from truncated tree listings (#738)

GitHub truncates tree listings of very large repositories. Folders whose
listing was truncated are recorded in truncatedFolders, but files that
fell outside the listing never reached the database, so requesting them
returned 404 file_not_found even though they exist on GitHub — and a
force refresh could not help.

When a file lookup misses and its directory is under a truncated folder,
fetch the file metadata directly from GitHub's contents API (object
media type, so it works past the 1MB inline limit), cache it in the
database, and serve it normally.

* feat: warn when a repository uses git submodules (#737)

GitHub archives and tree listings never include submodule contents, so
submodules end up as empty folders in the anonymized repository, which
surprises users. Detect a root .gitmodules file and show a warning
banner in the explorer explaining that submodule contents are not
included.

* feat: allow users to delete their account (#741)

Add DELETE /api/user: removes all anonymized repositories, gists, and
pull requests owned by the user, best-effort revokes the GitHub OAuth
grant, and scrubs personal data (username, emails, tokens, GitHub id,
photo) from the user record. The record itself is kept with a
placeholder username so removed repoIds stay reserved and owner
references remain resolvable.

The settings page gains an Account section with a confirmed delete
button.

* fix: add missing error translations for token_expired and job_is_active

The error-code coverage test failed because both backend codes had no
frontend translation.
This commit is contained in:
Thomas Durieux
2026-07-02 14:35:48 +03:00
committed by GitHub
parent e4e102eccd
commit 839582c657
13 changed files with 267 additions and 4 deletions
+44
View File
@@ -147,6 +147,17 @@ export default class AnonymizedFile {
this._file = res;
return res;
}
// The stored tree can be incomplete: GitHub truncates tree listings of
// very large repositories, and folders recorded in `truncatedFolders`
// have entries that never made it into the database. Ask GitHub
// directly for the path before concluding the file does not exist
// (#738). Without an anonymization mask the anonymized path is the
// original path, so it can be looked up as-is.
const recovered = await this.recoverTruncatedFile(fileDir);
if (recovered) {
this._file = recovered;
return recovered;
}
throw new AnonymousError("file_not_found", {
object: this,
httpStatus: 404,
@@ -189,6 +200,39 @@ export default class AnonymizedFile {
});
}
// On-demand recovery for files missing from the database because the
// GitHub tree listing was truncated. Only paths under a recorded
// truncated folder qualify — everything else is a genuine miss.
private async recoverTruncatedFile(fileDir: string): Promise<IFile | null> {
const truncated = this.repository.model.truncatedFolders || [];
const isAffected = truncated.some(
(folder) =>
folder === "" || fileDir === folder || fileDir.startsWith(folder + "/")
);
if (!isAffected) return null;
const source = this.repository.source as {
fetchFileInfoFromPath?: (filePath: string) => Promise<IFile | null>;
};
if (typeof source.fetchFileInfoFromPath !== "function") return null;
const recovered = await source.fetchFileInfoFromPath(this.anonymizedPath);
if (!recovered) return null;
recovered.repoId = this.repository.repoId;
logger.info("recovered file from truncated tree", {
repoId: this.repository.repoId,
path: this.anonymizedPath,
});
try {
// Cache it so the next request is served from the database.
await FileModel.create(recovered);
} catch (error) {
logger.warn(
"failed to cache recovered file",
serializeError(error as Error)
);
}
return recovered;
}
/**
* De-anonymize the path
*
+4
View File
@@ -101,6 +101,10 @@ function classifyByName(filePath: string): boolean | null {
const extension = name.split(".").reverse()[0].toLowerCase();
if (config.additionalExtensions.includes(extension)) return true;
if (KNOWN_TEXT_FILENAMES.has(name.toLowerCase())) return true;
// mime-types maps `.bat` to application/x-msdownload, the same MIME as
// .exe/.dll, so the MIME allowlist can't distinguish them. Batch scripts
// are text and must be anonymized (#735).
if (extension === "bat" || extension === "cmd") return true;
const mime = lookupMime(name);
if (mime === false) return null;
// mime-types treats `.ts` as video/mp2t; route.ts already special-cases it.
+38
View File
@@ -376,6 +376,44 @@ export default class GitHubStream extends GitHubBase {
return this.getTruncatedTree(this.data.commit, progress);
}
/**
* Fetch a single file's blob metadata directly from GitHub. Used as a
* fallback when the stored tree is incomplete because GitHub truncated
* the tree listing of a very large repository (#738). The `object` media
* type returns sha/size without the content payload, so it also works for
* files above the 1MB contents-API inline limit.
*/
async fetchFileInfoFromPath(filePath: string): Promise<IFile | null> {
const token = await this.data.getToken();
const oct = octokit(token);
try {
await waitForTokenGate(token);
const res = await oct.repos.getContent({
owner: this.data.organization,
repo: this.data.repoName,
path: filePath,
ref: this.data.commit,
mediaType: { format: "object" },
});
const data = res.data as { type?: string; sha?: string; size?: number };
if (data.type !== "file" || !data.sha) return null;
const parent = dirname(filePath);
return {
name: basename(filePath),
path: parent === "." ? "" : parent,
repoId: this.data.repoId,
sha: data.sha,
size: data.size,
};
} catch (error) {
logger.debug("fetchFileInfoFromPath miss", {
filePath,
error: serializeError(error),
});
return null;
}
}
private async getGHTree(
oct: ReturnType<typeof octokit>,
token: string,