Skip to main content

Command Palette

Search for a command to run...

Your Backend Is Leaking Secrets (Mine Was Too)

Updated
4 min read
Your Backend Is Leaking Secrets (Mine Was Too)

Ever had that feeling where your app works perfectly… but deep down you know it's kinda unsafe?

Yeah — that was me.

So I went all-in on fixing some serious backend security flaws in my project: 👉 BAR (Burn After Reading) — a secure file system with self-destruct capabilities.

And honestly? This round of fixes made the project feel 10x more production-ready.

Let me walk you through what I fixed — in a way that actually makes sense 👇


🚨 The Problem

The app was functional, but under the hood:

  • Sensitive error messages were leaking 😬

  • Debug print() statements were everywhere

  • Logging wasn’t structured

  • Some code paths were… let’s say “questionable choices”

Nothing was breaking — but from a security perspective? It needed serious tightening.


🛠️ What I Fixed (The Real Stuff)

1. 💀 Killing Error Leaks (Big One)

Before:

detail=str(e)

Yeah… that means if something fails, users might see internal errors, stack traces, even SMTP failures.

After:

detail=security.OPAQUE_500_DETAIL

Now:

  • Users get a generic safe message

  • Real errors go to logs (where they belong)

👉 Result: No internal system info leaks to clients


2. 🧼 Cleaning Up a Dead Function Parameter

There was this:

sanitize_error_message(error: str)

But… the parameter wasn’t even used properly 🤦‍♂️

So I:

  • Removed the useless parameter

  • Exported a clean constant:

OPAQUE_500_DETAIL

👉 Cleaner code, less confusion, fewer mistakes.


3. 📧 Fixing OTP Email Leak

This one was sneaky.

If OTP sending failed, the API returned:

detail=error_msg

Which could expose:

  • SMTP issues

  • Email service internals

After fix:

logger.error(...)
detail=security.OPAQUE_500_DETAIL

👉 Now:

  • Users see nothing sensitive

  • Devs still get full logs


4. 🕵️ Tamper Detection Logging (Finally Useful)

Before:

print(f"🚨 tamper detected: {tamper_exc}")

After:

logger.warning("[SECURITY] Possible tamper detected …")

👉 Why this matters:

  • Works with logging systems

  • Can trigger alerts

  • Actually usable in production


5. ⚠️ Logger Setup Order Fix

Yeah… this was subtle.

Before:

router = APIRouter()
logger = get_logger()

After:

logger = get_logger()
router = APIRouter()

👉 Prevents weird initialization issues and keeps things clean.


6. 🧯 Removing All print() From Security Logic

This was a big cleanup.

Replaced things like:

print("Wrong password")
print("File destroyed")
print("Brute force attempt")

With:

logger.warning(...)
logger.info(...)

👉 Why this matters:

  • print() = invisible in production

  • logger = structured, searchable, monitorable


✅ Verification (No Guesswork)

I didn’t just “hope it works” — I verified everything:

  • ✅ No sanitize_error_message() calls left

  • ✅ No detail=str(e) anywhere

  • ✅ No security-related print() calls

  • ✅ OTP leaks completely removed

  • ✅ All files compile cleanly

  • ✅ Logging is consistent across modules


🧠 What I Learned

Honestly, this round of fixes taught me something important:

Secure code isn’t about big features — it’s about small decisions done right.

Things like:

  • Not exposing errors

  • Logging properly

  • Keeping APIs predictable

These are the details that separate: 👉 a “working app” from 👉 a production-ready system


🚀 Final Thoughts

This wasn’t a flashy update.

No UI changes. No new features.

But under the hood?

👉 It made the app way more solid, safer, and professional


🔗 Check Out the Project

If you’re curious or want to explore the code:

👉 https://github.com/Mrtracker-new/BAR\_RYY


💬 If You’re Building Something…

Take this as a reminder:

  • Don’t trust raw error messages

  • Never leave print() in security logic

  • Logging is your best friend

  • Small fixes = big impact

More from this blog

B

Beginning

22 posts

This is a space where I share my journey as a beginner developer — the experiments, the mistakes, and the little victories along the way.