mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
Merge remote-tracking branch 'origin/main' into feat/repo-list-sync
# Conflicts: # deploy/logging/sanitize.vrl # public/asset-manifest.json # public/script/vendor.min.js
This commit is contained in:
commit
07bdae9252
22 files changed
+394
-66
No files matched your search
@@ -548,8 +548,12 @@ export default class AnonymizedFile {
|
||||
);
|
||||
void notifyOwnerAccessProblem(this.repository.owner.id, error, { kind: "repository", id: String(this.repository.model._id) });
|
||||
error.value = this;
|
||||
// Only a response that was already streaming body bytes must be
|
||||
// cut. handleError's own reply can be mid-write: express-session
|
||||
// holds back its last byte until the session store touch ends.
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
});
|
||||
resolve();
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { recordResponseFailure } from "./request-evidence";
|
||||
import { watchClientClose } from "./response-cancellation";
|
||||
import { createGzip } from "zlib";
|
||||
import { createHash } from "crypto";
|
||||
import { Readable, PassThrough } from "stream";
|
||||
@@ -53,12 +54,19 @@ async function sendCached(content: Readable, res: Response,
|
||||
// Install evidence before pipeline's listeners destroy the response.
|
||||
const localFailure = () => { if (!res.destroyed) recordResponseFailure(res, "unknown", "local_abort"); };
|
||||
stream.once("error", localFailure);
|
||||
if (record.encoding === "identity" && !res.req.acceptsEncodings("identity")) {
|
||||
res.setHeader("Content-Encoding", "gzip"); res.removeHeader("Content-Length");
|
||||
const gzip = createGzip();
|
||||
gzip.once("error", localFailure);
|
||||
await pipeline(stream, gzip, res);
|
||||
} else await pipeline(stream, res);
|
||||
const clientClosed = watchClientClose(res, stream);
|
||||
try {
|
||||
if (record.encoding === "identity" && !res.req.acceptsEncodings("identity")) {
|
||||
res.setHeader("Content-Encoding", "gzip"); res.removeHeader("Content-Length");
|
||||
const gzip = createGzip();
|
||||
gzip.once("error", localFailure);
|
||||
await pipeline(stream, gzip, res);
|
||||
} else await pipeline(stream, res);
|
||||
} catch (error) {
|
||||
// A visitor who stops a download is not a server fault.
|
||||
if (clientClosed()) throw Object.assign(new Error("response_cancelled"), { cause: error });
|
||||
throw error;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const decision = results.decision(key);
|
||||
|
||||
@@ -1570,11 +1570,13 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
],
|
||||
"src/core/response-cancellation.ts": [
|
||||
"<anonymous>",
|
||||
"isResponseCancellation"
|
||||
"isResponseCancellation",
|
||||
"watchClientClose"
|
||||
],
|
||||
"build/core/response-cancellation.js": [
|
||||
"<anonymous>",
|
||||
"isResponseCancellation"
|
||||
"isResponseCancellation",
|
||||
"watchClientClose"
|
||||
],
|
||||
"src/core/response-stream.ts": [
|
||||
"<anonymous>",
|
||||
@@ -2979,3 +2981,4 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
|
||||
};
|
||||
export const LOG_ERROR_TYPES = ["Error","TypeError","RangeError","ReferenceError","SyntaxError","URIError","EvalError","AggregateError","AnonymousError","HTTPError","RequestError","MongoServerError","MongoNetworkError","MongoServerSelectionError","ValidationError","TimeoutError","AbortError","UnknownError"];
|
||||
export const LOG_ROUTES = ["/","other","/dashboard","/anonymize","/healthcheck","/api/healthcheck","/api","/api/download","/api/stat","/api/stat/history","/api/options","/api/message","/api/user","/api/user/quota","/api/user/dashboard","/api/repo","/api/anonymize-preview","/api/admin/overview","/api/admin/performance","/api/admin/errors","/api/admin/errors/stats","/api/admin/queues","/api/admin/queues/metrics","/github/app/webhook","/api/repo/:repoId","/api/repo/:repoId/file/:path","/api/repo/:repoId/files","/api/repo/:repoId/files/counts","/api/repo/:repoId/files/search","/api/repo/:repoId/zip","/api/repo/:repoId/options","/api/repo/:repoId/refresh","/api/repo/:repoId/coauthors","/api/repo/:repoId/extend","/api/repo/:owner/:repo","/api/repo/:owner/:repo/tree","/api/repo/:owner/:repo/file","/api/repo/:owner/:repo/readme","/api/repo/:owner/:repo/branches","/w/:repoId/:path","/r/:repoId/:path","/api/pr/:id/:path","/api/gist/:id/:path","/assets/:path","/github/:action","/api/admin/:action","/api/user/:action","/api/repo/:id/file/:path","/api/repo/:id/files/counts","/api/repo/:id/files/search","/api/repo/:id/files","/api/repo/:id/zip","/api/repo/:id","/viewer/:id/:path","/api/billing","/api/billing/draft","/api/billing/draft/:id","/api/billing/checkout","/api/billing/portal","/api/billing/refresh","/api/billing/webhook","/api/conferences/plans","/profile","/conference/:id"];
|
||||
export const LOG_THROWN_ERROR_CODES = ["another_login_required","billing_address_missing","billing_already_paid","billing_busy","billing_checkout_disabled","billing_checkout_in_progress","billing_city_missing","billing_country_missing","billing_customer_mismatch","billing_draft_not_found","billing_email_missing","billing_invalid_conference","billing_invalid_draft","billing_invalid_purchase","billing_invalid_repository_size","billing_invalid_review_window","billing_missing","billing_name_missing","billing_plan_change_not_supported","billing_plan_unavailable","billing_price_misconfigured","billing_recovery_required","billing_review_window_locked","billing_subscription_exists","billing_unavailable","billing_zip_missing","branch_not_found","branch_not_specified","cache_busy","cache_miss","cannot_coauthor_self","commit_not_found","commit_not_specified","conf_end_date_invalid","conf_end_date_missing","conf_id_missing","conf_id_used","conf_name_missing","conf_not_activated","conf_not_found","conf_start_date_invalid","conf_start_date_missing","conference_not_found","conference_payment_required","connection_changed","download_not_enabled","expiration_limit_reached","file_listing_too_large","file_not_accessible","file_not_found","file_not_supported","file_too_big","folder_not_supported","gistId_already_used","gistId_not_specified","gist_expired","gist_not_available","gist_not_found","gist_not_ready","github_app_access_required","github_app_authorization_cancelled","github_app_disabled","github_app_permissions_invalid","github_app_reconnect_required","github_app_refresh_busy","github_grant_revocation_failed","github_identity_mismatch","github_oauth_required","github_rate_limit_exceeded","github_unavailable","github_user_not_found","invalid_auth_state","invalid_billing_expiration","invalid_commit_format","invalid_connection","invalid_cursor","invalid_gistId","invalid_github_path","invalid_path","invalid_plan","invalid_preserve_files_format","invalid_project_name","invalid_pullRequestId","invalid_repo","invalid_repoId","invalid_request","invalid_settings","invalid_sort","invalid_status","invalid_terms_format","invalid_token_id","invalid_token_options","is_removed","not_authorized","not_connected","not_owner","oauth_resources_remaining","options_not_provided","page_not_activated","page_not_supported_on_different_branch","path_not_defined","path_not_specified","pullRequestId_already_used","pullRequestId_is_not_a_number","pullRequestId_not_specified","pull_request_expired","pull_request_not_available","pull_request_not_found","pull_request_not_ready","quota_exceeded","quota_repository_limit","quota_storage_limit","rate_limited","readme_not_available","repoId_already_used","repoId_not_defined","repoUrl_not_defined","repo_access_limited","repo_empty","repo_not_accessible","repo_not_found","repo_saml_enforcement","repository_archived","repository_busy","repository_changed","repository_expired","repository_job_cancelled","repository_not_accessible","repository_not_ready","repository_not_specified","repository_tree_incomplete","repository_tree_too_large","s3_config_not_provided","source_not_provided","storage_delete_failed","storage_write_size_mismatch","streamer_unreachable","streamer_upstream_error","submodule_not_available","subscription_required_for_never_expiration","sync_failed","terms_not_specified","token_expired","token_limit_reached","unable_to_connect_user","unable_to_download","upstream_error","user_banned","user_not_found","username_not_defined","zip_not_available","zip_unsafe_entry_path"];
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ANONYMIZATION_ERRORS } from "./anonymization-errors";
|
||||
import { requestReproduction, safeReproductionPath } from "./log-reproduction";
|
||||
import { safeDiagnosticFields, errorDiagnostics } from "./log-diagnostics";
|
||||
import { LOG_ROUTES } from "./log-diagnostic-schema";
|
||||
import { LOG_ROUTES, LOG_THROWN_ERROR_CODES } from "./log-diagnostic-schema";
|
||||
import { LOG_MODULES, ERROR_CODES, LOG_EVENTS } from "./log-schema";
|
||||
import { randomUUID } from "crypto";
|
||||
import { logContext, validTraceId } from "./log-context";
|
||||
@@ -17,8 +17,9 @@ const events: Record<string, string> = {
|
||||
"process heartbeat": "process_heartbeat", "job started": "job_started", "job completed": "job_completed",
|
||||
"job failed": "job_failed", "job stalled": "job_stalled", "queue heartbeat": "queue_heartbeat",
|
||||
};
|
||||
const errorCodes = new Set([
|
||||
...ERROR_CODES, ...ANONYMIZATION_ERRORS, "zip_unsafe_entry_path",
|
||||
// LOG_THROWN_ERROR_CODES is generated from the codes the source throws.
|
||||
export const LOG_ERROR_CODES: ReadonlySet<string> = new Set([
|
||||
...ERROR_CODES, ...ANONYMIZATION_ERRORS, ...LOG_THROWN_ERROR_CODES, "zip_unsafe_entry_path",
|
||||
"repo_renamed", "preparation_interrupted", "commit_not_found", "zip_not_available", "token_refresh_failed", "quota_exceeded", "quota_repository_limit", "quota_storage_limit", "github_rate_limit_exceeded", "github_app_reconnect_required", "github_token_invalid",
|
||||
"repository_expired", "repository_not_ready", "repository_not_found", "repository_job_cancelled",
|
||||
"ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND", "EPIPE", "ABORT_ERR",
|
||||
@@ -57,7 +58,7 @@ export function logRecord(level: string, module: string, args: unknown[]) {
|
||||
}
|
||||
if (Number.isSafeInteger(context.attempt)) record.attempt = context.attempt;
|
||||
for (const key of LOG_NUMBERS) if (typeof details[key] === "number" && Number.isFinite(details[key])) record[key] = details[key];
|
||||
const code = [details.code, details.message].find(value => typeof value === "string" && errorCodes.has(value));
|
||||
const code = [details.code, details.message].find(value => typeof value === "string" && LOG_ERROR_CODES.has(value));
|
||||
if (code) record.errorCode = code;
|
||||
if (allowed(["protocol", "credentials", "port", "host"], details.reason)) record.reason = details.reason;
|
||||
if (allowed(["parse", "find_grant_owners", "reconcile_grant", "persist_installation_block", "reconcile_installation"], details.phase)) record.phase = details.phase;
|
||||
|
||||
@@ -14,3 +14,19 @@ export function isResponseCancellation(error: unknown, response?: { destroyed?:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* pipeline() rejects with ERR_STREAM_PREMATURE_CLOSE both when the client goes
|
||||
* away and when the source ends early. Call before piping; the returned check
|
||||
* is true only when the response closed unfinished before the source failed.
|
||||
*/
|
||||
export function watchClientClose(response: { writableFinished?: boolean; once(event: "close", listener: () => void): unknown },
|
||||
source: { readableEnded?: boolean; once(event: "close" | "error", listener: () => void): unknown }): () => boolean {
|
||||
let sourceFailed = false;
|
||||
let clientClosed = false;
|
||||
source.once("error", () => { sourceFailed = true; });
|
||||
// A source that closes without ending was cut short.
|
||||
source.once("close", () => { if (!source.readableEnded) sourceFailed = true; });
|
||||
response.once("close", () => { if (!sourceFailed && !response.writableFinished) clientClosed = true; });
|
||||
return () => clientClosed;
|
||||
}
|
||||
@@ -41,8 +41,9 @@ router.post(
|
||||
res
|
||||
);
|
||||
} catch (error) {
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -121,8 +122,9 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
||||
if (!content.closed && !content.destroyed) {
|
||||
content.destroy();
|
||||
}
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
anonymizer.destroy();
|
||||
}
|
||||
content
|
||||
|
||||
Reference in new issue
Block a user