Applying a lowpass filter to a noisy square signal leads to a shift of the signal
The only possible way that any real-world filter can work is by using past values of the signal you're filtering to get the latest filtered value.  So any real-world filter will always have some delay.
So if by &quot;correct this shift&quot; you mean &quot;make it go away&quot; -- not really.
However, if you want to look at the signal and its filtered version after the fact, then yes -- calculate the filter's group delay (or just eyeball it in your data), and in your graphs shift the input over by that amount.  This is easier to do if you use a symmetric FIR filter, because it'll have a constant group delay and the group delay is just half the filter length.
If your goal is to measure the duration and magnitude, then as long as you can have some delay in the measurement then just take your filtered version and feed it into whatever duration-and-magnitude measuring algorithm you've cooked up.  Since the leading and trailing edges of the square wave are offset by the same amount, the measured duration should be just fine.