Skip to content

Commit 5e685b0

Browse files
authored
Removing all slashes from branch name in the custom workspaces for safer traversal (#65)
1 parent 284427a commit 5e685b0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

core/src/main/kotlin/com/code42/jenkins/pipelinekt/core/Pipeline.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ data class Pipeline(
8181
writer.writeln("def customWorkspacePath = null")
8282
writer.writeln("if (env.BRANCH_NAME) {")
8383
val innerWriter = writer.inner()
84-
innerWriter.writeln("def safeBranch = env.BRANCH_NAME.replaceAll(/[^A-Za-z0-9._-]/, '_')")
84+
innerWriter.writeln("// Replace slashes and other special characters with underscores for safe filesystem paths")
85+
innerWriter.writeln("def safeBranch = env.BRANCH_NAME.replaceAll('/', '_').replaceAll(/[^A-Za-z0-9._-]/, '_')")
8586
innerWriter.writeln("customWorkspacePath = \"./workspace//\${env.JOB_NAME}-\${safeBranch}\"")
8687
writer.writeln("}")
8788
writer.writeln("")

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.21.11
1+
0.21.12

0 commit comments

Comments
 (0)