Skip to content

Introduction

SaltyKeys.js is a lightweight JavaScript library designed for developers working on CodePen projects that need to use non-sensitive API keys. It provides a client-side approach to obfuscating and verifying API keys by binding them to a specific CodePen pen ID, making it harder to casually extract and reuse the key elsewhere.

The library uses a combination of techniques:

  • Context-binding — the salted key encodes the pen’s ID, so it only works when decoded in the same pen
  • Multi-level obfuscation — base64 encoding, string reversal, timestamps, and random nonces beyond a simple encode
  • Caching — the extracted pen ID is cached to avoid repeated DOM queries

When you embed an API key directly in a CodePen, it’s visible to anyone who views the pen’s source. SaltyKeys adds a layer of friction: the obfuscated key won’t work if someone simply copies it into a different pen or environment, because the pen ID won’t match.

This is useful for:

  • Demonstrations and experiments — when you want to share a pen that calls an API without making the key trivially portable
  • Educational projects — teaching about API usage without exposing production credentials
  • Quick prototypes — where API key security is not a primary concern

Do not use SaltyKeys.js for:

  • Production applications
  • Projects handling sensitive or paid API services
  • Applications where security is a requirement
  • As a replacement for proper server-side API key management

For real applications, keep API keys on the server:

┌─────────────┐ ┌─────────────┐ ┌───────────────┐
│ │ │ │ │ │
│ Client │──────│ API Proxy │──────│ External API │
│ Browser │ │ Server │ │ Service │
│ │ │ │ │ │
└─────────────┘ └─────────────┘ └───────────────┘
No keys Secure key
management

Use environment variables on your server, never in client-side code. Implement rate limiting and rotate keys regularly.

SaltyKeys.js uses modern JavaScript features with no transpilation step.

BrowserMinimum Version
Chrome92+
Firefox90+
Safari15+
Edge92+

Required browser APIs:

  • window.location
  • document.querySelector()
  • btoa() / atob() for Base64 encoding
  • ES2022 private class fields (#field)
  • Regular expressions