Skip to content

fix: calendar_id validation rejects valid IDs with @ and . chars - #194

Merged
lishuceo merged 3 commits into
mainfrom
fix/calendar-id-validation
Apr 8, 2026
Merged

fix: calendar_id validation rejects valid IDs with @ and . chars#194
lishuceo merged 3 commits into
mainfrom
fix/calendar-id-validation

Conversation

@lishuceo

Copy link
Copy Markdown
Owner

Summary

  • validateToken() regex ^[A-Za-z0-9_-]+$ was too strict, rejecting valid calendar IDs containing @, ., =, +, : characters
  • Added CALENDAR_ID_RE regex specifically for calendar_id that allows these chars while still blocking path traversal (/, \, .., spaces)
  • Fixes repeated feishu_calendar tool error ("无效的 calendar_id") when querying shared/subscribed/Google calendars

Evidence from logs

{"err":"无效的 calendar_id: 仅允许字母、数字、下划线、横线","action":"list_events","msg":"feishu_calendar tool error"}

Multiple occurrences across March 23-26.

Test plan

  • Added test cases for calendar_id with @, ., =, +, : chars
  • Verified path traversal (../, /) still rejected for calendar_id
  • Verified strict validation still applies to non-calendar tokens (doc_token, folder_token)
  • CI tests pass

🤖 Generated with Claude Code

lishuceo and others added 2 commits March 28, 2026 13:22
The validateToken regex was too strict (only [A-Za-z0-9_-]),
rejecting valid Feishu calendar IDs that contain @ and .
characters (e.g., Google Calendar IDs like user@gmail.com,
shared/subscribed calendars).

This caused repeated "无效的 calendar_id" errors when the
Claude agent tried to query specific calendars, while queries
to the primary calendar (no calendar_id) worked fine.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover new calendar_id-specific regex (allows @.=+:),
ensure path traversal still blocked, and verify strict
mode still applies to non-calendar tokens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude

claude Bot commented Mar 28, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Apr 8, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 2s —— View job


PR Review: #194 — calendar_id validation

Approved — Clean, well-scoped fix with good test coverage.

What changed:

  • New CALENDAR_ID_RE regex (/^[A-Za-z0-9_@.=+:-]+$/) for calendar_id fields, allowing @, ., =, +, : characters that appear in Google/shared calendar IDs
  • Strict TOKEN_RE still enforced for all other token types (doc_token, folder_token, etc.)
  • Caller in calendar.ts:195 already passes 'calendar_id' as the name, so the branching works correctly

Security check:

  • Path traversal chars / and \ are still blocked (not in character class) ✅
  • Spaces blocked ✅
  • Empty strings blocked (regex requires +) ✅
  • event_id on calendar.ts:196 still uses strict validation ✅

Minor note (not blocking): The doc comment on line 6 says "仍禁止 .." but the regex does allow consecutive dots (e.g., abc..def). This is fine since .. is only a traversal risk when paired with / or \ (both blocked), but the comment is slightly imprecise.

Tests: 3 new test cases covering valid calendar IDs, path traversal rejection, and strict validation for non-calendar tokens — good coverage.

@lishuceo
lishuceo merged commit db01286 into main Apr 8, 2026
4 checks passed
@lishuceo
lishuceo deleted the fix/calendar-id-validation branch April 8, 2026 04:21
lishuceo added a commit that referenced this pull request Apr 8, 2026
fix: calendar_id validation rejects valid IDs with @ and . chars
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.

1 participant