fix(cron,mcp): allow day/month names in cron, prune output files, secure OAuth writes#6670
Open
aaronlab wants to merge 1 commit into
Open
Conversation
…s, secure OAuth token writes - cron/jobs: broaden schedule validation regex from [\d\*\-,/] to [\d\w\*\-,/] so standard day/month names (MON-FRI, JAN, etc.) pass the pre-check and reach croniter for proper validation instead of being rejected as "Unrecognized schedule format" - cron/jobs: add _prune_job_output() to cap output files at 100 per job after each save — without pruning, a 5-minute job creates ~105K files per year with no cleanup mechanism - mcp_oauth: open token temp file with os.open(0o600) instead of Path.write_text + os.chmod, eliminating the TOCTOU window where OAuth tokens are world-readable between write and permission change Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MON-FRI,JAN, etc.)Details
Cron regex rejects valid day/month names (MEDIUM)
The pre-validation regex
r'^[\d\*\-,/]+$'only allows digits and special chars. Standard cron expressions like0 9 * * MON-FRIcontain alphabetic day names that fail this regex, falling through to the duration/timestamp parsers and raising"Unrecognized schedule format".croniteritself fully supports these names.Fix: change character class to
[\d\w\*\-,/]to allow letters. Actual validation is still done bycroniter().Cron output directory grows without bound (MEDIUM)
Every job execution writes
~/.hermes/cron/output/{job_id}/{timestamp}.md. No cleanup exists — a 5-minute job creates ~105K files/year.remove_job()doesn't clean the output directory either.Fix: add
_prune_job_output()that keeps the newest 100 files per job, called after each save.MCP OAuth token TOCTOU (MEDIUM)
_write_json()usesPath.write_text()which creates files with the process umask (typically 0o644, world-readable).os.chmod(tmp, 0o600)runs afterward — between write and chmod, OAuth tokens (access/refresh) are readable by other users.Fix: use
os.open(path, O_WRONLY|O_CREAT|O_TRUNC, 0o600)+os.fdopen()to create the file with restricted permissions from the start (matching the pattern used incron/jobs.pyfor job persistence).Test plan
parse_schedule("0 9 * * MON-FRI")succeedspytest tests/ -q🤖 Generated with Claude Code