@@ -232,12 +232,13 @@ public void pathTraversalRejected() throws Exception {
232
232
233
233
WorkflowRun b = p .getLastBuild ();
234
234
assertEquals (1 , b .getNumber ());
235
- r .assertLogContains ("secrets/ master.key references a file that is not inside " + r .jenkins .getWorkspaceFor (p ).getRemote (), b );
235
+ r .assertLogContains ("master.key references a file that is not inside " + r .jenkins .getWorkspaceFor (p ).getRemote (), b );
236
236
}
237
237
238
238
@ Issue ("SECURITY-2491" )
239
239
@ Test
240
240
public void symlinksInReadTrustedCannotEscapeWorkspaceContext () throws Exception {
241
+ assumeFalse (Functions .isWindows ()); // On Windows, the symlink is treated as a regular file, so there is no vulnerability, but the behavior is different.
241
242
SCMBinder .USE_HEAVYWEIGHT_CHECKOUT = true ;
242
243
sampleRepo .init ();
243
244
sampleRepo .write ("Jenkinsfile" , "node { checkout scm; echo \" ${readTrusted 'secrets/master.key'}\" }" );
@@ -259,6 +260,7 @@ public void symlinksInReadTrustedCannotEscapeWorkspaceContext() throws Exception
259
260
@ Issue ("SECURITY-2491" )
260
261
@ Test
261
262
public void symlinksInUntrustedRevisionCannotEscapeWorkspace () throws Exception {
263
+ assumeFalse (Functions .isWindows ()); // On Windows, the symlink is treated as a regular file, so there is no vulnerability, but the behavior is different.
262
264
SCMBinder .USE_HEAVYWEIGHT_CHECKOUT = true ;
263
265
sampleRepo .init ();
264
266
sampleRepo .write ("Jenkinsfile" , "node { checkout scm; echo \" ${readTrusted 'secrets/master.key'}\" }" );
@@ -286,6 +288,7 @@ public void symlinksInUntrustedRevisionCannotEscapeWorkspace() throws Exception
286
288
@ Issue ("SECURITY-2491" )
287
289
@ Test
288
290
public void symlinksInNonMultibranchCannotEscapeWorkspaceContextViaReadTrusted () throws Exception {
291
+ assumeFalse (Functions .isWindows ()); // On Windows, the symlink is treated as a regular file, so there is no vulnerability, but the behavior is different.
289
292
SCMBinder .USE_HEAVYWEIGHT_CHECKOUT = true ;
290
293
sampleRepo .init ();
291
294
sampleRepo .write ("Jenkinsfile" , "echo \" ${readTrusted 'master.key'}\" " );
@@ -319,7 +322,10 @@ public void symlinksInNonMultibranchCannotEscapeWorkspaceContextViaReadTrusted()
319
322
FileUtils .copyDirectory (new File (sampleRepo .getRoot (), ".git" ), gitDirInSvnRepo );
320
323
String jenkinsRootDir = r .jenkins .getRootDir ().toString ();
321
324
// Add a Git post-checkout hook to the .git folder in the SVN repo.
322
- Files .write (gitDirInSvnRepo .toPath ().resolve ("hooks/post-checkout" ), ("#!/bin/sh\n touch '" + jenkinsRootDir + "/hook-executed'\n " ).getBytes (StandardCharsets .UTF_8 ));
325
+ Path postCheckoutHook = gitDirInSvnRepo .toPath ().resolve ("hooks/post-checkout" );
326
+ // Always create hooks directory for compatibility with https://github.com/jenkinsci/git-plugin/pull/1207.
327
+ Files .createDirectories (postCheckoutHook .getParent ());
328
+ Files .write (postCheckoutHook , ("#!/bin/sh\n touch '" + jenkinsRootDir + "/hook-executed'\n " ).getBytes (StandardCharsets .UTF_8 ));
323
329
sampleRepoSvn .svnkit ("add" , sampleRepoSvn .wc () + "/Jenkinsfile" );
324
330
sampleRepoSvn .svnkit ("add" , sampleRepoSvn .wc () + "/.git" );
325
331
sampleRepoSvn .svnkit ("propset" , "svn:executable" , "ON" , sampleRepoSvn .wc () + "/.git/hooks/post-checkout" );
@@ -354,7 +360,10 @@ public void symlinksInNonMultibranchCannotEscapeWorkspaceContextViaReadTrusted()
354
360
FileUtils .copyDirectory (new File (sampleRepo .getRoot (), ".git" ), gitDirInSvnRepo );
355
361
String jenkinsRootDir = r .jenkins .getRootDir ().toString ();
356
362
// Add a Git post-checkout hook to the .git folder in the SVN repo.
357
- Files .write (gitDirInSvnRepo .toPath ().resolve ("hooks/post-checkout" ), ("#!/bin/sh\n touch '" + jenkinsRootDir + "/hook-executed'\n " ).getBytes (StandardCharsets .UTF_8 ));
363
+ Path postCheckoutHook = gitDirInSvnRepo .toPath ().resolve ("hooks/post-checkout" );
364
+ // Always create hooks directory for compatibility with https://github.com/jenkinsci/git-plugin/pull/1207.
365
+ Files .createDirectories (postCheckoutHook .getParent ());
366
+ Files .write (postCheckoutHook , ("#!/bin/sh\n touch '" + jenkinsRootDir + "/hook-executed'\n " ).getBytes (StandardCharsets .UTF_8 ));
358
367
sampleRepoSvn .svnkit ("add" , sampleRepoSvn .wc () + "/Jenkinsfile" );
359
368
sampleRepoSvn .svnkit ("add" , sampleRepoSvn .wc () + "/.git" );
360
369
sampleRepoSvn .svnkit ("propset" , "svn:executable" , "ON" , sampleRepoSvn .wc () + "/.git/hooks/post-checkout" );
0 commit comments