Skip to content

fix(snapshot): scope GetLastSnapshot query by teamID to prevent unauthorized cross-team access#2638

Open
AdaAibaby wants to merge 3 commits into
e2b-dev:mainfrom
AdaAibaby:main
Open

fix(snapshot): scope GetLastSnapshot query by teamID to prevent unauthorized cross-team access#2638
AdaAibaby wants to merge 3 commits into
e2b-dev:mainfrom
AdaAibaby:main

Conversation

@AdaAibaby
Copy link
Copy Markdown

Fixes #2637

Problem

Four handlers (sandbox_connect, sandbox_get, sandbox_pause, sandbox_resume) called
SnapshotCache.Get(ctx, sandboxID) which fetches a snapshot by sandbox ID only, then
performed a post-fetch ownership check:

if lastSnapshot.Snapshot.TeamID != teamID {
    return api.NewError(http.StatusNotFound, "snapshot not found")
}

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@cla-bot cla-bot Bot added the cla-signed label May 13, 2026
@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Error parsing command: EOF found when expecting closing quote

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8e62f63f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/api/internal/cache/snapshots/snapshot_cache_test.go Outdated
Comment thread spec/openapi.yml Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a GetByTeam method to the SnapshotCache to enforce team-level scoping for snapshot lookups at the database layer, replacing manual ownership checks in various API handlers. It includes corresponding database queries, comprehensive unit tests, and updates to the OpenAPI specification to support sandbox creation from snapshots. A syntax error was identified in the new test file where the package declaration is duplicated.

Comment thread packages/api/internal/cache/snapshots/snapshot_cache_test.go Outdated
…napshotID from spec

- Remove duplicate 'package snapshotcache' line in snapshot_cache_test.go
  (caused compile error, caught by Codex/Gemini review)
- Revert snapshotID field from NewSandbox schema and related descriptions
  in openapi.yml — backend handler not yet implemented, advertising it
  breaks the API contract (caught by Codex P2 review)
@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Error parsing command: EOF found when expecting closing quote

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 13, 2026

Error parsing command: EOF found when expecting closing quote

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Error parsing command: EOF found when expecting closing quote

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Error parsing command: EOF found when expecting closing quote

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f117e07a5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/api/internal/sandbox/store.go Outdated
Comment on lines +159 to +163
for _, sbx := range orphanSandboxes {
wg.Go(func() {
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), sbxRemoveTimeout)
defer cancel()
s.callbacks.RemoveSandboxFromNode(ctx, sbx)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore add-vs-kill distinction in Reconcile

Store.Reconcile now unconditionally treats every sandbox returned by storage.Reconcile as an orphan and calls RemoveSandboxFromNode, but the memory/populate-redis path still returns sandboxes that are missing from cache and should be added (packages/api/internal/sandbox/storage/memory/sync.go:53-70, forwarded by packages/api/internal/sandbox/storage/populate_redis/main.go:88-89). Since node sync always invokes store.Reconcile (packages/api/internal/orchestrator/nodemanager/sync.go:55) and both config and IaC defaults still use the memory backend (packages/api/internal/cfg/model.go:88, iac/modules/job-api/variables.tf:107-110), an API restart or cache desync will cause healthy running sandboxes to be killed instead of re-registered.

Useful? React with 👍 / 👎.

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Atlantis commands can't be run on fork pull requests. To enable, set --allow-fork-prs or, to disable this message, set --silence-fork-pr-errors

@e2b-atlantis
Copy link
Copy Markdown

e2b-atlantis Bot commented May 14, 2026

Error parsing command: EOF found when expecting closing quote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants