Skip to content

SpotBugs: Getters expose internal mutable objects (EI_EXPOSE_REP, 95 instances) #19

@brunoborges

Description

@brunoborges

SpotBugs Finding: EI_EXPOSE_REP

Category: MALICIOUS_CODE
Priority: 2 (Normal) | Rank: 18
Bug Type: EI_EXPOSE_REP
CWE: CWE-374
Instances: 95

Description

Returning a reference to a mutable object value stored in one of the object's fields exposes the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to return a defensive copy.

Affected Classes

These findings are concentrated in DTO/event classes in the events and json packages:

Events Package (com.github.copilot.sdk.events)

  • AbortEventgetData()
  • AssistantIntentEventgetData()
  • AssistantMessageDeltaEventgetData()
  • AssistantMessageEventgetData(), getToolRequests()
  • AssistantReasoningDeltaEventgetData()
  • AssistantReasoningEventgetData()
  • AssistantTurnEndEventgetData()
  • AssistantTurnStartEventgetData()
  • AssistantUsageEventgetData(), getQuotaSnapshots()
  • HookEndEventgetData()
  • HookStartEventgetData()
  • SessionIdleEventgetData()
  • ToolExecutionEndEventgetData()
  • ToolExecutionStartEventgetData()

JSON Package (com.github.copilot.sdk.json)

  • CreateSessionRequestgetTools(), getMcpServers(), getCustomAgents(), getSkillDirectories(), getDisabledSkills()
  • ResumeSessionConfiggetTools(), getMcpServers(), getCustomAgents(), getSkillDirectories(), getDisabledSkills()
  • ResumeSessionRequestgetTools(), getMcpServers(), getCustomAgents(), getSkillDirectories(), getDisabledSkills()
  • SendMessageRequestgetAttachments()
  • SessionConfiggetTools(), getAvailableTools(), getExcludedTools(), getMcpServers(), getCustomAgents(), getSkillDirectories(), getDisabledSkills()
  • SessionEndHookOutputgetCleanupActions()
  • SessionLifecycleEventgetMetadata()
  • SessionStartHookOutputgetModifiedConfig()
  • ToolResultObjectgetBinaryResultsForLlm(), getToolTelemetry()
  • UserInputRequestgetChoices()

Decision Needed

For DTO/POJO classes used for JSON serialization, this is generally a low-risk finding since:

  1. These objects are deserialized from JSON-RPC and consumed locally
  2. Defensive copying would add overhead without meaningful security benefit
  3. Jackson deserialization relies on mutable setters

Options:

  • Suppress: Add @SuppressFBWarnings("EI_EXPOSE_REP") to DTO packages
  • Fix with records: Convert simple DTOs to Java records (immutable by default)
  • Defensive copy: Return Collections.unmodifiableList() / Map.copyOf() from getters

Generated from SpotBugs 4.9.8 static analysis

Metadata

Metadata

Labels

spotbugsSpotBugs static analysis finding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions