RTSP Authentication Loop: Fixing 401 Unauthorized, Digest Auth, and Camera Login Failures
A practical guide to RTSP 401 Unauthorized loops, Digest authentication, Basic authentication, stale nonce responses, wrong camera users, and URL credential problems.
An RTSP authentication loop is not defined by one 401 Unauthorized response. The first 401 can be a normal challenge. The loop begins when the client retries and the control exchange still cannot advance—or when authentication succeeds for one RTSP method and fails again at the next protected method.
Debug the session as a sequence of boundaries. Do not reset passwords, change codecs, and rewrite stream paths at the same time; that destroys the evidence needed to tell which change mattered.
First classify the trace
Capture the RTSP method, CSeq, response status, and relevant headers for each exchange. Then place the failure in one of these patterns:
| Trace pattern | What it proves | Next boundary to inspect |
|---|---|---|
| No RTSP response | Authentication has not started | DNS, address, port, routing, firewall, TLS if applicable |
Request → 401 → authenticated retry → success |
Challenge-response worked | Continue through DESCRIBE, SETUP, and PLAY |
Request → 401 with no retry |
Client did not answer the challenge | Supported scheme and credential configuration |
Request → 401 → retry → 401 |
Credentials or challenge calculation rejected | Scheme, user, secret, realm, nonce, URI, account state |
One method succeeds; later method gets 401 |
Login is not globally complete | Authorization header reuse and per-method policy |
Authenticated request gets 404, 454, or another status |
Authentication progressed | Stream path, session state, transport, or server policy |
This table prevents a common mistake: treating every black screen after a login prompt as the same failure.
Boundary 1: parse the RTSP URL correctly
Inline user information must obey URL syntax. Reserved characters in a username or password can change where a parser thinks the credentials, host, port, path, query, or fragment begins.
For example, a literal @ inside the password conflicts with the delimiter before the host. Encode credential components once using a URL-aware method; do not repeatedly encode the entire RTSP URL. Also compare clients: some accept credentials in a separate field, while others parse them only from the URL.
Keep two facts separate:
- Connection target: host and port the client actually contacted.
- RTSP request URI: target placed on the request line and used by authentication.
A parsing error can corrupt either one before the camera evaluates the password.
Boundary 2: distinguish account validity from RTSP permission
A successful camera web login proves that an account exists for the web interface. It does not prove permission to view a particular RTSP channel or profile. On a camera or recorder, verify the account’s live-view, RTSP, channel, and stream-profile permissions using the vendor’s administration surface.
Also check operational account state:
- Was the account locked after repeated attempts?
- Did a password or role change reach every recorder or proxy in the path?
- Is the client still sending a saved credential under another profile?
- Does the URL point to a camera directly or to an NVR channel with separate authorization?
Use a dedicated least-privilege test account when possible. Do not publish a production administrator credential in a trace or support ticket.
Boundary 3: prove which scheme was offered and answered
The server advertises its expected scheme in WWW-Authenticate. A client that receives a Digest challenge but sends Basic credentials has not answered that challenge. A client that never emits Authorization may not support or may not have enabled the advertised method.
For Basic authentication, remember that Base64 is an encoding, not encryption. Protect the management network and transport according to the deployment’s security requirements.
For Digest authentication, a retry can be rejected even when the human-entered password is correct because the response also depends on the server challenge, RTSP method, and request URI. The deeper RTSP Digest authentication guide shows how to compare those fields without exposing the secret.
Boundary 4: follow the complete method ladder
Do not stop after one successful request. A typical session advances through control methods such as:
OPTIONS → DESCRIBE → SETUP (per media track) → PLAY
Implementations vary: a server may challenge OPTIONS, wait until DESCRIBE, or enforce authorization again on SETUP or PLAY. Match each response to its request with CSeq. If DESCRIBE succeeds after a retry but SETUP receives 401, the problem is no longer “the password is definitely wrong.” The evidence points to method-level credential reuse or server policy.
Record whether the authenticated retry preserved:
- the intended RTSP method;
- the exact request URI;
- monotonically sensible
CSeqbehavior; - the selected authentication scheme;
- the current server challenge;
- the correct session identifier once one exists.
Boundary 5: separate a protected path from a valid path
A server can require authentication before revealing whether a resource exists. Therefore a 401 does not validate the stream path. Only after the challenge succeeds can a later status, an SDP response, or a successful setup prove progress toward the intended media resource.
Do not cycle through guessed paths and credentials simultaneously. Hold credentials constant, test a vendor-documented main or substream URL, and record the first response after authentication. This separates “access denied” from “authenticated request reached an invalid resource.”
A minimal, reversible triage procedure
- Save the failing URL with credentials redacted.
- Capture one complete request/response ladder.
- Mark the first
401as challenge or rejection based on the next exchange. - Confirm the advertised scheme and whether a retry was sent.
- Verify account and channel permission separately from web login.
- Test reserved URL characters without changing the account itself.
- Follow authentication through every
SETUPandPLAYrequest. - Move to path, SDP, transport, RTP, or codec analysis only after control authentication advances.
RTSP Inspector keeps OPTIONS, DESCRIBE, SETUP, PLAY, status codes, headers, CSeq, and redacted authentication evidence in one timeline. The Community edition is free and covers RTSP, RTP, RTCP, H.264 inspection, and a JSON report preview. Use it to identify the first failed boundary rather than treating “camera login failed” as a diagnosis.
Digest authentication: compare inputs without exposing the secret
Digest authentication does not send the password directly, but the response depends on several values that must agree between client and server. A correct-looking username and password can still yield another 401 when the realm, nonce, algorithm, URI, method, nonce count, client nonce, or quality-of-protection fields are inconsistent.
| Digest field | Why it matters | Safe evidence to retain |
|---|---|---|
realm |
It scopes the authentication challenge | Redacted challenge header value |
nonce |
Server-supplied freshness input | Value or fingerprint, with capture timestamp |
algorithm |
Client and server must compute the same scheme | Advertised and answered algorithm |
qop / nc / cnonce |
Replay/freshness calculation depends on them when present | Field presence and sequence, not password |
| Request URI | It participates in the response calculation | Exact escaped URI from request line |
| RTSP method | DESCRIBE and SETUP are distinct inputs |
Method and matching CSeq |
Never place an Authorization response, password, or full credential-bearing URL into a public bug report. A redacted trace can still preserve the method, request URI shape, realm, nonce transitions, selected scheme, status code, and relative sequence needed to locate the mismatch.
Handle stale nonce and retry behaviour as a timeline
A nonce can expire or be marked stale. In that case the server should provide a new challenge and the client should recompute a response for the new nonce. Reusing an old Authorization header after a new challenge is different from a wrong password; the trace must show which happened.
| Trace sequence | Evidence-compatible interpretation | Next check |
|---|---|---|
401 with Digest nonce A, retry succeeds |
Normal challenge-response | Continue method ladder |
401 nonce A, retry 401 nonce A |
Credentials/URI/method/algorithm may be wrong | Compare request inputs and account policy |
401 nonce A, retry 401 stale/new nonce B |
Challenge freshness changed | Confirm client recomputes response for B |
Successful DESCRIBE, later fresh 401 |
Per-method/replay/session policy may apply | Header reuse, clock, nonce count, server logs |
| Basic offered alongside Digest | Client selection may vary by library | Record offered and chosen scheme |
Do not send repeated retries faster than a camera or recorder can reasonably process them. Excess attempts can lock an account or hide the original first-failure boundary in a long, noisy trace.
Reproduce authentication with one controlled variable
- Start with a redacted RTSP URL and known permitted channel/profile.
- Capture
OPTIONSthrough the first protected request. - Hold the account and path constant while comparing one client or one credential-delivery method.
- Check the first post-challenge retry for scheme, URI, and nonce change.
- Continue to
DESCRIBE, eachSETUP, andPLAY; note the first method that fails. - If a stale/new nonce appears, repeat once with a fresh session instead of reusing prior headers.
| QA question | Evidence needed |
|---|---|
Is the first 401 normal? |
A subsequent authenticated retry and status |
| Which scheme was offered and selected? | WWW-Authenticate plus Authorization scheme name |
| Did the client retry the correct URI/method? | Request line, method, CSeq progression |
| Did a nonce change? | Ordered redacted challenge values |
| Is the failure auth or later RTSP state? | First non-401 boundary after authentication |
RTSP Digest nonce and realm debugging covers the challenge fields in more depth. Use RTSP 401/404 camera URL diagnostics after credentials have genuinely advanced, and RTSP 454 session not found only when session state, not authentication, is the failure boundary.
Does a successful web login prove the RTSP password is right?
No. Web and RTSP services can use different account permissions, realms, channels, or recorders. It proves only that the web path accepted that account under its own policy.
Should I fall back from Digest to Basic to make the stream work?
Only if the server offers Basic and the deployment's security requirements allow it. Basic over an unprotected network exposes credentials to interception; changing schemes also changes the diagnosis. Record the offered and selected scheme rather than silently switching.
What can a trace prove when credentials are redacted?
It can prove the challenge/retry sequence, method, URI, nonce transition, status, and first failed boundary. Server logs or a controlled credential test are still needed to establish an account-secret mismatch.
Continue with the RTSP Inspector troubleshooting guide, inspect RTSP camera stream diagnostics, or download RTSP Inspector to retain redacted control evidence in a shareable timeline.
How do you prove an RTSP authentication loop is fixed?
Start with a new TCP connection and no reused authorization state. Record the first unauthenticated
request, CSeq, exact protected request URI, 401 response, offered scheme, realm, nonce,
algorithm, qop, and stale flag. For the retry, retain method, URI, scheme, nonce identity, nonce
count, cnonce presence, and next status while redacting the username, password, and response hash.
| Sequence boundary | Expected evidence | Failure interpretation |
|---|---|---|
| Initial request | One bounded unauthenticated request | Repeated requests may already be client looping |
| Challenge | Supported scheme and usable parameters | Missing/changed fields require server review |
| Authorized retry | Same intended method/resource with current challenge | URI, nonce, qop, or policy may differ |
| Advancement | Non-401 response and next RTSP state | Another 401 means authentication did not advance |
| Track SETUP | Per-track URI and any new challenge | DESCRIBE success does not authorize every track |
Compare one known-working client only to identify a changed input; do not copy its credentials or
assume its web-session state applies to RTSP. If the server sends stale=true, permit one retry
with the fresh nonce and verify that nonce count behavior follows the selected qop. Cap automated
retries so a defect cannot create an account lockout or load the camera with an endless loop.
Acceptance requires two clean reconnects: each should receive a challenge, send one valid retry, advance beyond authentication, and preserve the expected session behavior. If DESCRIBE succeeds but one SETUP fails, report that track’s resolved control URI and challenge separately. The Digest nonce and realm guide provides the field-by-field companion review.
Also record the retry limit and final status so support can distinguish a bounded test from an uncontrolled authentication storm.
<!-- multilingual-related-reading:start -->Related guides
Continue with the same-language pages below. They cover adjacent stages without changing the canonical owner of this topic:
<!-- multilingual-related-reading:end -->