If he saw something in plain sight through the window then it can be used as probable cause to search the vehicle. But yeah, it’s still sketchy.
Also with regards to the title, he’s not an “undercover” cop if he has a badge around his neck. He’s a plainclothes office, most likely a detective.