Skip to content

Commit 5866df3

Browse files
committed
typo and format issues
1 parent 272f9ff commit 5866df3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

_posts/2025-07-31-drf-authentication-order-bug.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ toc_label: "DRF Auth Internals"
2525
toc_icon: "bug"
2626
---
2727

28-
# Introduction
28+
# The sneaky bug
2929

3030
Not all bugs scream at you. Some whisper in 403s.
3131

@@ -35,7 +35,7 @@ After triple-checking everything and diving deep into DRF’s internals, I found
3535

3636
Let me walk you through what happened, what I learned, and why I believe this is a real bug in DRF.
3737

38-
# Background: DRF Authentication Flow
38+
## Background: DRF Authentication Flow
3939

4040
In DRF, authentication is handled by a list of classes defined in `DEFAULT_AUTHENTICATION_CLASSES`. Each class tries to authenticate the request, raising `AuthenticationFailed` on failure or returning `None` if it chooses not to act.
4141

@@ -59,7 +59,7 @@ Because DRF uses the **first** authenticator’s header presence to decide statu
5959

6060
The rationale: session first → no header → 403; token-first → header present → 401.
6161

62-
# My Setup
62+
## My Setup
6363

6464
I had this configuration:
6565

@@ -77,7 +77,7 @@ My `BearerAuthentication` inherits from `BaseAuthentication` and returns `"Beare
7777

7878
Yet failed bearer requests returned **403**, not **401**-because `SessionAuthentication` came first.
7979

80-
# DRF Source Code Digging
80+
## DRF Source Code Digging
8181

8282
In `rest_framework/views.py` (around line 189), DRF handles exceptions like this:
8383

@@ -139,7 +139,7 @@ Until then, the only reliable workaround is:
139139

140140
👉 **Always put the authenticator likely to raise errors (e.g. your BearerAuthentication) *first* in the list, or implement your own exception handler**
141141

142-
# Conclusion
142+
## Conclusion
143143

144144
This subtle auth-status behavior can sneakily break API logic or client-side handling. DRF’s current design serves spec compliance-but sacrifices developer intuition when multiple authentication schemes are involved.
145145

0 commit comments

Comments
 (0)