pub struct Policy {
pub allow_local_gateway: bool,
pub allow_local_backend: bool,
}Expand description
Which URLs may receive credentials.
The default policy only allows the hosted Grok Bot gateway and Cursor backend over
https. Every Client call re-checks the gateway URL, and
ensure_sandbox checks both the backend URL and the gateway
URL it gets back. See the POLICY.md guide.
use grokbot_api::Policy;
let p = Policy::default();
assert_eq!(p.check_gateway("https://box.us1.cursorvm.com/").unwrap(), "https://box.us1.cursorvm.com");
assert!(p.check_gateway("https://example.com").is_err());
assert!(p.check_backend("https://box.us1.cursorvm.com").is_err()); // never send the Cursor token to a boxFields§
§allow_local_gateway: boolAllow localhost / 127.0.0.1 / ::1 gateways over http or https.
allow_local_backend: boolAllow a loopback EnsureSandBox backend. Never set from the environment; for tests only.
Implementations§
Source§impl Policy
impl Policy
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
The default policy, plus loopback gateways when ALLOW_LOCAL_ENV is 1/true/yes.
The loopback backend is never enabled from the environment.
Sourcepub fn local_testing() -> Self
pub fn local_testing() -> Self
Allow loopback gateway and backend. Intended for tests against a local mock server.
Sourcepub fn check_gateway(&self, raw: &str) -> Result<String, String>
pub fn check_gateway(&self, raw: &str) -> Result<String, String>
Validate a gateway URL; returns it trimmed and without a trailing slash.
Allowed: https on cursor.sh, cursor.com, *.cursor.sh, *.cursor.com,
*.cursorvm.com; loopback only with Policy::allow_local_gateway. URLs with
userinfo are always rejected. The error is a human-readable reason.
Sourcepub fn check_backend(&self, raw: &str) -> Result<String, String>
pub fn check_backend(&self, raw: &str) -> Result<String, String>
Validate the EnsureSandBox backend base URL (which receives the Cursor access token).
Allowed: https on cursor.sh, cursor.com, *.cursor.sh, *.cursor.com only (never
*.cursorvm.com); loopback only with Policy::allow_local_backend.