This is the only time WD-40 gets near my bike. I used the same set of brifters for 22 years and every few years I had to rinse them out liberally. It'll make less of a mess if you can loosen both cables, unbolt the shifter from the handlebar, and hold it over a pan to catch the dirty oil. You'll see waves of dirt come out at first, rinse until it comes clean.
If you have access to an ultrasonic cleaner, all the better.