Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
AI

The AI Prompt That Sniffs Out an Auth Timing Side-Channel

- 02.12.26 - ErcanOPAK

🤖 The AI Prompt That Sniffs Out an Auth Timing Side-Channel

A string comparison like storedHash == providedHash or a naive loop-based token check returns as soon as it finds the first mismatched character, which means a wrong guess that happens to share a correct first few characters takes measurably longer to reject than one that’s wrong from character one — and an attacker measuring response latency over enough requests can use that timing difference to recover a secret one character at a time, without ever seeing the actual value being compared. This pattern hides easily inside password checks, API key validation, HMAC signature verification, and session token comparisons, because the code reads as completely correct — it’s the timing of a correct-looking comparison that leaks the secret, not its logic.

🔎 The Problem

Paste this prompt along with the auth-related file(s) you want checked:

"Scan this code for any place a secret value (password hash, API key,
HMAC signature, session token, CSRF token) is compared against untrusted
input using a standard equality operator, string comparison function, or
character-by-character loop that can return early on a mismatch. For each
one found: show the exact comparison, explain in one sentence why its
runtime depends on how many leading characters match, and give the
constant-time replacement for this specific language/framework (for
example hmac.compare_digest in Python, crypto.timingSafeEqual in Node,
CryptographicOperations.FixedTimeEquals in C#). Do not flag comparisons
of genuinely public, non-secret values."

✅ Fix: Replace Every Flagged Comparison With a Constant-Time One

  • Swap each flagged secret comparison for your language’s built-in constant-time equality function rather than hand-rolling one — these are deceptively easy to get subtly wrong (a short-circuiting length check before the loop starts can reintroduce the exact same leak).
  • Ask the follow-up prompt “Which of these comparisons sits directly on a request path reachable without authentication?” first, since a timing side-channel on an already-authenticated, rate-limited internal endpoint is a far lower priority fix than one sitting on a public login or API-key check.
  • Re-run the same scan after the fix as a regression check — it’s common to fix the main comparison but miss a second one nearby (an “early return if API key is missing” check that still does a non-constant-time length comparison first).

🚨 Why This Is Dangerous

  • A timing side-channel produces zero error logs, zero failed-auth alerts, and zero visible symptoms right up until someone has quietly extracted a valid credential — by the time it’s noticed, there’s no incident to point to, just a comparison that’s been leaking information to every request it ever answered.

A secret comparison that’s logically correct can still be a side-channel — the bug isn’t in what the code decides, it’s in how long it takes to decide it.

— AI Power User

Related posts:

AI — Few-Shot Examples Beat Long Instructions

AI — Few-Shot Examples Beat Long Instructions

The AI Prompt That Catches Missing Signature Verification in Your Webhook Handler Before It Trusts t...

The AI Prompt That Catches Missing Signature Verification in Your Webhook Handler Before It Trusts t...

The AI Prompt That Turns a Scope-of-Work Document Into a List of Which Deliverables Are Vague Enough...

The AI Prompt That Turns a Scope-of-Work Document Into a List of Which Deliverables Are Vague Enough...

Views: 0
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Docker: Fix compose watch Ignoring a Renamed Source File
Git: Fix rerere Replaying a Resolution You Already Reverted

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com