Although in principle, it is not necessary to mask for self-attentions in the encoder, in practical implementation it is required to mask the padding positions.
self-attention in the decoder only allows positions up to the current one to be attended to, preventing information flow from the left and preserving the auto-regressive property.