Implementation:0sec labs 0 loadScope
| Knowledge Sources | |
|---|---|
| Domains | MCP, Scope_Enforcement, Security_Policy |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for loading a scope policy JSON file and resolving an engagement posture that gates tool availability, provided by the 0security core scope module.
Description
The loadScope function loads a JSON scope file and returns a ScopePolicy (host allowlist, path policy). The isScopeEnforcementEnabled and getScopeEnforcementState functions check whether scope enforcement is active. The resolveEngagementProfile function takes EngagementProfileInputs and returns an EngagementPosture that hardens the server's posture (standard vs conservative). Scope enforcement gates offensive tool availability: offensive tools are blocked when enforcement is enabled without an authorized scope.
Usage
Import these when you need to enforce scope boundaries and engagement posture in the MCP server or agent loop. They are Step 2 of the MCP server integration workflow.
Code Reference
Source Location
- Repository: 0security
- File: packages/core/src/scope/scope.ts:L176-178, packages/core/src/scope/activation.ts:L35-37, packages/core/src/scope/engagement-profile.ts:L205+
Signature
export function loadScope(path: string): ScopePolicy;
export function isScopeEnforcementEnabled(): boolean;
export function getScopeEnforcementState(): { enabled: boolean; ... };
export function resolveEngagementProfile(inputs: EngagementProfileInputs): EngagementPosture;
class ScopePolicy {
static fromJsonFile(path: string): ScopePolicy;
match(url: string): ScopeMatch;
// host allowlist, path policy
}
interface EngagementProfileInputs {
profile?: string; // "standard" | "conservative"
scope?: ScopePolicy;
// ... additional inputs
}
interface EngagementPosture {
// hardened posture config that gates tool availability and rate limits
}
Import
import { loadScope, isScopeEnforcementEnabled, getScopeEnforcementState, resolveEngagementProfile } from "@0/core";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| path | string | Yes (loadScope) /// JSON scope file path | |
| inputs | EngagementProfileInputs | Yes (resolveEngagementProfile) /// Profile name + scope |
Outputs
| Name | Type | Description |
|---|---|---|
| loadScope return | ScopePolicy /// Host allowlist + path policy | |
| isScopeEnforcementEnabled return | boolean /// Whether scope enforcement is active | |
| resolveEngagementProfile return | EngagementPosture /// Hardened posture config |
Usage Examples
Scope enforcement in MCP server
import { loadScope, isScopeEnforcementEnabled, resolveEngagementProfile } from "@0/core";
const scope = loadScope("./scope.json");
const posture = resolveEngagementProfile({
profile: "conservative",
scope,
});
console.log(`Scope enforcement: ${isScopeEnforcementEnabled()}`);
console.log(`Posture: ${JSON.stringify(posture)}`);
Scope file format
{
"hosts": ["example.com", "*.target.com"],
"paths": ["/api/*"],
"deny": ["admin.example.com"]
}