{"record":{"id":"8a2b51453075467d","repo":"MyCATApache/Mycat-Server","slug":"host-duplicated-host","errorCode":null,"errorMessage":"host duplicated : ${host}","messagePattern":"host duplicated : (.+?)","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java","lineNumber":152,"sourceCode":"     * @date 2016/12/8\n     * @modifiedBy Hash Zhang\n     */\n    private void loadFirewall(Element root) throws IllegalAccessException, InvocationTargetException {\n        NodeList list = root.getElementsByTagName(\"host\");\n        Map<String, List<UserConfig>> whitehost = new HashMap<>();\n        Map<Pattern, List<UserConfig>> whitehostMask = new HashMap<>();\n\n        for (int i = 0, n = list.getLength(); i < n; i++) {\n            Node node = list.item(i);\n            if (node instanceof Element) {\n                Element e = (Element) node;\n                String hostStr = e.getAttribute(\"host\").trim();\n                String userStr = e.getAttribute(\"user\").trim();\n                String []hosts = hostStr.split(\",\");\n                for (String host : hosts) {\n                    host = host.trim();\n                    if (this.firewall.existsHost(host)) {\n                        throw new ConfigException(\"host duplicated : \" + host);\n                    }\n                }\n                String []users = userStr.split(\",\");\n                List<UserConfig> userConfigs = new ArrayList<UserConfig>();\n                for(String user : users){\n                    user = user.trim();\n                \tUserConfig uc = this.users.get(user);\n                    if (null == uc) {\n                        throw new ConfigException(\"[user: \" + user + \"] doesn't exist in [host: \" + hostStr + \"]\");\n                    }\n                    if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {\n                        throw new ConfigException(\"[host: \" + hostStr + \"] contains one root privileges user: \" + user);\n                    }\n                    userConfigs.add(uc);\n                }\n                for (String host : hosts) {\n                    host = host.trim();\n                    if (host.contains(\"*\") || host.contains(\"%\")) {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java#L134-L170","documentation":"XMLServerLoader.loadFirewall parses the <firewall><host> section of server.xml, which maps host patterns to allowed users. Each host value must not already be registered in the firewall's host table; if firewall.existsHost(host) is true while adding, it throws this ConfigException. Duplicate host entries would make whitelist enforcement ambiguous.","triggerScenarios":"Loading server.xml at startup; a <host host=\"10.0.0.1\"> element lists an IP/host that a previous <host> element (or an earlier entry in the same comma-separated list) already registered.","commonSituations":"Repeating the same IP in two <host> elements to grant different user groups; including the same host twice within one comma-separated host attribute; merging server.xml fragments that both whitelist the same host.","solutions":["Open server.xml's <firewall> section and remove or merge duplicate host entries so each host/IP appears only once across all <host> elements","If one host needs multiple users, list several users in the single host element's user attribute instead of duplicating the host","Check comma-separated lists within one attribute for repeated values after trimming","Restart MyCat after deduplicating"],"exampleFix":"// before\n<host host=\"10.0.0.1\" user=\"user1\"/>\n<host host=\"10.0.0.1\" user=\"user2\"/>\n// after\n<host host=\"10.0.0.1\" user=\"user1,user2\"/>","handlingStrategy":"validation","validationCode":"// detect duplicate hosts in server.xml firewall section\nSet<String> seen = new HashSet<>();\nNodeList hs = doc.getElementsByTagName(\"host\");\nfor (int i = 0; i < hs.getLength(); i++) {\n    for (String h : ((Element) hs.item(i)).getAttribute(\"host\").split(\",\")) {\n        if (!seen.add(h.trim())) throw new IllegalStateException(\"Duplicate firewall host: \" + h);\n    }\n}","typeGuard":"null","tryCatchPattern":"try {\n    serverLoader.load();\n} catch (ConfigException e) {\n    LOG.error(\"Firewall host duplication in server.xml: \" + e.getMessage());\n    throw new ConfigurationException(\"Each whitelisted host may appear only once\", e);\n}","preventionTips":["Whitelist each host once and group multiple users via the user attribute","Trim and dedupe comma-separated host lists at generation time","Diff-merge server.xml fragments carefully to avoid re-adding hosts"],"tags":["configuration","firewall","duplicate"],"backgroundTag":"conflicting-config-options","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}