Skip to content

SpotBugs: Setters incorporate reference to external mutable objects (EI_EXPOSE_REP2, 95 instances) #20

@brunoborges

Description

@brunoborges

SpotBugs Finding: EI_EXPOSE_REP2

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

Description

Code stores a reference to an externally mutable object into 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, storing a copy of the object is the better approach.

Affected Classes

These are the setter counterparts to the EI_EXPOSE_REP getters — same DTO/event classes:

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

  • AbortEventsetData()
  • AssistantIntentEventsetData()
  • AssistantMessageDeltaEventsetData()
  • AssistantMessageEventsetData(), setToolRequests()
  • AssistantReasoningDeltaEventsetData()
  • AssistantReasoningEventsetData()
  • AssistantTurnEndEventsetData()
  • AssistantTurnStartEventsetData()
  • AssistantUsageEventsetData(), setQuotaSnapshots()
  • HookEndEventsetData()
  • HookStartEventsetData()
  • SessionIdleEventsetData()
  • ToolExecutionEndEventsetData()
  • ToolExecutionStartEventsetData()

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

  • CreateSessionRequestsetTools(), setMcpServers(), setCustomAgents(), setSkillDirectories(), setDisabledSkills()
  • ResumeSessionConfigsetTools(), setMcpServers(), setCustomAgents(), setSkillDirectories(), setDisabledSkills()
  • ResumeSessionRequestsetTools(), setMcpServers(), setCustomAgents(), setSkillDirectories(), setDisabledSkills()
  • SendMessageRequestsetAttachments()
  • SessionConfigsetTools(), setAvailableTools(), setExcludedTools(), setMcpServers(), setCustomAgents(), setSkillDirectories(), setDisabledSkills()
  • SessionEndHookOutputsetCleanupActions()
  • SessionLifecycleEventsetMetadata()
  • SessionStartHookOutputsetModifiedConfig()
  • ToolResultObjectsetBinaryResultsForLlm(), setToolTelemetry()
  • UserInputRequestsetChoices()

Decision Needed

Same considerations as EI_EXPOSE_REP — for JSON-deserialized DTOs, this is low-risk. See companion issue #19 for options.

Options:

  • Suppress: Add @SuppressFBWarnings("EI_EXPOSE_REP2") to DTO packages
  • Fix with records: Convert simple DTOs to Java records
  • Defensive copy: Store List.copyOf() / Map.copyOf() in setters

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