Build your own advanced USB condom
The job of a USB condom is simple: Turn any USB port into a charge-only port by blocking all the data lines, thereby reducing the attack surface for hackers, pranksters, and vandals to cause damage and mayhem.
And they’re cheap. If you use random USB ports for charging devices when out and about, I recommend you get one because they’re a little insurance in an increasingly chaotic world.
USB condoms have limitations. But you can build your own super USB condom.
The other day I came across USBCondom.org, and on that site are plans for three different types of USB condom, from a basic data blocker to a more sophisticated one that allows for switching between charge to data transfer modes to a really smart one that features anti-USB-killer features to prevent your device being fried by high voltage.
And you can grab everything you need, from the files to get the circuit boards printed (either do it yourself the old fashioned way — expect a lot of hit and miss initially — or have a company make them). There’s even a full component list of everything you need (which really isn’t much, even for the most complicated one!).
Of you can just buy some basic ones that just isolate the data lines from the charge lines. These won’t protect you from attacks such as Juice Jacking or having your equipment nuked by a USB killer, but if you are that worried, stop using random USB charging ports and carry around a power bank with you instead.