Skip to content

Commit c5cd71f

Browse files
committed
Disallow \n in header command
1 parent b9c7634 commit c5cd71f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,13 @@ class CoderCLIManager @JvmOverloads constructor(
201201
* Escape a command argument by wrapping it in double quotes and escaping
202202
* any slashes and double quotes in the argument. For example, echo "te\st"
203203
* becomes "echo \"te\\st\"".
204+
*
205+
* Throws if the argument is invalid.
204206
*/
205207
private fun escape(s: String): String {
208+
if (s.contains("\n")) {
209+
throw Exception("argument cannot contain newlines")
210+
}
206211
return "\"" + s.replace(escapeRegex, """\\$1""") + "\""
207212
}
208213

src/test/groovy/CoderCLIManagerTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ class CoderCLIManagerTest extends Specification {
453453
]
454454
}
455455

456+
def "fails if header command is malformed"() {
457+
given:
458+
def ccm = new CoderCLIManager(new URL("https://test.coder.invalid"), tmpdir)
459+
460+
when:
461+
ccm.configSsh(["foo", "bar"].collect { DataGen.workspace(it) }, headerCommand)
462+
463+
then:
464+
thrown(Exception)
465+
466+
where:
467+
headerCommand << [
468+
"new\nline",
469+
]
470+
}
471+
456472
@IgnoreIf({ os.windows })
457473
def "parses version"() {
458474
given:

0 commit comments

Comments
 (0)