Skip to content

Fix 500 on tokenless POST to unknown paths; ignore 4xx in EB health - #455

Merged
ndemianc merged 3 commits into
developfrom
fix/static-404-and-eb-health-4xx
Oct 18, 2026
Merged

ndemianc merged 3 commits into
developfrom
fix/static-404-and-eb-health-4xx

Conversation

@ndemianc

Copy link
Copy Markdown
Member

Why

Elastic Beanstalk emailed Thinly-env health flips (Ok -> Severe 89% 4xx at 12:01 UTC, Ok -> Degraded 63% 4xx at 18:27 UTC on 2026-10-18). The instance was healthy both times. The EB log bundle shows scanner bursts (about 320 requests in 3 min of /wp-login.php, /.env, /.git/config, /actuator/health) answered 404/403 by design, which EB counts against health.

The logs also showed a real bug: about 1,400 POST /login requests on 2026-10-17 returned 500 (NoMethodError: undefined method 'flash=' from ApplicationController's :null_session CSRF handler; the api_only app has no Flash middleware in production).

Changes

  • StaticController: skip_forgery_protection, so tokenless non-GET requests hitting the catch-all route return 404 instead of 500. The spec fails without the fix (4 failures) and passes with it.
  • .ebextensions/06_health_rules.config: disable the ApplicationRequests4xx and ELBRequests4xx enhanced-health rules. 5xx, latency and instance checks stay on.

Test plan

  • bundle exec rspec spec/requests/static_spec.rb (17 examples, 0 failures); rubocop clean
  • After deploy: confirm aws elasticbeanstalk describe-configuration-settings shows the ConfigDocument, and curl -X POST https://thin.ly/login returns 404

Not validated: the .ebextensions file has not been applied to the live environment.

…404, not 500

The catch-all route sends any verb to StaticController#not_found, which inherited
ApplicationController's :null_session CSRF handler. That handler calls
request.flash = nil, which this api_only app does not define in production
(no Flash middleware), so bot probes like POST /login raised NoMethodError and
returned 500 (about 1,400 of them on 2026-10-17). Skip forgery protection on
this page-only controller.
Internet scanners probing /.env, /wp-login.php etc. produce short 4xx bursts that
flip Thinly-env Ok -> Degraded/Severe -> Ok. Disable the ApplicationRequests4xx
and ELBRequests4xx health rules; 5xx, latency and instance checks stay on.
Copilot AI balanced review requested due to automatic review settings October 18, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The health configuration needs corrected JSON serialization and rule structure before deployment.

1 open issue
What changed in this PR

Fixes tokenless requests to unknown paths and reduces scanner-driven Elastic Beanstalk health alerts.

Changes:

  • Skips CSRF protection in the static-page and catch-all controller.
  • Adds regression coverage for tokenless POST, PUT, PATCH, and DELETE requests.
  • Configures enhanced health to ignore 4xx responses.
File Description
spec/​requests/​static_spec.rb Tests that tokenless requests return 404.
app/​controllers/​static_controller.rb Bypasses the failing CSRF handler.
.ebextensions/​06_health_rules.config Adds 4xx health-rule overrides.

Review effort: Balanced

Comment thread .ebextensions/06_health_rules.config Resolved
….Instance

EB rejects a nested YAML mapping and the Rules.Instance scope. Verified with
aws elasticbeanstalk validate-configuration-settings against Thinly-env.
@ndemianc
ndemianc merged commit 5e31527 into develop Oct 18, 2026
3 checks passed
@ndemianc
ndemianc deleted the fix/static-404-and-eb-health-4xx branch October 18, 2026 20:44
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.

2 participants