Technically it violates the UL listing of the device to spice the cable like that.
As far as safety and actually doing it, Your fine. It's low voltage (5v) I wouldn't splice the cable but run new cable the entire length and splice in the boxes.
You'll probably need to buy a couple cord grip...