The only way you can get attacked in Alliance areas (Including Major cities) is if you're marked for PvP.
How can you be marked for PvP? Either you have it enabled, or you buffed a PvP-flagged player, or you just came from a contested territory. For the last part, let's say you fly from Ironforge to SW instead of using Deeprun Tram, the gryphon flies through Searing Gorge and marks you for PvP for the next 5 minutes. When you land in SW, you can be attacked by Horde players. On the other hand, if you use Hearthstone, you are not marked for PvP, even if you came from a Contested Territory.
What you can do is, every time you enter an Alliance area, relog once so that you are no longer marked.
As for the 20 second logout, it only happens in rested areas if you're stuck in combat.