Skip to content

Api for setting up domain transform#2515

Open
sitole wants to merge 20 commits intomainfrom
feat/api-for-setting-up-domain-transform-eng-3871
Open

Api for setting up domain transform#2515
sitole wants to merge 20 commits intomainfrom
feat/api-for-setting-up-domain-transform-eng-3871

Conversation

@sitole
Copy link
Copy Markdown
Member

@sitole sitole commented Apr 28, 2026

Support for setting injection headers. Sandbox creation and network update are supported. Configuration is stored in the database to support the sandbox resume flow.

@linear
Copy link
Copy Markdown

linear Bot commented Apr 28, 2026

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 28, 2026

PR Summary

Medium Risk
Introduces new network-egress behavior and a gRPC schema change that affects sandbox creation/update flows and persistence. Guarded by a feature flag and version checks, but misvalidation or rule propagation issues could impact outbound request handling.

Overview
Adds support for configuring per-domain egress request transform rules (currently header injection/override) on sandbox create and network update, persists these rules in the sandbox network config for resume, and wires them through to the orchestrator via updated gRPC/OpenAPI models. The API now validates rule usage behind a new NetworkTransformRulesFlag and minimum envd version, enforces limits on domain/rule/header sizes, and emits analytics events when rules are set or updated.

Reviewed by Cursor Bugbot for commit a0fe0c0. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread spec/openapi.yml Outdated
Comment thread packages/api/internal/handlers/sandbox_create.go
Comment thread packages/api/internal/handlers/sandbox_get.go
Comment thread spec/openapi.yml Outdated
Comment thread packages/api/internal/handlers/sandbox_network_update.go Outdated
Comment thread packages/api/internal/handlers/sandbox_get.go
sitole added 4 commits April 28, 2026 12:10
Prevents HTTP header injection via network transform rules by checking
for CR and LF bytes in both header names and values before storing or
forwarding them.
Avoid aliasing the internal cache struct by cloning the headers map
before exposing it in the API response. Also fixes a nil pointer to nil
map serializing as "headers":null — when headers are nil the pointer is
left nil so omitempty correctly omits the field.
PUT handler was emitting "sandbox with network transform rules created"
instead of "updated", mislabeling update operations in analytics.
@sitole sitole marked this pull request as ready for review April 28, 2026 10:38
Comment thread packages/api/internal/orchestrator/create_instance.go
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: 4c96456b90

ℹ️ 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/handlers/sandbox_create.go Outdated
Comment thread packages/api/internal/handlers/sandbox_network_update.go
Copy link
Copy Markdown
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

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

few NITs

Comment thread packages/api/internal/handlers/sandbox_create.go Outdated
Comment thread packages/api/internal/orchestrator/create_instance.go Outdated
Comment thread packages/api/internal/handlers/sandbox_create.go
sitole added 2 commits April 29, 2026 14:44
maxNetworkRuleHeaderValueLen was set to 256, which is too small for
common base64-encoded values such as Bearer tokens or API keys that
can easily exceed that length. Raise it to 2048.

Add maxNetworkRuleHeadersPerRule (20) and enforce it in
validateNetworkRules before iterating individual headers. Without a
per-rule header count limit a single rule could carry an unbounded
number of headers.
buildEgressConfig unconditionally allocated an empty map for orchRules
even when rules was nil. Downstream consumers check
`if egress.Rules != nil` to detect whether transform rules are
configured; a non-nil empty map caused a false positive for every
sandbox that was created without any transform rules.

Guard the allocation behind `if rules != nil` so the field stays nil
when no rules were provided.
@sitole sitole requested a review from jakubno April 29, 2026 12:46
Copy link
Copy Markdown
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

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

Can we

Comment thread packages/api/internal/handlers/sandbox_create.go Outdated
@sitole sitole requested a review from jakubno April 29, 2026 17:07
Comment thread packages/api/internal/handlers/sandbox_create.go
Comment thread packages/api/internal/handlers/sandbox_create.go
sitole added 2 commits April 30, 2026 15:52
… version

Adds same envd version logic we already have for volumes.
Re-worked logic a bit so we have helper function that handles all corner cases for us.
@sitole sitole requested a review from arkamar April 30, 2026 14:37
Comment thread packages/api/internal/handlers/sandbox_create.go Outdated
@sitole sitole requested a review from arkamar April 30, 2026 15:33
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a0fe0c0. Configure here.

}

return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unnecessary GetSandbox call on every network update

Low Severity

The GetSandbox call is made unconditionally on every network update request, but sbxInfo.EnvdVersion is only needed when body.Rules is non-nil. When no rules are provided (the common case of just updating allow/deny lists), validateNetworkRules returns nil immediately, making the GetSandbox round-trip pure overhead. The call could be moved inside a body.Rules != nil guard.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a0fe0c0. Configure here.

Err: err,
ClientMsg: "internal error while validating network rules",
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing envd version returns 500 instead of 400

Medium Severity

When envdVersion is empty, checkEnvdVersionRequirement returns errNoEnvdVersion. In validateNetworkRules, this error does not match the errors.Is(err, errNetworkRulesNotSupported) check, so it falls through to the catch-all that returns http.StatusInternalServerError. A missing envd version is a client-side condition (old template that needs rebuilding), not a server error, so returning 500 is misleading to API consumers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a0fe0c0. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is actually reasonable point, I think. Why are we returning internal server error for envd version validation? This would not tell users that they cannot do it for old templates, which might be the case where this is triggered, right? Hope I understand it correctly.

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.

3 participants