Skip to content

W-22550530: Prevent SOQL injection in DevOps Work Item and Pipeline queries#460

Open
jag-j wants to merge 4 commits into
mainfrom
jj/W-22550530
Open

W-22550530: Prevent SOQL injection in DevOps Work Item and Pipeline queries#460
jag-j wants to merge 4 commits into
mainfrom
jj/W-22550530

Conversation

@jag-j

@jag-j jag-j commented Jun 1, 2026

Copy link
Copy Markdown

Fixes @W-22550530@

This commit addresses SOQL injection vulnerabilities in the MCP DevOps provider by implementing strict input validation for all user-provided values in SOQL queries.

Changes:

  • Created soqlUtils.ts with validation functions for Salesforce IDs and work item names
  • Added isValidSalesforceId() to validate 15/18 character ID format
  • Added validateWorkItemName() to validate WI-XXXXXXX format
  • Added escapeSoqlString() for proper quote escaping
  • Applied validation to all SOQL queries in:
    • getWorkItems.ts (projectId, workItemName)
    • getWorkItemsMP.ts (workItemName, workItemId)
    • getPipelineMP.ts (projectId)
    • getPipelineStagesMP.ts (pipelineId)
  • Added comprehensive unit tests for all validation functions

Security improvements:

  • Prevents injection via malformed IDs like "001' OR 1=1--"
  • Validates work item name format before query construction
  • Rejects all non-alphanumeric characters in IDs
  • Blocks common SQL injection patterns

What does this PR do?

What issues does this PR fix or reference?

Fixes W-22550530

This commit addresses SOQL injection vulnerabilities in the MCP DevOps provider
by implementing strict input validation for all user-provided values in SOQL queries.

Changes:
- Created soqlUtils.ts with validation functions for Salesforce IDs and work item names
- Added isValidSalesforceId() to validate 15/18 character ID format
- Added validateWorkItemName() to validate WI-XXXXXXX format
- Added escapeSoqlString() for proper quote escaping
- Applied validation to all SOQL queries in:
  * getWorkItems.ts (projectId, workItemName)
  * getWorkItemsMP.ts (workItemName, workItemId)
  * getPipelineMP.ts (projectId)
  * getPipelineStagesMP.ts (pipelineId)
- Added comprehensive unit tests for all validation functions

Security improvements:
- Prevents injection via malformed IDs like "001' OR 1=1--"
- Validates work item name format before query construction
- Rejects all non-alphanumeric characters in IDs
- Blocks common SQL injection patterns

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jag-j jag-j requested a review from a team as a code owner June 1, 2026 20:17
@jag-j jag-j changed the title @W-22550530@ Prevent SOQL injection in DevOps Work Item and Pipeline queries W-22550530: Prevent SOQL injection in DevOps Work Item and Pipeline queries Jun 1, 2026
jag-j and others added 3 commits June 1, 2026 13:31
The previous validation was too strict and only accepted WI-XXXXXXX format.
This caused test failures because managed package work items can have
alphanumeric names like "Test Work Item".

Changes:
- Added containsSqlInjectionPatterns() to detect actual injection attempts
- Updated validateWorkItemName() to accept both:
  * Standard format: WI-XXXXXXX
  * Managed package format: alphanumeric with spaces, hyphens, underscores
- Still blocks all SQL injection patterns (OR, UNION, --, semicolons, etc.)
- Added tests for new validation scenarios
- Maintains strong security while supporting existing test mocks

This fixes test failures while preserving injection protection.
- Remove single quote from injection patterns array (was causing array index issues)
- Simplify containsSqlInjectionPatterns logic
- Allow single quotes in safe name pattern since they are escaped
- Simplify error message format for validateWorkItemName

This fixes unit test failures where valid names like "O'Brien Task"
were incorrectly rejected.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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