Skip to main content
Menu
Advisories

Schema paths can inject source through generated file comments

GHSA-R593-M628-69HHPublished Updated GitHub

Description

Wire places a schema file path into generated Kotlin and Swift file comments without removing carriage returns. Releases before 3.3.0 also do this for generated Java file comments. A crafted path can end the line comment and insert source text into generated files. This affects schemas that Wire selects for generation through sourcePath. A dependency used only for protoPath type resolution does not, by itself, generate affected files.

Impact and prerequisites

An attacker must control a schema path that a consumer selects for generation. This can include paths inside a directory, ZIP, or JAR source input. A downstream compiler can compile injected source into the consumer artifact. Compilation alone does not execute that source. Execution requires the consumer to load or call the injected code, depending on its contents.

Wire already treats third-party schemas as source code in its security policy. The additional issue here is that a filename can leave a generated comment and become source text. The advisory does not claim that generation itself runs attacker code.

Affected versions and components

The raw source-comment sink is confirmed by source inspection of release tags. In com.squareup.wire:wire-compiler, a Java sink is in the compiler itself from 1.0.0 through 3.2.2. A Kotlin or Swift sink is in the compiler itself from 3.0.0-alpha01 through 4.9.11. From 5.0.0-alpha01, wire-compiler depends on the generator artifacts below, so it stays affected through 7.1.1. In com.squareup.wire:wire-kotlin-generator, the Kotlin sink is present from 4.7.0 through 7.1.1. In com.squareup.wire:wire-swift-generator, the Swift sink is present from 5.0.0-alpha01 through 7.1.1. Prereleases inside these ranges are affected. Releases 3.1.x and 3.2.x have no repository tags. Their published sources jars contain the sink. Source inspection confirms the sink, rather than independent runtime reproduction on each release. Java output from releases before 3.3.0 is affected, because older JavaPoet and JavaWriter versions do not split comment text on carriage returns. From 3.3.0, JavaPoet splits all line terminators, so Java output is not known to be affected by the reported carriage-return vector.

Reproduction

Use a benign schema path containing a carriage return followed by INJECTED_MARKER.proto. Generate Kotlin or Swift output with an affected version and inspect the leading source comment. The affected code emits the carriage return literally. The target compiler treats carriage return as a line terminator, so text after it is outside the comment.

Remediation

Upgrade the Wire compiler, including wire-kotlin-generator and wire-swift-generator, to 7.1.2 or later. Gradle plugin users upgrade the com.squareup.wire plugin to 7.1.2 or later. Then regenerate affected sources with the fixed compiler, and rebuild and redistribute affected artifacts. A runtime-only upgrade does not remove source already injected into generated files.

Wire 7.1.2 replaces compiler-recognized line terminators in the schema path with spaces when it emits the source comment. The schema location and the input filesystem path stay unchanged. The fix covers Kotlin and Swift output, and applies the same normalization to Java output. The release adds regression coverage for carriage return, line feed, CRLF, vertical tab, form feed, NEL, and Unicode line and paragraph separators.

References

Affected versions

References

GitHub · square/wire