Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 9250051

Browse files
authored
Merge pull request #270 from mathworks/dev_main
Fixed security issue
2 parents c513689 + 96af1c5 commit 9250051

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

src/main/java/com/mathworks/ci/MatlabBuilder.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* [email protected] Date : 28/03/2018 (Initial draft)
99
*/
1010

11+
import hudson.model.Item;
12+
import hudson.security.Permission;
1113
import java.io.File;
1214
import java.io.IOException;
1315
import java.io.InputStream;
@@ -19,6 +21,7 @@
1921
import javax.annotation.Nonnull;
2022
import org.apache.commons.io.FilenameUtils;
2123
import org.apache.commons.lang.ArrayUtils;
24+
import org.kohsuke.stapler.AncestorInPath;
2225
import org.kohsuke.stapler.DataBoundConstructor;
2326
import org.kohsuke.stapler.DataBoundSetter;
2427
import org.kohsuke.stapler.QueryParameter;
@@ -43,6 +46,7 @@
4346
import jenkins.model.Jenkins;
4447
import jenkins.tasks.SimpleBuildStep;
4548
import net.sf.json.JSONObject;
49+
import org.kohsuke.stapler.verb.POST;
4650

4751
public class MatlabBuilder extends Builder implements SimpleBuildStep {
4852

@@ -148,8 +152,12 @@ public DescriptorExtensionList<TestRunTypeList, Descriptor<TestRunTypeList>> get
148152
* descriptor class.
149153
*/
150154

151-
152-
public FormValidation doCheckMatlabRoot(@QueryParameter String matlabRoot) {
155+
@POST
156+
public FormValidation doCheckMatlabRoot(@QueryParameter String matlabRoot, @AncestorInPath Item item) {
157+
if (item == null) {
158+
return FormValidation.ok();
159+
}
160+
item.checkPermission(Item.CONFIGURE);
153161
setMatlabRoot(matlabRoot);
154162
List<Function<String, FormValidation>> listOfCheckMethods =
155163
new ArrayList<Function<String, FormValidation>>();

src/main/java/com/mathworks/ci/MatlabReleaseInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import javax.xml.parsers.DocumentBuilder;
2020
import javax.xml.parsers.DocumentBuilderFactory;
21+
import javax.xml.parsers.ParserConfigurationException;
2122
import org.apache.commons.collections.MapUtils;
2223
import org.w3c.dom.Document;
2324
import org.w3c.dom.Element;
2425
import org.w3c.dom.Node;
2526
import org.w3c.dom.NodeList;
2627
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2728
import hudson.FilePath;
29+
import org.xml.sax.SAXException;
2830

2931
public class MatlabReleaseInfo {
3032
private FilePath matlabRoot;
@@ -82,6 +84,15 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
8284
FilePath versionFile = new FilePath(this.matlabRoot, VERSION_INFO_FILE);
8385
if(versionFile.exists()) {
8486
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
87+
String FEATURE = null;
88+
try{
89+
FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
90+
dbFactory.setFeature(FEATURE, true);
91+
dbFactory.setXIncludeAware(false);
92+
93+
} catch (ParserConfigurationException e) {
94+
throw new MatlabVersionNotFoundException("Error parsing verify if XML is valid", e);
95+
}
8596
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
8697
Document doc = dBuilder.parse(versionFile.read());
8798

src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*
99
*/
1010

11+
import hudson.model.Item;
12+
import hudson.security.Permission;
1113
import java.io.File;
1214
import java.io.IOException;
1315
import java.util.ArrayList;
@@ -17,6 +19,8 @@
1719

1820
import hudson.matrix.MatrixProject;
1921
import hudson.model.Computer;
22+
import jenkins.model.Jenkins;
23+
import org.kohsuke.stapler.AncestorInPath;
2024
import org.kohsuke.stapler.DataBoundConstructor;
2125
import org.kohsuke.stapler.DataBoundSetter;
2226
import org.kohsuke.stapler.QueryParameter;
@@ -31,6 +35,7 @@
3135
import hudson.tasks.BuildWrapperDescriptor;
3236
import hudson.util.FormValidation;
3337
import jenkins.tasks.SimpleBuildWrapper;
38+
import org.kohsuke.stapler.verb.POST;
3439

3540
public class UseMatlabVersionBuildWrapper extends SimpleBuildWrapper {
3641

@@ -137,8 +142,12 @@ public String getMatlabAxisWarning() {
137142
* these methods are used to perform basic validation on UI elements associated with this
138143
* descriptor class.
139144
*/
140-
141-
public FormValidation doCheckMatlabRootFolder(@QueryParameter String matlabRootFolder) {
145+
@POST
146+
public FormValidation doCheckMatlabRootFolder(@QueryParameter String matlabRootFolder, @AncestorInPath Item item) {
147+
if (item == null) {
148+
return FormValidation.ok();
149+
}
150+
item.checkPermission(Item.CONFIGURE);
142151
List<Function<String, FormValidation>> listOfCheckMethods =
143152
new ArrayList<Function<String, FormValidation>>();
144153
listOfCheckMethods.add(chkMatlabEmpty);

src/main/resources/com/mathworks/ci/MatlabBuilder/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<font color="red">Using this build step is not recommended and will be removed in a feature release. Use “Run MATLAB Tests” or “Run MATLAB Command” instead.</font>
55
<f:section>
66
<f:entry title="MATLAB root " field="matlabRoot">
7-
<f:textbox disabled="disabled"/>
7+
<f:textbox disabled="disabled" checkMethod="post" />
88
</f:entry>
99
</f:section>
1010
<f:dropdownDescriptorSelector title="Test mode" field="testRunTypeList" descriptors="${descriptor.testRunTypeDescriptor}" selected="${instance.testRunTypeList}" disabled="true"/>

src/main/resources/com/mathworks/ci/UseMatlabVersionBuildWrapper/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<j:choose>
1919
<j:when test="${loop.last}">
2020
<f:entry title="MATLAB root: " field="matlabRootFolder">
21-
<f:textbox/>
21+
<f:textbox checkMethod="post"/>
2222
</f:entry>
2323
</j:when>
2424
</j:choose>

0 commit comments

Comments
 (0)