Sanitize tool_id in toolops responses (XSS/robustness)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in toolops_router.py at generate_testcases_for_tool and enrich_a_tool, especially the output assignment around lines 165-168 and the logger call. Trace existing SecurityValidator.sanitize_display_text() usage, add regression tests for sanitized tool_id responses, and run those tests plus lint on the changed files.
Written by the indexing model from the issue text.
Description
Description
Two security/robustness fixes were identified in the pr-5417-decomposition scope sweep. After triage, only Fix 1 remains actionable.
Fix 1 (actionable): XSS prevention in toolops_router.py
Apply SecurityValidator.sanitize_display_text() to tool_id at output sites in generate_testcases_for_tool and enrich_a_tool:
toolops_router.py:168:result["tool_id"] = tool_id— reflects raw value into responsetoolops_router.py:165: string concatenation in logger call
Risk level: Low in practice — tool_id is already constrained by QueryIdentifierDotted300 (SecurityValidator.IDENTIFIER_PATTERN: ^[a-zA-Z0-9_\-\.]+$), which prevents HTML/JS injection at the input boundary. The output sanitization is defence-in-depth.
Fix 2 (superseded): int(hours) coercion in observability.py
Both get_stats and get_query_performance already declare hours: int = Query(24, ge=1, le=168). FastAPI enforces the type at the HTTP boundary — a non-integer value results in a 422 before the handler runs. Adding int(hours) inside the handler would be a no-op. This fix is not needed.
Acceptance Criteria
-
tool_idoutputs in/toolopsendpoints are sanitized viaSecurityValidator.sanitize_display_text() - Regression tests added for the fix
- Lint passes on changed files
Labels
bug, security
Related
Part of pr-5417-decomposition security family completion.
- Dominant language
- Python
- Stars
- 4.5k
- Forks
- 877
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 66
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from IBM/mcp-context-forge
-
bug triage ui-rewrite
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
IBM/mcp-context-forge#6854 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
IBM/mcp-context-forge#6829 ·
-
bug ui-rewrite
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
IBM/mcp-context-forge#6796 ·
-
chore triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
IBM/mcp-context-forge#6714 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
IBM/mcp-context-forge#6685 · 1 comment ·
All issues in IBM/mcp-context-forge
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100