|
78 | 78 | import java.io.Serializable;
|
79 | 79 | import java.io.Writer;
|
80 | 80 | import java.nio.file.Files;
|
| 81 | +import java.nio.file.InvalidPathException; |
81 | 82 | import java.nio.file.Paths;
|
82 | 83 | import java.text.MessageFormat;
|
83 | 84 | import java.util.AbstractList;
|
@@ -1393,17 +1394,32 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
|
1393 | 1394 | }
|
1394 | 1395 | }
|
1395 | 1396 |
|
1396 |
| - private void abortIfSourceIsLocal() throws AbortException { |
| 1397 | + /* Package protected for test access */ |
| 1398 | + void abortIfSourceIsLocal() throws AbortException { |
1397 | 1399 | for (UserRemoteConfig userRemoteConfig: getUserRemoteConfigs()) {
|
1398 | 1400 | String remoteUrl = userRemoteConfig.getUrl();
|
1399 |
| - if (remoteUrl != null && (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://") || Files.exists(Paths.get(remoteUrl)))) { |
| 1401 | + if (!isRemoteUrlValid(remoteUrl)) { |
1400 | 1402 | throw new AbortException("Checkout of Git remote '" + remoteUrl + "' aborted because it references a local directory, " +
|
1401 | 1403 | "which may be insecure. You can allow local checkouts anyway by setting the system property '" +
|
1402 | 1404 | ALLOW_LOCAL_CHECKOUT_PROPERTY + "' to true.");
|
1403 | 1405 | }
|
1404 | 1406 | }
|
1405 | 1407 | }
|
1406 | 1408 |
|
| 1409 | + private static boolean isRemoteUrlValid(String remoteUrl) { |
| 1410 | + if (remoteUrl == null) { |
| 1411 | + return true; |
| 1412 | + } else if (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://")) { |
| 1413 | + return false; |
| 1414 | + } |
| 1415 | + try { |
| 1416 | + // Check for local remotes with no protocol like /path/to/repo.git/ |
| 1417 | + return !Files.exists(Paths.get(remoteUrl)); |
| 1418 | + } catch (InvalidPathException e) { |
| 1419 | + return true; |
| 1420 | + } |
| 1421 | + } |
| 1422 | + |
1407 | 1423 | private void printCommitMessageToLog(TaskListener listener, GitClient git, final Build revToBuild)
|
1408 | 1424 | throws IOException {
|
1409 | 1425 | try {
|
|
0 commit comments