The payment secret is used to make sure the amount the sender intends to pay is actually received by the recipient. It is encoded in the BOLT11 invoice, so only the sender and recipient of the payment know about it. The sender adds the payment secret to the onion payload (BOLT4) for the recipient. This way the recipient knows the payload was constructed by the sender and thus the amount was the intended amount.
If the payment secret would not be added in the onion payload, the forwarding node of the final hop could attempt to forward a smaller amount than intended by the sender. If the sender overpaid the invoice, for example because it was a zero amount invoice, the recipient would accept the payment and release the preimage. The forwarding node will have made the difference in a successful attack by 'probing' with a smaller amount.