{"record":{"id":"6b6e6c28a9691f5d","repo":"jdx/mise","slug":"firewall-rule-name-sets-port-without-protocol","errorCode":null,"errorMessage":"firewall rule '{name}' sets port without protocol","messagePattern":"firewall rule '(.+?)' sets port without protocol","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/firewall.rs","lineNumber":426,"sourceCode":"                .source\n                .map(|source| source.parse::<IpNet>())\n                .transpose()\n                .wrap_err_with(|| format!(\"firewall rule '{name}' has an invalid source\"))?;\n            let destination = rule\n                .destination\n                .map(|destination| destination.parse::<IpNet>())\n                .transpose()\n                .wrap_err_with(|| format!(\"firewall rule '{name}' has an invalid destination\"))?;\n            if source.is_some_and(|source| {\n                destination.is_some_and(|destination| {\n                    source.addr().is_ipv4() != destination.addr().is_ipv4()\n                })\n            }) {\n                bail!(\"firewall rule '{name}' mixes IPv4 and IPv6 source/destination networks\");\n            }\n            let port = rule.port.map(FirewallPort::from_toml).transpose()?;\n            if port.is_some() && rule.protocol.is_none() {\n                bail!(\"firewall rule '{name}' sets port without protocol\");\n            }\n            rules.push(FirewallRule {\n                name,\n                state: rule.state,\n                direction: rule.direction,\n                action: rule.action,\n                port,\n                protocol: rule.protocol,\n                source,\n                destination,\n                interface,\n            });\n        }\n        let ssh_connection = std::env::var(\"SSH_CONNECTION\")\n            .ok()\n            .map(|value| parse_ssh_connection(&value))\n            .transpose()?;\n        let request = Self {","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/firewall.rs#L408-L444","documentation":"A rule sets a `port` but omits `protocol`. A port number is only meaningful for a transport protocol (tcp/udp); without `protocol` mise cannot emit a valid nftables/ufw/firewalld rule, so from_toml rejects the combination at parse time.","triggerScenarios":"Writing `[[firewall.rules]]` with `port = 22` but no `protocol = \"tcp\"` and running a firewall bootstrap command (`mise bootstrap firewall ...`) that constructs FirewallRequest::from_toml. Fires whenever port.is_some() && protocol.is_none().","commonSituations":"Copying a rule snippet that used a default protocol implicitly; hand-writing config assuming tcp is the default; tooling that fills port but not protocol.","solutions":["Add `protocol = \"tcp\"` (or \"udp\") to the rule alongside the port.","If you want to allow all ports, remove the `port` field and rely on protocol/state/action alone.","Define two rules with distinct ports/protocols if both tcp and udp are needed."],"exampleFix":"// before\n[[firewall.rules]]\nname = \"allow-ssh\"\nport = 22\naction = \"allow\"\n\n// after\n[[firewall.rules]]\nname = \"allow-ssh\"\nport = 22\nprotocol = \"tcp\"\naction = \"allow\"","handlingStrategy":"validation","validationCode":"for rule in &firewall_config.rules {\n    if rule.port.is_some() && rule.protocol.is_none() {\n        return Err(format!(\"rule '{}' sets port without protocol\", rule.name));\n    }\n}","typeGuard":"fn port_rule_has_protocol(rule: &FirewallRuleToml) -> bool {\n    rule.port.is_none() || rule.protocol.is_some()\n}","tryCatchPattern":"match FirewallRequest::from_toml(cfg) {\n    Err(e) if e.to_string().contains(\"port without protocol\") => {\n        eprintln!(\"add protocol = \\\"tcp\\\" or \\\"udp\\\" to the rule\");\n    }\n    other => other?,\n}","preventionTips":["Always write port and protocol on adjacent lines so one cannot be omitted.","Template rules with a default protocol = \"tcp\" fill-in.","Validate config with `mise bootstrap firewall status` (dry inspection) before applying."],"tags":["firewall","config-validation","missing-field"],"backgroundTag":"missing-required-config-field","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}