Skip to content

Remove http_digest - #2849

Open
ericproulx wants to merge 1 commit into
masterfrom
remove/http-digest-dsl
Open

Remove http_digest#2849
ericproulx wants to merge 1 commit into
masterfrom
remove/http-digest-dsl

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Summary

Nothing http_digest could reach has existed since 2.0.0. #2361 removed Rack::Auth::Digest and Grape's :http_digest strategy after Rack 3 dropped digest authentication — but Grape::Middleware::Auth::DSL#http_digest survived, complete with its opaque-defaulting logic, and kept recording its settings happily.

So an API declaring it still booted, and then raised on the first request:

class API < Grape::API
  http_digest(realm: 'r') { |u| lookup_password(u) }   # class loads fine
  get('/x') { 'ok' }
end
Grape::Exceptions::UnknownAuthStrategy: unknown auth strategy: http_digest
  lib/grape/middleware/auth/base.rb:12:in 'initialize'
  rack/builder.rb:164:in 'block in use'

Raised from inside the middleware build, so it escaped as an uncaught exception rather than a response — a misconfiguration only visible in production.

The 4.0 UPGRADING notes pointed at it too, using auth :http_digest, realm: 'API', opaque: 'secret', &proc as a worked example of a supported call.

before after
http_digest(...) with no registered strategy boots, then raises on every request NoMethodError while the class is defined
auth :http_digest, ... with a registered strategy works works, unchanged

Why remove the sugar rather than validate the strategy

I tried validating in #auth so an unregistered strategy raises at definition time. It breaks 6 in-tree specs: dsl_spec.rb has a .http_digest block asserting it "sets auth parameters", and the .auth specs use :http_digest as their example label throughout.

That makes the contract deliberate and specified — #auth records whatever label it is given and resolves the strategy when the middleware is built, which is exactly what lets an application register its own. Validating early breaks that, and would also break registering a strategy after the API class is defined.

So only the sugar goes. auth :http_digest still works for anyone who registered a strategy under that label; verified.

Backward compatibility

UPGRADING entry added, and the existing keyword-arguments section rewritten to stop advertising http_digest.

The removed method supplied two defaults auth does not — realm defaulted to 'API Authorization' and opaque to 'secret' (nested inside realm when realm was itself a Hash) — so UPGRADING spells those out for anyone migrating a custom strategy to auth.

Test plan

  • The .http_digest describe block and its deprecation example are removed; the .auth specs now use a neutral :custom label, which keeps the distinction they are actually about (a label is recorded, the strategy is looked up later).
  • Verified http_digest now raises NoMethodError at definition, and that auth :http_digest with a registered strategy still authenticates (200).
  • Full RSpec suite passes locally (2540 examples, 0 failures — three fewer than before, being the removed examples).
  • RuboCop clean.
  • CI green.

🤖 Generated with Claude Code

Nothing it could reach has existed since 2.0.0. #2361 removed
Rack::Auth::Digest and Grape's :http_digest strategy after Rack 3 dropped
digest authentication, but Grape::Middleware::Auth::DSL#http_digest survived
and kept recording its settings, so an API declaring it still booted --
and then raised Grape::Exceptions::UnknownAuthStrategy on the first request,
from inside the middleware build, as an uncaught exception rather than a
response. A misconfiguration only visible in production.

The 4.0 UPGRADING notes still used `auth :http_digest, realm: 'API', opaque:
'secret'` as a worked example of a supported call, so the documentation
pointed at it too. That section is rewritten, and the removal documented.

Removing the sugar rather than validating the strategy when `auth` is called:
#auth deliberately records whatever it is given and resolves the strategy when
the middleware is built, which is what lets an application register its own.
That contract is specified -- validating early breaks it, and would break
registering a strategy after the API class is defined. `auth :http_digest`
therefore still works for anyone who registered one; only the sugar is gone,
along with the two defaults it supplied (realm 'API Authorization', opaque
'secret'), which UPGRADING spells out.

The DSL specs used :http_digest as their example label for #auth itself. They
now use a neutral :custom, which keeps the distinction the specs are actually
about: #auth records a label, the strategy behind it is looked up later.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the remove/http-digest-dsl branch from de85b55 to 2e12a20 Compare August 1, 2026 12:53
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant