validateStrictNetwork validates network configuration in strict mode and refuses "*" wildcard Note: networkPermissions should never be nil at this point because the compiler orchestrator applies defaults (Allowed: ["defaults"]) when no network configuration is specified in frontmatter. This automati
(networkPermissions *NetworkPermissions)
| 16 | // applies defaults (Allowed: ["defaults"]) when no network configuration is specified in frontmatter. |
| 17 | // This automatic default application means users don't need to explicitly declare network in strict mode. |
| 18 | func (c *Compiler) validateStrictNetwork(networkPermissions *NetworkPermissions) error { |
| 19 | // This check should never trigger in production since the compiler orchestrator |
| 20 | // always applies defaults before calling validation. However, we keep it for defensive programming |
| 21 | // and to handle direct unit test calls. |
| 22 | if networkPermissions == nil { |
| 23 | strictModeValidationLog.Printf("Network configuration unexpectedly nil (defaults should have been applied)") |
| 24 | return errors.New("internal error: network permissions not initialized (this should not happen in normal operation)") |
| 25 | } |
| 26 | |
| 27 | // If allowed list contains "defaults", that's acceptable (this is the automatic default) |
| 28 | if slices.Contains(networkPermissions.Allowed, "defaults") { |
| 29 | strictModeValidationLog.Printf("Network validation passed: allowed list contains 'defaults'") |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | // Check for wildcard "*" in allowed domains |
| 34 | if slices.Contains(networkPermissions.Allowed, "*") { |
| 35 | strictModeValidationLog.Printf("Network validation failed: wildcard detected") |
| 36 | return NewValidationError( |
| 37 | "network.allowed", |
| 38 | "*", |
| 39 | "strict mode: wildcard '*' is not allowed in network.allowed domains to prevent unrestricted internet access; expected explicit domains or ecosystem identifiers", |
| 40 | "Use specific domains or supported ecosystem identifiers:\n\nnetwork:\n allowed:\n - github.com\n - api.github.com\n - python", |
| 41 | ) |
| 42 | } |
| 43 | |
| 44 | strictModeValidationLog.Printf("Network validation passed: allowed_count=%d", len(networkPermissions.Allowed)) |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | // validateStrictMCPNetwork requires top-level network configuration when custom MCP servers use containers |
| 49 | func (c *Compiler) validateStrictMCPNetwork(frontmatter map[string]any, networkPermissions *NetworkPermissions) error { |