Cloudflare

Using Cloudflare Workers to identify pwned passwords

Feb 26, 2018John Graham-Cumming
Using Cloudflare Workers to identify pwned passwords
SummaryAI, from the source post

This post introduces the implementation of a Cloudflare Worker that intercepts POST requests, extracts a 'password' field, calculates its SHA-1 hash, and checks the first 5 characters against the Pwned Passwords API range. If a match is found for the remaining characters, a 'Cf-Password-Pwnd: YES' header is added to the request before it's forwarded to the origin. The Worker also includes basic error handling and demonstrates the use of `crypto.subtle.digest` for hashing and `fetch` for subrequests.

More from the Edge Computing with Cloudflare Workers trail