The principle of least privilege enhances web security by granting users the minimal level of access necessary for their duties, reducing the risk of unauthorized access and potential security breaches.