The answer to the question on how to tell if a USB device is safe is that it's complicated. What should tip people off on an unsafe device is the use of a USB-A port as an input. The USB-A port is never used as an input to a device.
There are safe ways to connect USB-A to USB-A but they are so rare that unless you know of a specific reason to do this don't do it. Unfortunately there are a lot of non-compliant devices and cables on the market that use the USB-A port as an input. I don't know why they do this, maybe the USB-A port is cheaper to make than a USB-B port and they can save a few pennies this way.
There's two kinds of compliant USB-A to USB-A cables. The first isn't really a cable but a device. These will sometimes be called "easy transfer cables" or "laplink cables" because they play off trade names from Microsoft and LapLink. There's one clue you are dealing with something shady, they use trademarked names on their products without attributing them. If done right these cables are safe because there is no direct electrical link between the two ports. While it might look like a USB cable with a RF choke in the middle there's actually a pair of network adapters and an opto-coupler in that lump in the middle. Unless you know what they are for then avoid them.
The other kind of compliant USB-A to USB-A cable is often called a "USB 3.0 debug cable". These are passive cables, no isolation in the middle, and perhaps no bump in the middle either. These are safe because they do not use the power and data pins for USB 2.0 backward compatibility. These are also specialty cables and unless you know what they are for then avoid them. In both cases the USB compliant cables I describe are perfectly safe but I suggest avoiding them because they are too easy to confuse with the far more common non-compliant cables.
I went through that in such detail because there are legitimate reasons to have a USB-A connector on both ends of a cable, it's that these are rarely used. If you see them somewhere then chances are they are not safe to use. Think of these like an electrical extension cord with a three prong plug on each end. There are very very rare cases to use a cable like this. For most people this is just asking to plug one wall outlet into another and make a short circuit, tripping a circuit breaker and potentially damaging some outlets.
The USB-A port on a computer or hub is like an outlet on a wall, power is to flow out and only out. If power is flowing in then someone did something unsafe.
The USB-B port is only to have power flow in. The misuse of this port is not all that common, I don't know why. Because power only flows in these ports the potential to short something out with a USB-B port or a cable with a USB-B connector is pretty slim.
USB-C and USB-AB are ports that allow power to flow in either direction. USB-AB ports are quite rare so you if in the slim chance you happen across one you might not even know it because it looks and acts a lot like a USB-B port. I will only mention that they exist because they are rare and you are not likely to see them. If you do see one then it's perhaps best to just pretend they are a USB-B port.
Because a USB-C port can act as an input or output there are compliant cables with a USB-C connector on one end and just about anything else on the other end, including another USB-C connector. When USB-C first came out there was a great number of these cables that were not wired correctly. How do you know the cable you see is compliant? The presence of the USB "trident" symbol is a good sign. Cheap non-compliant cables will likely not bother to put the symbol on the cable. If by chance someone does put the symbol on the cable and it doesn't comply then the people that enforce the spec can go after the violators for trademark infringement, and that carries a lot of weight in law. Making cheap cables is not a crime, trademark infringement is.
The same goes for cables with USB-A and USB-B connectors, if there's no trident symbol then the chances of being a dangerous cable is quite high. USB compliant devices should have this USB trident symbol somewhere as well.
Another dangerous and common USB item you could come across are a specific kind of USB adapter. There's people that will want to take a USB-C device, with a captive USB-C connector, and want to plug this into a computer with a USB-A port. Adapters for this exist but they violate the spec. These are dangerous so don't buy them, and don't buy any device that comes with them. These will have a female USB-C port and a male USB-A connector. They violate the spec in a number of ways. One is that they could potentially connect a power supplying port to another power supplying port.
I could keep going but this is already a lot to process. I know I cited nothing when I probably should have. Linking to the USB spec sheets are problematic because it seems the spec sheets keep moving around on the USB website. I gave one short answer at the beginning, it's complicated. Another short answer is to look for the USB trident symbol. All that I had in the middle is to do a best guess overview on what concerns you.