Usb condom ?
Privacy
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
Or a portable battery instead of connecting devices to untrusted USB ports.
The problem with this solution is that your device will only charge at legacy 5V low power charging. The data pins are used to negotiate charging rates between devices and without this capability the charger will only deliver the known-safe basic low power charging rate.
That’s why you plug your power bank into the charger and plug your phone into the power bank.
It’s mind-boggling how many people raw dog USB ports in public spaces, airplanes, and Ubers.
While researchers have demonstrated charging-port attacks in controlled settings, as of May 2023, multiple reviews have found no credible reported cases of juice jacking on mobile OSs outside of research efforts, and experts generally assess the risk to typical users as low relative to other threats.
Its entirely a non-issue until there's literally any commercially viable real-world application of this. You should be more worried about NFC relay attacks and other real world attack vectors.
Or just use a power USB cable after testing that it only charges and doesn't comm with any of your devices.