spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

StandardApiVersionDeprecationHandler generates nonconforming Sunset HTTP dates

Open hickey-ai opened this issue 1 month ago • 5 comments

Summary

Passing a non-GMT ZonedDateTime to VersionSpec.setSunsetDate() generates a Sunset header with a numeric timezone offset instead of GMT. Single-digit month days are also rendered without the two-digit IMF-fixdate day.

The class advertises RFC 8594 support. RFC 8594 section 3 specifies HTTP-date for the Sunset value; RFC 9110 section 5.6.7 requires senders to generate IMF-fixdate (GMT and a two-digit day). This is a header formatting issue, not a claim of a security vulnerability.

Versions and verification scope

Reproduced using official Spring Framework 7.0.9 Maven artifacts on Windows 11 / OpenJDK 21 / Maven 3.6.3. The same regressions were also executed against eleven relevant, byte-for-byte unmodified source files from main (7.1.0-SNAPSHOT), commit 4dea36c5872b3ad9ac9357a9cd8a077264f88a39, with 7.0.9 supporting dependencies.

The released-artifact project has no copied implementation sources. The current-source project compiles the original classes under review. These are isolated public-API regressions; no full upstream Gradle build, NullAway/checkstyle run, server deployment, or production validation is claimed.

Minimal reproduction

import java.time.ZoneId;
import java.time.ZonedDateTime;

import org.junit.jupiter.api.Test;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.accept.ApiVersionParser;
import org.springframework.web.accept.StandardApiVersionDeprecationHandler;

import static org.assertj.core.api.Assertions.assertThat;

class SunsetHttpDateTests {

    @Test
    void sunsetMustUseGmtAndTwoDigitDay() {
        ApiVersionParser<String> parser = version -> version;
        StandardApiVersionDeprecationHandler handler =
                new StandardApiVersionDeprecationHandler(parser);
        handler.configureVersion("1").setSunsetDate(
                ZonedDateTime.of(2026, 11, 1, 11, 11, 11, 0,
                        ZoneId.of("Asia/Shanghai")));

        MockHttpServletResponse response = new MockHttpServletResponse();
        handler.handleVersion("1", new Object(),
                new MockHttpServletRequest(), response);

        assertThat(response.getHeader("Sunset"))
                .isEqualTo("Sun, 01 Nov 2026 03:11:11 GMT");
    }
}

Expected and actual results

Expected, preserving the instant:

Sun, 01 Nov 2026 03:11:11 GMT

Actual:

Sun, 1 Nov 2026 11:11:11 +0800

The actual handler writes this value to the servlet response; this is not merely a standalone formatter comparison. A GMT date with a two-digit day (November 11) passes, matching the existing upstream test's shape. HTTP client compatibility was not measured.

Root-cause observation

VersionInfo.withSunsetDate uses DateTimeFormatter.RFC_1123_DATE_TIME on the supplied ZonedDateTime without normalizing the instant to GMT. That general formatter also permits a one-digit day.

Spring's existing HttpHeaders.setZonedDateTime() HTTP-date formatting preserves the instant and emits the expected GMT/two-digit form. An isolated candidate reusing this formatter passes both the regression and the original-shape GMT control; the upstream clone remains unchanged.

Related work and references

Searched existing issues/PRs for StandardApiVersionDeprecationHandler, Sunset/GMT, and Sunset timezone formatting; no matching report was found in those results.

  • https://datatracker.ietf.org/doc/html/rfc8594#section-3
  • https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.7

hickey-ai avatar Oct 15 '26 02:10 hickey-ai

Hi, I'd be happy to fix this.

The Sunset header is currently formatted with an RFC-1123 pattern, but HTTP requires the IMF-fixdate format. It's a small change plus a test.

Since the issue is awaiting triage I won't open a pull request yet — let me know if/when you'd like it and I'll pick it up. Thanks!

Yusuf-Hussien avatar Oct 16 '26 18:10 Yusuf-Hussien

Thank you! Feel free to start working on it and submit your PR when ready.

---Original--- From: "Yusuf @.> Date: Sat, Oct 17, 2026 02:27 AM To: @.>; Cc: @.@.>; Subject: Re: [spring-projects/spring-framework] StandardApiVersionDeprecationHandler generates nonconforming Sunset HTTP dates (Issue #37486)

Yusuf-Hussien left a comment (spring-projects/spring-framework#37486)

Hi, I'd be happy to fix this.

The Sunset header is currently formatted with an RFC-1123 pattern, but HTTP requires the IMF-fixdate format. It's a small change plus a test.

Since the issue is awaiting triage I won't open a pull request yet — let me know if/when you'd like it and I'll pick it up. Thanks!

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today! You are receiving this because you authored the thread.Message ID: @.***>

hickey-ai avatar Oct 17 '26 04:10 hickey-ai

@hickey-ai that is not for you to say. This issue is still being triaged so we don't expect contributions at this time.

bclozel avatar Oct 17 '26 05:10 bclozel

@bclozel Understood, and sorry for overstepping. My earlier reply should not have implied maintainer approval or permission to proceed. I retract that invitation and will wait for the maintainers to complete triage before proposing a contribution. @Yusuf-Hussien please follow the maintainers' guidance here.

hickey-ai avatar Oct 17 '26 08:10 hickey-ai

Fixed via 07687e6cc5e473fe37a64f3e033f93b7302b7378

github-actions[bot] avatar Nov 11 '26 15:11 github-actions[bot]