The Stuttgart striker opened the scoring for Germany with a brilliant first-time finish following a lay-off from Florian Wirtz.
Shortly after, debutant Tim Kleindienst had a goal disallowed due to offside.
Bosnia-Herzegovina had a golden opportunity to equalize when Ermedin Demirovic’s shot hit the post.
Not long after, former Brighton player Undav scored again, this time from a cross by Maximilian Mittelstadt, extending Germany’s lead.
This marked his third international goal in just his fifth cap and second start.
Undav believed he had completed a hat trick, and Serge Gnabry also found the net, but both goals were disallowed for offside.
Edin Dzeko, at 38 years old, gave Bosnia a glimmer of hope with a well-placed header from eight yards out.
However, the hosts were unable to find an equalizer in Zenica.