Skip to content

fix: return error instead of panicking on invalid date input in parse_date()#7070

Closed
mango766 wants to merge 2 commits intodani-garcia:mainfrom
mango766:fix/parse-date-panic
Closed

fix: return error instead of panicking on invalid date input in parse_date()#7070
mango766 wants to merge 2 commits intodani-garcia:mainfrom
mango766:fix/parse-date-panic

Conversation

@mango766
Copy link
Copy Markdown
Contributor

@mango766 mango766 commented Apr 9, 2026

Fixes #7069

What's happening

parse_date() in src/util.rs calls .unwrap() on a DateTime::parse_from_rfc3339() result, where the input comes directly from HTTP query parameters or JSON body fields. Sending a malformed RFC3339 date string to any of the event endpoints panics the request handler thread.

Affected endpoints:

  • GET /api/organizations/{id}/events?start=...&end=...
  • GET /api/ciphers/{id}/events?start=...&end=...
  • GET /api/organizations/{id}/users/{id}/events?start=...&end=...
  • POST /events/collect

Fix

Changed parse_date() to return Result<NaiveDateTime, Error> and updated all callers in events.rs to propagate the error with ?, which results in a 400 Bad Request response instead of a panic.

The one call site with a hardcoded literal (sends.rs, epoch timestamp used for an anonymous push device) now uses .expect() with an explanatory message since that string is always valid.

Changes

  • src/util.rs: parse_date() now returns Result<NaiveDateTime, crate::Error> and uses pattern matching instead of .unwrap()
  • src/api/core/events.rs: all parse_date() calls use ? to propagate errors
  • src/api/core/sends.rs: hardcoded constant call-site uses .expect() with explanation

easonysliu and others added 2 commits April 9, 2026 14:30
`Cipher::to_json()` returns `Result<Value, Error>` but its match arm for
unknown `atype` values called `panic!("Wrong type")` instead of
propagating an error. This means if a cipher with an invalid/unknown type
ends up in the database (via direct DB edits, data migration issues, or
future type additions in the upstream Bitwarden protocol), the entire
server process would crash on the next sync request.

Replace the `panic!` with `err!()` so callers receive a proper `Err` and
can handle or log it gracefully without taking down the server.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The parse_date() utility function called .unwrap() directly on user-
controlled date strings from HTTP query parameters, allowing any
authenticated user to crash the server with a malformed RFC3339 date.

Change parse_date() to return Result<NaiveDateTime, Error> and update
all callers in events.rs to propagate the error with ?, returning a
400 Bad Request instead of panicking. The one call-site using a
hardcoded literal (sends.rs) uses .expect() with an explanatory message.

Affected endpoints:
- GET /organizations/{id}/events?start=...&end=...
- GET /ciphers/{id}/events?start=...&end=...
- GET /organizations/{id}/users/{id}/events?start=...&end=...
- POST /collect (event collection endpoint)
@BlackDex
Copy link
Copy Markdown
Collaborator

BlackDex commented Apr 9, 2026

I'm not sure this really really is needed, though it might be a bit nicer.
But your Claude Code is mixing PR's or isn't using the right branch. You now also have the fix of your other PR included here. That is probably not what you want.

@BlackDex
Copy link
Copy Markdown
Collaborator

Going to close this, it's not a real issue, and no response regarding the mixing of PR's

@BlackDex BlackDex closed this Apr 30, 2026
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.

parse_date() panics on invalid user-supplied date strings, crashing the server

2 participants