[ZBX-17940] API host.create does not validate proxy_hostid field Created: 2020 Jun 19  Updated: 2023 Oct 11

Status: Confirmed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 5.0.2rc1, 5.2.0alpha1, 6.0.22
Fix Version/s: None

Type: Problem report Priority: Critical
Reporter: Mārtiņš Tālbergs (Inactive) Assignee: Zabbix Development Team
Resolution: Unresolved Votes: 0
Labels: proxy
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File skrew.png    
Issue Links:
Causes
Duplicate

 Description   

When creating host with correct API parameters except for non-existant proxyid in "proxy_hostid" field - technical SQL constraint error is returned.

And one more case below in comments too.

Expected:
User friendly error.



 Comments   
Comment by Oleksii Zagorskyi [ 2023 Oct 11 ]

Zabbix 6.0.23rc1  (checked 5.0.37rc1 too - the same behavior, just API call also needs interfaces data)

Just showing that I have such hostid=10084

mysql> SELECT host FROM hosts where hostid=10084;
+---------------+
| host          |
+---------------+
| Zabbix server |
+---------------+

API host.create all. Note, for proxy_hostid I give ID of the existing host:

{"host":"wrong-proxy-given","groups":[{"groupid":"4"}],"proxy_hostid":"10084"}

Result: success, "hostids": ["10622"] created.
While it should fail !!!

Then in frontend, an error on top of the page:

Undefined offset: 10084 [zabbix.php:22 → require_once() → ZBase->run() → ZBase->processRequest() → ZBase->processResponseFinal() → CView->getOutput() → include() in app/views/configuration.host.list.php:426]
Trying to access array offset on value of type null [zabbix.php:22 → require_once() → ZBase->run() → ZBase->processRequest() → ZBase->processResponseFinal() → CView->getOutput() → include() in app/views/configuration.host.list.php:426]

and the view is screwed up:

If give an not existing hostID=99999, this API/SQL error is returned, which also should not happen as well:

        "code": -32500,
        "message": "Application error.",
        "data": "SQL statement execution has failed \"INSERT INTO hosts (hostid,host,proxy_hostid,name,description) VALUES ('10621','wrong-proxy-given','99999','wrong-proxy-given','')\".",
Generated at Fri Jun 12 03:42:49 EEST 2026 using Jira 10.3.18#10030018-sha1:5642e4ad348b6c2a83ebdba689d04763a2393cab.