spring-projects / spring-projects/spring-security

Add HSTS header also in case of a RequestRejectedException

Open
#16,358 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

By default, Spring sends an HSTS (Strict-TransportSecurity) header, though this can be configured. Requests that are rejected by the StrictHttpFirewall (with a RequestRejectedException) should result in a response with a HSTS header like for all other requests, given that the protocol is HTTPS and HSTS is enabled.

Current Behavior

Requests that are rejected by the StrictHttpFirewall currently do not receive a HSTS header while request that are not rejected, have the header in their response.

Context

The Web Application Scanner we use checks our application for presence of HSTS headers on any request it generates towards a live instance of our application. Some of our endpoints have path parameters (such as /api/v1/resource/:id/subresource), for which the scan creates a request (among others) /api/v1/resource//subresource - note the double slash because the ID is left out. Double slashes lead to a rejection of the request by the StrictHttpFirewall. That in turn results in a response without the HSTS header, which makes our scanner complain.

As a workaround, we have added a Bean for a RequestRejectedHandler that adds the header to the response and then terminates it with status 400.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace how StrictHttpFirewall handles RequestRejectedException and compare that path with the existing HSTS header handling for accepted HTTPS requests. Confirm the behavior with a focused test or reproduction, and consider the issue done when rejected HTTPS requests receive the HSTS header whenever HSTS is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.