{"record":{"id":"35ae7af0c4d0c184","repo":"openai/codex","slug":"network-mitm-hooks-hook-index-host-must-not-be","errorCode":null,"errorMessage":"network.mitm_hooks[{hook_index}].host must not be empty","messagePattern":"network\\.mitm_hooks\\[(.+?)\\]\\.host must not be empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"codex-rs/network-proxy/src/mitm_hook.rs","lineNumber":223,"sourceCode":"            let _ = body;\n            return Err(anyhow!(\n                \"network.mitm_hooks[{hook_index}].match.body is reserved for a future release and is not yet supported\"\n            ));\n        }\n\n        validate_query_constraints(&hook.matcher.query)\n            .with_context(|| format!(\"invalid network.mitm_hooks[{hook_index}].match.query\"))?;\n        validate_header_constraints(&hook.matcher.headers)\n            .with_context(|| format!(\"invalid network.mitm_hooks[{hook_index}].match.headers\"))?;\n        validate_strip_request_headers(&hook.actions.strip_request_headers).with_context(|| {\n            format!(\"invalid network.mitm_hooks[{hook_index}].actions.strip_request_headers\")\n        })?;\n        validate_injected_headers(&hook.actions.inject_request_headers).with_context(|| {\n            format!(\"invalid network.mitm_hooks[{hook_index}].actions.inject_request_headers\")\n        })?;\n\n        if host.is_empty() {\n            return Err(anyhow!(\n                \"network.mitm_hooks[{hook_index}].host must not be empty\"\n            ));\n        }\n    }\n\n    Ok(())\n}\n\npub(crate) fn compile_mitm_hooks(config: &NetworkProxyConfig) -> Result<MitmHooksByHost> {\n    compile_mitm_hooks_with_resolvers(\n        config,\n        |name| env::var(name).ok(),\n        |path| {\n            let value = fs::read_to_string(path.as_path()).with_context(|| {\n                format!(\"failed to read secret file {}\", path.as_path().display())\n            })?;\n            Ok(value.trim().to_string())\n        },","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/network-proxy/src/mitm_hook.rs#L205-L241","documentation":"validate_mitm_hook_config checks that each MITM hook's host is non-empty. In practice this branch is shadowed: normalize_hook_host runs earlier in the same loop (line 183) and already fails with 'host must not be empty' under the context 'invalid network.mitm_hooks[i].host' whenever a host normalizes to nothing, so the line-223 check is a defensive re-check that a successfully normalized (hence non-empty) host cannot trigger.","triggerScenarios":"A [[network.mitm_hooks]] entry with host = \"\" or a whitespace-only host. The error actually observed for this condition is 'invalid network.mitm_hooks[i].host: host must not be empty' from normalize_hook_host; the line-223 message can only appear if the earlier normalization passed an empty host, which its own contract prevents.","commonSituations":"Template config with an unfilled host placeholder; variable substitution rendering an empty string; host key omitted entirely (serde default is the empty string).","solutions":["Set host to an exact hostname, e.g. host = \"api.example.com\"","If config is templated, fail the substitution step when a host renders empty","Expect the sibling normalize_hook_host message with the 'invalid network.mitm_hooks[i].host' context — use its index to find the bad entry"],"exampleFix":"# before\n[[network.mitm_hooks]]\nhost = \"\"\n\n# after\n[[network.mitm_hooks]]\nhost = \"api.example.com\"","handlingStrategy":"validation","validationCode":"// Rust — before compiling hooks\nfor (i, hook) in config.mitm_hooks.iter().enumerate() {\n    if hook.host.trim().is_empty() {\n        return Err(anyhow!(\"network.mitm_hooks[{i}].host is empty\"));\n    }\n}","typeGuard":"fn hook_host_is_set(hook: &MitmHookConfig) -> bool {\n    !hook.host.trim().is_empty()\n}","tryCatchPattern":"match validate_mitm_hook_config(&config) {\n    Ok(()) => {}\n    Err(err) => eprintln!(\"{err:#}\"), // 'invalid network.mitm_hooks[0].host: host must not be empty'\n}","preventionTips":["Fail template substitution when any host renders empty","Always fill host when adding a hook block — it has no useful default","Lint generated config for empty required fields before deploy"],"tags":["network","mitm","codex","config-validation","required-field"],"backgroundTag":"empty-required-config-field","analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","schemaVersion":2},"datasetVersion":"2026-08-25T06:17:31.827Z"}