Skip to content

Conversation

@github-actions
Copy link
Contributor

Security Fix: Allocation Size Overflow in Domain List Merging

Alert Number: #6
Severity: High (security_severity_level: high)
Rule: go/allocation-size-overflow
File: pkg/parser/mcp.go:35
CWE: CWE-190 (Integer Overflow or Wraparound)

Vulnerability Description

The EnsureLocalhostDomains function was vulnerable to allocation size overflow when computing the capacity for the merged domain list. The vulnerable pattern was:

result := make([]string, 0, len(domains)+4)

When computing the size of an allocation based on potentially large values, the result may overflow (for signed integer types) or wraparound (for unsigned types). An overflow causes the result to become negative, while a wraparound results in a small positive number.

If the domains slice from user configuration was extremely large (close to max int), adding 4 to it could:

  1. Overflow to negative: Cause a runtime panic when passed to make()
  2. Wraparound: Allocate an unexpectedly small buffer, potentially causing issues

While the function only adds 4 localhost domains, the domains parameter comes from user-provided workflow configuration and could theoretically be very large.

Fix Applied

The fix eliminates the overflow risk by removing pre-allocation entirely and relying on Go's append function to handle capacity growth automatically:

// CWE-190: Allocation Size Overflow Prevention
// Instead of pre-calculating capacity (len(domains)+4), which could overflow
// if domains is extremely large, we let Go's append handle capacity growth
// automatically. This is safe and efficient for domain arrays which are
// typically small in practice.
var result []string

// Always add localhost domains first (with and without port specifications)
if !hasLocalhost {
    result = append(result, "localhost")
}
if !hasLocalhostPorts {
    result = append(result, "localhost:*")
}
if !hasLoopback {
    result = append(result, "127.0.0.1")
}
if !hasLoopbackPorts {
    result = append(result, "127.0.0.1:*")
}

// Add the rest of the domains
result = append(result, domains...)

Approach

Rather than implementing complex overflow guards, the fix takes a simpler approach:

  1. No pre-allocation: Use var result []string instead of make([]string, 0, capacity)
  2. Automatic capacity growth: Let Go's append function handle capacity management efficiently
  3. Simpler code: Eliminates all overflow calculation logic, making the code easier to understand and maintain

This approach is appropriate because domain arrays are not expected to be large, and Go's append function is optimized for incremental growth.

Security Best Practices Applied

Simplicity over complexity: Removed unnecessary pre-allocation logic that introduced overflow risk
Language built-ins: Relied on Go's append function which handles capacity safely
Maintainability: Cleaner code that's easier to review and maintain
Defense in Depth: Eliminates the vulnerability at its source

Testing Considerations

To validate this fix, please test:

  • Normal workflow compilation with MCP server configurations
  • Workflows with custom Playwright allowed_domains configurations
  • Workflows with default localhost domains
  • Workflows with empty domain lists
  • Existing workflows continue to compile successfully
  • No runtime panics during domain list processing
  • All unit tests pass

Impact Assessment

Risk Level: Low

  • This is a preventive fix for a potential denial-of-service vulnerability
  • No known exploits in production
  • Realistic domain arrays are small (typically < 100 domains)
  • Fix maintains backward compatibility

Functionality: No Breaking Changes

  • Normal workflows (with reasonable domain configurations) are unaffected
  • Code compiles successfully with no errors
  • All existing functionality continues to work as expected
  • Simpler implementation reduces maintenance burden

Related Security Alerts

This PR fixes CodeQL alert #6. There are 8 other open code scanning alerts in the repository:

References


🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

AI generated by Security Fix PR

AI generated by Security Fix PR

This fix addresses CodeQL alert #6 (CWE-190: Integer Overflow) in the
EnsureLocalhostDomains function by eliminating pre-allocation overflow risk.

The vulnerable pattern was:
  result := make([]string, 0, len(domains)+4)

If the domains slice was extremely large (close to max int), adding 4 could
cause integer overflow (negative result) leading to a runtime panic.

The fix removes pre-allocation entirely and relies on Go's append function
to handle capacity growth automatically, which is safe and efficient for
domain arrays that are typically small in practice.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@pelikhan pelikhan marked this pull request as ready for review October 11, 2025 06:20
@github-actions
Copy link
Contributor Author

Agentic Changeset Generator triggered by this pull request

…rging

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@pelikhan pelikhan merged commit 8bb16cc into main Oct 11, 2025
4 checks passed
@pelikhan pelikhan deleted the security-fix-alert-6-allocation-overflow-mcp-10f73bdaeb4deb39 branch October 11, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants