Skip to content

fix(secops): standardize ISO datetime parsing and normalize to UTC - #292

Open
dandye wants to merge 1 commit into
mainfrom
fix/issue-291-datetime-parsing
Open

fix(secops): standardize ISO datetime parsing and normalize to UTC#292
dandye wants to merge 1 commit into
mainfrom
fix/issue-291-datetime-parsing

Conversation

@dandye

@dandye dandye commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves issue #291 by replacing the fragile ad-hoc datetime.fromisoformat(ts.replace("Z", "+00:00")) pattern across SecOps tools with a robust, standardized parse_iso_datetime() utility.

Fixes #291

Changes Made

  1. server/secops/secops_mcp/utils.py:

    • Implemented parse_iso_datetime(time_input) supporting both str and datetime inputs.
    • Robustly handles trailing "Z" / "z" and explicit non-UTC offsets (e.g. "-05:00", "+02:00"), guaranteeing conversion to UTC with .astimezone(timezone.utc) so downstream SDK calls like .strftime("%Y-%m-%dT%H:%M:%S.%fZ") send the true UTC timestamp rather than shifted local wall-clock hours.
    • Defaults naive ISO timestamps without offset to UTC (tzinfo=timezone.utc).
    • Refactored parse_time_range() to use parse_iso_datetime().
  2. Tools Refactored:

    • server/secops/secops_mcp/tools/log_ingestion.py: ingest_raw_log
    • server/secops/secops_mcp/tools/curated_rules_management.py: search_curated_detections
    • server/secops/secops_mcp/tools/security_rules.py: create_retrohunt, search_rule_alerts
  3. Testing:

    • Added unit test coverage in tests/test_secops_tools_unit.py covering uppercase "Z", lowercase "z", non-UTC timezone offsets, naive timestamps, and malformed inputs.
    • Verified all unit tests pass cleanly.

@dandye
dandye requested a review from a team August 29, 2026 00:38
- Add parse_iso_datetime in secops_mcp.utils to handle trailing Z/z, non-UTC offsets, and naive timestamps with UTC normalization
- Refactor log_ingestion, curated_rules_management, and security_rules to use parse_iso_datetime instead of fragile .replace("Z", "+00:00")
- Add unit tests for timezone offsets, Z/z handling, and error cases

Fixes #291
@dandye
dandye force-pushed the fix/issue-291-datetime-parsing branch from 413a018 to 852d8c3 Compare August 30, 2026 02:42
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.

Fragile ISO datetime parsing antipattern .replace("Z", "+00:00") causes time shift and validation errors

1 participant