Never send raw LLM provider error text back to your app's users
pgEdge RAG Server passed LLM provider errors to anyone, leaking part of the operator's OpenAI key · Security incident · GitHub · pgEdge · Nov 12, 2026
What happened
A GitHub advisory for pgEdge RAG Server (1.0.0 and earlier) says its unauthenticated query API relayed the provider's error message straight to the caller. For OpenAI that message quotes the sk-proj- prefix and the last four characters of the rejected key, so anyone who could trigger a failure saw a fragment of the operator's key. A sibling advisory covers the same leak in pgEdge's Go LLM library; fixes are in 2.0.0 and 0.2.0.
How to prevent it
Log provider errors on the server and show users a generic message instead, put authentication on any endpoint that calls an AI provider, and rotate the key if errors were ever exposed (upgrading doesn't undo a leak). See API key protection.
Fix prompt for your own AI tool
Copy this into your own AI tool (Cursor, Lovable, Claude Code, Bolt…). It's general guidance written by us. Review what the AI suggests before applying it.
I'm a beginner and want to make sure my API keys are safe in my OpenAI API project. 1) Search the code for hardcoded keys or tokens and for secrets in variables that ship to the browser (NEXT_PUBLIC_, VITE_, REACT_APP_). List the file and line, but don't print the values. 2) For each one, tell me whether it's meant to be public (like a Supabase anon key) or secret. 3) For secret ones, show me how to move them to server-side env vars and call the provider through a server route. 4) Give me the steps to rotate each exposed key in the provider's dashboard and set a spending limit. 5) Make sure .env is in .gitignore and in my AI tool's ignore file. Don't change anything until I've approved your plan. Never ask me to paste API keys, passwords or .env contents; tell me where to check them myself.
Why this keeps happening: leaked secrets & api keys
Secret keys placed in front-end code, mobile bundles or public repositories can be found by automated scanners and abused, often running up large bills on AI or cloud accounts before anyone notices.
A quick checklist before you ship
- Keep secret keys only in server-side environment variables, never in browser or app code.
- Set spend limits and usage alerts with every AI and cloud provider.
- Turn on secret scanning and push protection for your repositories.
- If a key leaks, revoke and replace it first; deleting the file is not enough.
More on this: every leaked secrets & api keys story and our related guide.
Tools involved
OpenAI API stories, RAG stories, Go stories
Related stories
- If you self-host n8n with several users, upgrade to 1.123.96, 2.47.6, 2.48.3, 3.2.2 or later and check active workflows for triggers using credentials their owner didn't set
n8n let a member activate a workflow using someone else's credential if they knew its ID - If you self-host the LiteLLM proxy with Azure models, upgrade to 1.106.9, 1.108.6, 1.109.1 or later and rotate the master key if low-trust users had access
LiteLLM proxy: a normal chat request could leak the master key and provider API keys through an Azure error - Never bake API keys or .env files into a container image; pass them at runtime, and if one ever went into a public image, rotate it now even if you deleted the tag
Study: AWS, OpenAI and Anthropic keys left in public Docker Hub images were used within seconds
Source: original post on GitHub ↗. Summarised in our own words; numbers are as stated by the source. Browse all stories.