Skip to content

fix(worker): guard against stale public flags when Bitbucket Server feature.public.access is disabled#999

Merged
brendan-kellam merged 1 commit intomainfrom
brendan/fix-bitbucket-server-public-access-SOU-661
Mar 13, 2026
Merged

fix(worker): guard against stale public flags when Bitbucket Server feature.public.access is disabled#999
brendan-kellam merged 1 commit intomainfrom
brendan/fix-bitbucket-server-public-access-SOU-661

Conversation

@brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Mar 13, 2026

Summary

  • When feature.public.access is disabled on a Bitbucket Server instance, per-repo public flags are not reset by Bitbucket — repos that were previously public remain public: true in the API response.
  • This caused Sourcebot's permission filter (clause 3 in getRepoPermissionFilterForUser) to treat those repos as genuinely public, potentially exposing them to users who no longer have access on the code host.
  • Fix: during Bitbucket Server compilation, make a single unauthenticated probe request to one of the reportedly-public repos. If the probe fails (401/403), the feature.public.access flag is assumed disabled and all repos on that instance are treated as private.

Test plan

  • Verify that a Bitbucket Server connection with feature.public.access=true and public repos correctly marks those repos as isPublic: true
  • Verify that a Bitbucket Server connection with feature.public.access=false (but stale public: true repo flags) marks all repos as isPublic: false

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Bitbucket Server repositories being incorrectly marked as public when the instance-level public access feature is disabled. Repository visibility now properly respects the instance-level configuration setting.

…eature.public.access is disabled

When feature.public.access is turned off on a Bitbucket Server instance,
per-repo public flags are not reset, so repos that were previously public
still appear as public: true in the API. This caused Sourcebot to treat
those repos as publicly accessible in the permission filter, potentially
exposing them to users who no longer have access.

Fix by making a single unauthenticated probe request to one of the
reportedly-public repos during compilation. If the probe fails, the
feature flag is assumed disabled and all repos are treated as private.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Walkthrough

This pull request fixes a bug where Bitbucket Server repositories are incorrectly treated as public when the instance-level feature.public.access setting is disabled. A new function probes anonymous access capability to Bitbucket Server, and visibility logic is updated to check both per-repo and server-wide public access settings.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry documenting the fix for Bitbucket Server public access handling when instance-level feature is disabled.
Bitbucket Server Public Access Detection
packages/backend/src/bitbucket.ts
New exported function isBitbucketServerPublicAccessEnabled() that probes Bitbucket Server for anonymous access capability via unauthenticated repository endpoint requests.
Repository Visibility Logic
packages/backend/src/repoCompileUtils.ts
Added import for new public access detection function and integrated runtime check for Bitbucket Server instance-level public access; Bitbucket Server repos now respect both per-repo and server-wide public access flags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

sourcebot-team

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing a guard mechanism against stale public flags in Bitbucket Server when feature.public.access is disabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch brendan/fix-bitbucket-server-public-access-SOU-661
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/backend/src/bitbucket.ts (2)

793-797: Consider logging when the probe is skipped due to missing identifiers.

When projectKey or repoSlug is missing, the function silently returns false, treating it as if public access is disabled. While defaulting to the safer assumption is appropriate, logging a warning here would help diagnose unexpected behavior if a repo from the API has malformed data.

🔧 Suggested improvement
     const projectKey = publicRepo.project?.key;
     const repoSlug = publicRepo.slug;
     if (!projectKey || !repoSlug) {
+        logger.warn(`Cannot probe public access: repo missing projectKey or repoSlug`);
         return false;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/backend/src/bitbucket.ts` around lines 793 - 797, When projectKey or
repoSlug extracted from publicRepo are missing, add a warning log before
returning false: log which identifier is missing and include identifying context
from publicRepo (e.g., publicRepo.id, publicRepo.name or the raw object) so
callers can diagnose malformed API data; implement this in the same block
handling projectKey/repoSlug (use the existing logger instance such as logger or
processLogger), then return false as before.

800-805: Consider adding a timeout to the probe request.

The unauthenticated fetch has no explicit timeout. If the server is slow or unresponsive, this could delay the entire connection sync. Consider adding an AbortSignal with a reasonable timeout (e.g., 10-30 seconds).

🔧 Suggested improvement
+    const PROBE_TIMEOUT_MS = 15000;
     const url = `${serverUrl}/rest/api/1.0/projects/${projectKey}/repos/${repoSlug}`;
     try {
         const response = await fetch(url, {
             headers: { Accept: 'application/json' },
             // Intentionally no Authorization header - we want to test anonymous access
+            signal: AbortSignal.timeout(PROBE_TIMEOUT_MS),
         });
         return response.ok;
     } catch (e) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/backend/src/bitbucket.ts` around lines 800 - 805, The anonymous
probe fetch currently has no timeout and can hang; wrap the request in an
AbortController with a short timeout (e.g., 10–30s), pass controller.signal to
fetch, and clear the timeout after the response is received. Locate the try
block that calls fetch(url, { headers: { Accept: 'application/json' } }) (the
anonymous probe returning response.ok) and add the AbortController logic and a
setTimeout that calls controller.abort(), and ensure any abort errors are
handled so the function returns false or propagates a controlled error as
appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/backend/src/bitbucket.ts`:
- Around line 793-797: When projectKey or repoSlug extracted from publicRepo are
missing, add a warning log before returning false: log which identifier is
missing and include identifying context from publicRepo (e.g., publicRepo.id,
publicRepo.name or the raw object) so callers can diagnose malformed API data;
implement this in the same block handling projectKey/repoSlug (use the existing
logger instance such as logger or processLogger), then return false as before.
- Around line 800-805: The anonymous probe fetch currently has no timeout and
can hang; wrap the request in an AbortController with a short timeout (e.g.,
10–30s), pass controller.signal to fetch, and clear the timeout after the
response is received. Locate the try block that calls fetch(url, { headers: {
Accept: 'application/json' } }) (the anonymous probe returning response.ok) and
add the AbortController logic and a setTimeout that calls controller.abort(),
and ensure any abort errors are handled so the function returns false or
propagates a controlled error as appropriate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79ae73bf-a40c-46d4-9f4a-864bb8f566eb

📥 Commits

Reviewing files that changed from the base of the PR and between 13629e9 and b8fb1d1.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/backend/src/bitbucket.ts
  • packages/backend/src/repoCompileUtils.ts

@brendan-kellam brendan-kellam merged commit a0d4658 into main Mar 13, 2026
9 checks passed
@brendan-kellam brendan-kellam deleted the brendan/fix-bitbucket-server-public-access-SOU-661 branch March 13, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant