Skip to content

Commit c564958

Browse files
authored
fixes SECURITY-2521 (#221)
1 parent bd85216 commit c564958

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

src/main/java/com/datapipe/jenkins/vault/credentials/VaultTokenFileCredential.java

+3-20
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import edu.umd.cs.findbugs.annotations.CheckForNull;
77
import edu.umd.cs.findbugs.annotations.NonNull;
88
import hudson.Extension;
9-
import hudson.FilePath;
10-
import hudson.remoting.VirtualChannel;
119
import java.io.File;
1210
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
1312
import org.apache.commons.io.FileUtils;
14-
import org.jenkinsci.remoting.RoleChecker;
1513
import org.kohsuke.stapler.DataBoundConstructor;
1614

1715
public class VaultTokenFileCredential extends AbstractVaultTokenCredential {
@@ -28,24 +26,9 @@ public VaultTokenFileCredential(@CheckForNull CredentialsScope scope, @CheckForN
2826

2927
@Override
3028
public String getToken(Vault vault) {
31-
FilePath file = new FilePath(new File(filepath));
3229
try {
33-
return file.act(new FilePath.FileCallable<String>() {
34-
@Override
35-
public void checkRoles(RoleChecker roleChecker) throws SecurityException {
36-
//not needed
37-
}
38-
39-
@Override
40-
public String invoke(File f, VirtualChannel channel) {
41-
try {
42-
return FileUtils.readFileToString(f);
43-
} catch (IOException e) {
44-
throw new RuntimeException(e);
45-
}
46-
}
47-
}).trim();
48-
} catch (IOException | InterruptedException e) {
30+
return FileUtils.readFileToString(new File(filepath), StandardCharsets.UTF_8);
31+
} catch (IOException e) {
4932
throw new VaultPluginException("Failed to read token from file", e);
5033
}
5134
}

0 commit comments

Comments
 (0)