Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from amuniz/JENKINS-35210
[JENKINS-35210] Fix for SECURITY-170
- Loading branch information
Showing
3 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/org/jenkinsci/plugins/p4/review/SafeParametersAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.jenkinsci.plugins.p4.review; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.EnvironmentContributor; | ||
import hudson.model.ParameterValue; | ||
import hudson.model.ParametersAction; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
|
||
@Restricted(NoExternalUse.class) | ||
public class SafeParametersAction extends ParametersAction { | ||
|
||
private List<ParameterValue> internalParameters; | ||
|
||
public SafeParametersAction(@NonNull List<ParameterValue> params, @NonNull List<ParameterValue> internalParameters) { | ||
// Apply security to regular parameters | ||
super(params); | ||
this.internalParameters = internalParameters; | ||
} | ||
|
||
@Override | ||
public List<ParameterValue> getParameters() { | ||
List<ParameterValue> params = new ArrayList<ParameterValue>(); | ||
List<ParameterValue> p = super.getParameters(); | ||
params.addAll(p); | ||
params.addAll(internalParameters); | ||
return Collections.unmodifiableList(params); | ||
} | ||
|
||
@Override | ||
public ParameterValue getParameter(String name) { | ||
ParameterValue param = super.getParameter(name); | ||
if (param != null) { | ||
return param; | ||
} | ||
for (ParameterValue p : internalParameters) { | ||
if (p == null) continue; | ||
if (p.getName().equals(name)) | ||
return p; | ||
} | ||
return null; | ||
} | ||
|
||
List<ParameterValue> getInternalParameters() { | ||
return Collections.unmodifiableList(internalParameters); | ||
} | ||
|
||
@Extension | ||
public static final class SafeParametersActionEnvironmentContributor extends EnvironmentContributor { | ||
|
||
@Override | ||
public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) | ||
throws IOException, InterruptedException { | ||
SafeParametersAction action = r.getAction(SafeParametersAction.class); | ||
if (action != null) { | ||
for (ParameterValue pv : action.getInternalParameters()) { | ||
envs.put(pv.getName(), String.valueOf(pv.getValue())); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters