The `hpkp` package provides HTTP Public Key Pinning (HPKP) middleware for Express and Connect applications. It facilitates adding the `Public-Key-Pins` or `Public-Key-Pins-Report-Only` headers to web responses, which allows sites to declare cryptographic identities for web servers. However, HPKP as a security standard has been widely deprecated by browser vendors, including Chrome, due to significant risks of misuse and the potential for self-inflicted denial-of-service by rendering a website permanently inaccessible to legitimate users. The package is currently at version 3.0.0 and is explicitly in maintenance mode, indicating it will not receive new feature development but will be maintained for critical bug fixes. Developers are strongly advised against implementing HPKP in new projects and should consider alternatives like Certificate Transparency and Expect-CT headers.
npm install hpkpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate the `hpkp` middleware into an Express.js application, setting a Public Key Pinning header with example SHA256 hashes and optional configurations. It highlights the use of `maxAge`, `sha256s`, and conditional header setting via `setIf`.
Avoid using HPKP in new applications. For existing applications, strongly consider migrating to alternative security mechanisms like Certificate Transparency and Expect-CT headers, which offer similar protections with fewer risks.
Always use `reportOnly: true` and a very short `maxAge` (e.g., 60 seconds) during initial deployment and testing. Ensure robust processes for key rotation and backup key management. Never deploy HPKP without a verified fallback strategy for pin mismatches.
Consider that the underlying technology is no longer actively developed or recommended. If you must use it, be aware of its static nature and potential for obsolescence.
Ensure that the provided hashes are correctly derived from the SPKI of your active and backup certificates, and are properly Base64 encoded. Tools are available to generate these from certificate files.
Before deploying, understand that the impact of HPKP will be limited to older or specific browser versions that still honor the header. The security benefits are minimal given current browser landscape.
During testing, verify `sha256s` values. If in production, and users are locked out, you must either deploy a certificate matching one of the original pinned keys, or if no backup key is available, wait for `maxAge` to expire (which could be months). Using `reportOnly: true` initially can help avoid this.
Ensure the `hpkp` middleware is applied before any routes that should be protected. Check your `setIf` function's logic to confirm it evaluates to `true` for the requests you intend to pin. Verify that `maxAge` is a positive integer.
No dependency data recorded yet.