learning-it by example

Back to the video

Stop Leaking API Keys: Build a Secret Scanner in Python

I hid six fake keys in a project. My first scanner found three.

Video #90 ยท AI security and governance

Steps in the video

  1. 0:00 A scanner that found three of six keys
  2. 0:27 The idea
  3. 0:55 Setup
  4. 1:17 Six habits and a decoy
  5. 1:45 Two scanners
  6. 2:10 An automatic fix
  7. 3:07 What this does not show
  8. 3:40 Mistakes to avoid
  9. 4:04 My take and next steps
  10. 4:35 Recap

Files

  • compare.py (19 lines)
  • fix.py (11 lines)
  • project.py (37 lines)
  • scan.py (26 lines)

Download the code (zip)

Tested with

Python 3.12.15

What this does not show

Six habits I chose and fake keys from a seeded generator; the three shapes are simplified and the entropy limit of 3.2 is a guess; real scanners were not compared; a key that was already pushed stays in the history and must be revoked and replaced.

Sources

Learning IT by Example.