Fix HostAuthorization blocking all RSpec requests in Rails 8.1 #104
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "103-fix-hostauthorization-blocking-all-rspec"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Rails 8.1's
HostAuthorizationmiddleware ignoresconfig.hosts.clearand enforces its own exclude list, causing every request spec to return 403. Addingconfig.host_authorization = { exclude: ->(request) { true } }bypasses host checks in the test environment.Changes
config/environments/test.rb-- Addedconfig.host_authorizationexclude lambda alongside existingconfig.hosts.clearso the HostAuthorization middleware permits all hosts during testsTest Plan
docker compose run --rm -e RAILS_ENV=test web bash -c "bundle install --quiet && bundle exec rspec"-- 88 examples, 0 failuresconfig/environments/test.rbis touched; development and production configs are unchangedReview Checklist
Related Notes
None.
Related
Closes #103
QA Review -- PR #104
Diff Analysis
File changed:
config/environments/test.rb(+3 lines, 0 deletions)The fix adds
config.host_authorization = { exclude: ->(request) { true } }to bypass Rails 8.1's HostAuthorization middleware in the test environment. This is the correct approach -- Rails 8.1 decoupledHostAuthorizationfromconfig.hosts, so clearingconfig.hostsno longer prevents the middleware from rejecting requests with unrecognized hosts likewww.example.com.Checklist
config.host_authorizationwith an exclude lambda is the documented Rails 8.1 approachlandscaping-dev.tail5b443a.ts.netat line 76), production.rb untouched103-fix-hostauthorization-blocking-all-rspecfollows{issue}-{kebab}conventionCloses #103, test plan, and review checklistFindings
No issues found. The change is minimal, correct, well-commented, and properly scoped.
VERDICT: APPROVE
PR #104 Review
DOMAIN REVIEW
Tech stack: Ruby on Rails 8.1.3, RSpec, Docker Compose
Change: A 3-line addition to
config/environments/test.rbthat addsconfig.host_authorization = { exclude: ->(request) { true } }alongside the existingconfig.hosts.clear, fixing Rails 8.1's HostAuthorization middleware blocking all RSpec request specs with 403.Rails domain assessment:
HostAuthorizationmiddleware maintains its own exclude list independent ofconfig.hosts. Clearingconfig.hostsalone no longer suppresses host checks. Theexcludelambda returningtruefor all requests is the documented bypass.test.rbonly. Development and production configs are untouched -- confirmed by reading both files. Production'sconfig/environments/production.rbeven has the same pattern as a commented example on line 98 (exclude: ->(request) { request.path == "/up" }), which validates that this API is the intended Rails configuration surface.config.hosts.clearis retained for backward compatibility context, which is fine -- it is a no-op in 8.1 but documents intent.BLOCKERS
None.
This is a config-only fix in the test environment. The "new functionality with zero test coverage" blocker criterion does not apply -- the fix is what makes the existing 88 RSpec examples runnable again. The test plan documents 88 examples, 0 failures.
NITS
None. The change is minimal, well-commented, and correctly scoped.
SOP COMPLIANCE
103-fix-hostauthorization-blocking-all-rspecfollows{issue-number}-{kebab-case-purpose}conventionPROCESS OBSERVATIONS
VERDICT: APPROVED
Review: APPROVED
Diff: 3 lines added to
config/environments/test.rb— minimal and safe.What it does: Adds
config.host_authorization = { exclude: ->(request) { true } }alongside the existingconfig.hosts.clear. In Rails 8.1, theHostAuthorizationmiddleware can enforce its own exclude list independently ofconfig.hosts, so this belt-and-suspenders approach ensures test requests fromwww.example.com(RSpec default) are never blocked.Verified:
test.rbis touched — dev and production configs unchangedShip it.