We analyze contractual clauses which limit the ability of licensees to challenge patents at the basis of their licensing agreements. In particular, we study no-contest clauses, which prohibit licensees from contesting the validity of the patent, and challenge-penalty clauses, which penalize licensees for doing so. We develop a model that we use to compare three legal regimes: “No Restriction,” in which the patent holder is given complete contractual freedom, “Partial Restriction,” in which no-contest clauses are forbidden but challenge penalties are allowed, and “Total Restriction,” in which neither no-contest nor challenge penalty clauses are enforced. We show that No Restriction is unlikely to be optimal, and further, we provide necessary and sufficient conditions under which Total Restriction is optimal. The rule we suggest differs significantly from the one currently applied by most courts.