[SECURITY-1986]

This commit is contained in:
Jeff Thompson authored and Jenkins CERT CI committed 2021-01-11 16:52:18 +00:00
1 parent 89ec0c40b6
commit ea302e1f43
2 files changed
+229

No files matched your search

@@ -33,13 +33,16 @@ import hudson.XmlFile;
import hudson.model.Action;
import hudson.model.Descriptor.FormException;
import hudson.model.Failure;
import hudson.model.FileParameterValue;
import hudson.util.*;
import jenkins.model.Jenkins;
import hudson.model.Label;
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import jenkins.util.SystemProperties;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
@@ -56,6 +59,8 @@ import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.Nullable;
@@ -66,6 +71,12 @@ import edu.umd.cs.findbugs.annotations.Nullable;
* @since 1.372
*/
public class LabelAtom extends Label implements Saveable {
private static final Pattern PROHIBITED_DOUBLE_DOT = Pattern.compile(".*\\.\\.[\\\\/].*");
private static /* Script Console modifiable */ boolean ALLOW_FOLDER_TRAVERSAL =
SystemProperties.getBoolean(LabelAtom.class.getName() + ".allowFolderTraversal");
private DescribableList<LabelAtomProperty,LabelAtomPropertyDescriptor> properties =
new DescribableList<>(this);
@@ -167,6 +178,9 @@ public class LabelAtom extends Label implements Saveable {
}
public void save() throws IOException {
if (isInvalidName()) {
throw new IOException("Invalid label");
}
if(BulkChange.contains(this)) return;
try {
getConfigFile().write(this);
@@ -206,6 +220,10 @@ public class LabelAtom extends Label implements Saveable {
app.checkPermission(Jenkins.ADMINISTER);
if (isInvalidName()) {
throw new FormException("Invalid label", null);
}
properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());
this.description = req.getSubmittedForm().getString("description");
@@ -216,6 +234,10 @@ public class LabelAtom extends Label implements Saveable {
FormApply.success(".").generateResponse(req, rsp, null);
}
private boolean isInvalidName() {
return !ALLOW_FOLDER_TRAVERSAL && PROHIBITED_DOUBLE_DOT.matcher(name).matches();
}
/**
* Accepts the new description.
*/