DEV Community

Cover image for Securing API Keys in a Strapi Plugin
Theodore Kelechukwu Onyejiaku
Theodore Kelechukwu Onyejiaku

Posted on Originally published at mystite.com

Securing API Keys in a Strapi Plugin

Padlock on a keyboard

Securing API Keys in a Strapi Plugin

A publishing plugin needs tokens for Medium, Dev.to, and Bluesky. Here's how to keep them safe.

Never hard-code secrets

Keep them out of your source code and out of git.

Option 1: Environment variables

DEVTO_API_KEY=xxxx
MEDIUM_TOKEN=xxxx
Enter fullscreen mode Exit fullscreen mode
// config/plugins.ts
export default ({ env }) => ({
  'content-publisher': {
    config: { devtoApiKey: env('DEVTO_API_KEY') },
  },
});
Enter fullscreen mode Exit fullscreen mode

Option 2: A settings page

If admins should manage keys from the UI, store them with the plugin store and protect the route with admin permissions. Never return the raw key to the browser — send back a masked value like ••••1234.

Checklist

  • [ ] .env is in .gitignore
  • [ ] Settings routes require an admin permission
  • [ ] Keys are masked in API responses
  • [ ] Tokens are rotated if leaked

Top comments (0)