Skip to content

🐛 Ignore invalid If-Modified-Since in catalogd metas handler - #3214

Merged
openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
andretorresdg:fix-ims-invalid-date
Nov 30, 2026
Merged

openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
andretorresdg:fix-ims-invalid-date

Conversation

@andretorresdg

@andretorresdg andretorresdg commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a request to /{catalog}/api/v1/metas carries an If-Modified-Since header that is not a valid HTTP-date, checkIfModifiedSince calls httpError, which writes a 500 Internal Server Error response, and then returns condNone. checkPreconditions therefore returns false, and handleV1Metas goes on to stream the catalog into the same response. The client gets status 500 with a body of 500 Internal Server Error\n followed by the catalog content (and the server logs an HTTP error at error level).

RFC 9110 section 13.1.3 says a recipient MUST ignore If-Modified-Since if the value is not a valid HTTP-date. That is what the upstream net/http/fs.go code this file was copied from does, and what the /api/v1/all endpoint already does because it uses http.ServeContent. This change drops the httpError call (and the http.ResponseWriter parameter that was only used for it), so an invalid date is ignored and the catalog is served normally.

Reproduction before the fix:

GET /test-catalog/api/v1/metas
If-Modified-Since: not-a-date

-> 500, body: "500 Internal Server Error\n{\"schema\":\"olm.package\",\"name\":\"foo\"}\n"

Added TestHandleV1Metas_IfModifiedSince to internal/catalogd/server/handlers_test.go, covering a 304 when the catalog is unchanged, a 200 when it changed, and a 200 with only the catalog body when the date is invalid. Note on #2879 (open): it also changes this branch of checkIfModifiedSince, keeping the 500 but stopping the catalog from being streamed after it. This PR instead follows RFC 9110 and ignores the invalid header, as net/http and /api/v1/all do. The two touch the same lines, so whichever merges second needs a small rebase; happy to adjust to whichever behaviour you prefer.

How I tested

  • go test ./internal/catalogd/server/: the new invalid date is ignored case fails without the fix (status 500, error text prepended to the body) and passes with it. The other cases pass in both.
  • go test ./internal/catalogd/storage/ (which includes an If-Modified-Since integration case) passes.
  • go tool golangci-lint run ./internal/catalogd/server/...: 0 issues.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Summary by CodeRabbit

  • Bug Fixes
    • Invalid If-Modified-Since dates are now ignored, allowing catalog metadata requests to return the content normally.
    • Requests with a matching modification date continue to receive a 304 response with no content; earlier dates receive the catalog content.
  • Tests
    • Added coverage for catalog metadata responses with matching, earlier, and invalid modification dates.

checkIfModifiedSince called httpError when the If-Modified-Since
header could not be parsed, which wrote a 500 response, and then
returned condNone, so handleV1Metas went on to stream the catalog
into the same response. Clients got a 500 status whose body was
"500 Internal Server Error" followed by the catalog content.

RFC 9110 section 13.1.3 says a recipient must ignore If-Modified-Since
when its value is not a valid HTTP-date, and that is what the
upstream net/http code this file was copied from does (and what the
/api/v1/all endpoint already does through http.ServeContent). Drop the
httpError call and the now unused ResponseWriter parameter.

Add handler tests for a 304 on an unchanged catalog, a 200 when it
changed, and a 200 with the plain catalog body for an invalid date.

Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
@netlify

netlify Bot commented Nov 29, 2026

Copy link
Copy Markdown

👷 Deploy request for olmv1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a7f09ff

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The precondition check now ignores invalid If-Modified-Since dates. Tests cover metadata responses for equal, earlier, and invalid dates.

Changes: Catalog metadata date preconditions

Layer / File(s) Summary
Date precondition handling and tests
internal/catalogd/server/http_preconditions_check.go, internal/catalogd/server/handlers_test.go
Invalid If-Modified-Since dates are ignored. Tests check that an equal timestamp returns 304 with an empty body, while an earlier timestamp or invalid date returns 200 with the catalog content.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: anik120, grokspawn

Merge Risk: Minimal · up to a7f09

Requests to the metas endpoint with a malformed If-Modified-Since header now return the catalog normally instead of a 500 error followed by the catalog body. Valid conditional requests behave as before, and the new tests cover the changed behavior. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the catalogd metas handler now ignores an invalid If-Modified-Since header. The 🐛 prefix matches the template's bug-fix convention. The title is specific and matches t…
Description check Passed The description covers the problem, the RFC 9110 basis, the code change, a reproduction, the new test, test results, and a note on related PR #2879. It follows the template's Description section. The …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the catalogd metas handler now ignores an invalid If-Modified-Since header. The 🐛 prefix matches the template's bug-fix convention. The title is specific and matches the raw summary and PR objectives.

Full details: Description check

Explanation

The description covers the problem, the RFC 9110 basis, the code change, a reproduction, the new test, test results, and a note on related PR #2879. It follows the template's Description section. The Reviewer Checklist is copied unchecked, which is expected for an open PR. It does not link a GitHub issue, which the checklist asks for, but the core content is complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b65f14ca-e5c0-4e0c-a819-1f914385f94a
Commits

Reviewing files that changed from the base of the PR and between 66fe7c8 and a7f09ff.

Files selected for processing: 2

  • internal/catalogd/server/handlers_test.go
  • internal/catalogd/server/http_preconditions_check.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

t, err := parseTime(ims)
if err != nil {
httpError(w, err)
// RFC 9110 section 13.1.3: an invalid HTTP-date must be ignored.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This behavior now mirrors the checkIfUnmodifiedSince() behavior.

@tmshort tmshort left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/approve

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2026
@openshift-ci

openshift-ci Bot commented Nov 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tmshort

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 30, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit 4cab3cf into operator-framework:main Nov 30, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants