Skip to content

Commit 482367c

Browse files
committed
Sanitize and bound raw HTTP response body in BitbucketResponseError
Truncate the response body to 512 characters before storing it in BitbucketResponseError.responseBody. This prevents sensitive data exposure (tokens, internal paths) and excessively large error payloads (HTML error pages) from propagating through error chains and logs. The bound is applied in the responseError() helper before constructing the error, consistent with the existing transportSafeSourceControlErrorValue pattern used elsewhere in the source control layer.
1 parent bbb7b63 commit 482367c

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

apps/server/src/sourceControl/BitbucketApi.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
2727

2828
const DEFAULT_API_BASE_URL = "https://api.bitbucket.org/2.0";
2929

30+
const MAX_RESPONSE_BODY_LENGTH = 512;
31+
3032
const BitbucketApiEnvConfig = Config.all({
3133
baseUrl: Config.string("T3CODE_BITBUCKET_API_BASE_URL").pipe(
3234
Config.withDefault(DEFAULT_API_BASE_URL),
@@ -488,15 +490,20 @@ function responseError(
488490
cause,
489491
}),
490492
),
491-
Effect.flatMap((body) =>
492-
Effect.fail(
493+
Effect.flatMap((body) => {
494+
const trimmed = body.trim();
495+
const bounded =
496+
trimmed.length > MAX_RESPONSE_BODY_LENGTH
497+
? `${trimmed.slice(0, MAX_RESPONSE_BODY_LENGTH)}…`
498+
: trimmed;
499+
return Effect.fail(
493500
new BitbucketResponseError({
494501
operation,
495502
status: response.status,
496-
responseBody: body,
503+
responseBody: bounded,
497504
}),
498-
),
499-
),
505+
);
506+
}),
500507
);
501508
}
502509

0 commit comments

Comments
 (0)