11package htmlpublisher ;
22
3- import java .io .File ;
4- import java .io .IOException ;
5- import java .nio .charset .StandardCharsets ;
6- import java .util .Objects ;
7- import java .util .regex .Matcher ;
8- import java .util .regex .Pattern ;
9-
3+ import com .infradna .tool .bridge_method_injector .WithBridgeMethods ;
104import edu .umd .cs .findbugs .annotations .NonNull ;
11- import javax .servlet .ServletException ;
12-
5+ import hudson .Extension ;
6+ import hudson .FilePath ;
7+ import hudson .Util ;
8+ import hudson .model .AbstractDescribableImpl ;
9+ import hudson .model .Action ;
10+ import hudson .model .AbstractItem ;
11+ import hudson .model .Run ;
12+ import hudson .model .DirectoryBrowserSupport ;
13+ import hudson .model .Job ;
14+ import hudson .model .ProminentProjectAction ;
15+ import hudson .model .AbstractBuild ;
16+ import hudson .model .InvisibleAction ;
17+ import hudson .model .Descriptor ;
18+ import hudson .util .HttpResponses ;
19+ import jenkins .model .RunAction2 ;
1320import org .apache .commons .codec .binary .Hex ;
1421import org .apache .commons .lang .StringUtils ;
1522import org .kohsuke .accmod .Restricted ;
2027import org .kohsuke .stapler .StaplerResponse ;
2128import org .owasp .encoder .Encode ;
2229
23- import com .infradna .tool .bridge_method_injector .WithBridgeMethods ;
30+ import javax .servlet .ServletException ;
31+ import java .io .File ;
32+ import java .io .IOException ;
33+ import java .nio .charset .StandardCharsets ;
34+ import java .util .Objects ;
35+ import java .util .regex .Matcher ;
36+ import java .util .regex .Pattern ;
2437
25- import hudson .Extension ;
26- import hudson .FilePath ;
27- import hudson .Util ;
28- import hudson .model .AbstractBuild ;
29- import hudson .model .AbstractDescribableImpl ;
30- import hudson .model .AbstractItem ;
31- import hudson .model .Action ;
32- import hudson .model .Descriptor ;
33- import hudson .model .DirectoryBrowserSupport ;
34- import hudson .model .InvisibleAction ;
35- import hudson .model .Job ;
36- import hudson .model .ProminentProjectAction ;
37- import hudson .model .Run ;
38- import hudson .util .HttpResponses ;
39- import jenkins .model .RunAction2 ;
38+ import static hudson .Functions .htmlAttributeEscape ;
4039
4140/**
4241 * A representation of an HTML directory to archive and publish.
@@ -48,7 +47,7 @@ public class HtmlPublisherTarget extends AbstractDescribableImpl<HtmlPublisherTa
4847 /**
4948 * The name of the report to display for the build/project, such as "Code Coverage"
5049 */
51- private final String reportName ;
50+ private String reportName ;
5251
5352 /**
5453 * The path to the HTML report directory relative to the workspace.
@@ -183,15 +182,8 @@ public void setReportTitles(String reportTitles) {
183182 this .reportTitles = StringUtils .trim (reportTitles );
184183 }
185184
186- /**
187- * Actually not safe, this allowed directory traversal (SECURITY-784).
188- * @return Returns a string with replaced whitespaces by underscores.
189- */
190- private String getLegacySanitizedName () {
191- String safeName = this .reportName ;
192- safeName = safeName .replace (" " , "_" );
193- return safeName ;
194- }
185+ //Add this for testing purposes
186+ public void setReportName (String reportName ) {this .reportName = StringUtils .trim (reportName );}
195187
196188 public String getSanitizedName () {
197189 return sanitizeReportName (this .reportName , getEscapeUnderscores ());
@@ -313,11 +305,6 @@ protected File dir() {
313305 if (run != null ) {
314306 File javadocDir = getBuildArchiveDir (run );
315307
316- if (!javadocDir .exists ()) {
317- javadocDir = getBuildArchiveDir (run , getLegacySanitizedName ());
318- }
319- // TODO not sure about this change
320-
321308 if (javadocDir .exists ()) {
322309 for (HTMLBuildAction a : run .getActions (HTMLBuildAction .class )) {
323310 if (a .getHTMLTarget ().getReportName ().equals (getHTMLTarget ().getReportName ())) {
@@ -329,15 +316,7 @@ protected File dir() {
329316 }
330317 }
331318
332- // SECURITY-784: prefer safe over legacy, but if neither exists, return safe dir
333319 File projectArchiveDir = getProjectArchiveDir (this .project );
334- if (projectArchiveDir .exists ()) {
335- return projectArchiveDir ;
336- }
337- File legacyProjectArchiveDir = getProjectArchiveDir (this .project , getLegacySanitizedName ());
338- if (legacyProjectArchiveDir .exists ()) {
339- return legacyProjectArchiveDir ;
340- }
341320 return projectArchiveDir ;
342321 }
343322
@@ -440,15 +419,7 @@ public String getBackToUrl() {
440419
441420 @ Override
442421 protected File dir () {
443- // SECURITY-784: prefer safe over legacy, but if neither exists, return safe dir
444422 File buildArchiveDir = getBuildArchiveDir (this .build );
445- if (buildArchiveDir .exists ()) {
446- return buildArchiveDir ;
447- }
448- File legacyBuildArchiveDir = getBuildArchiveDir (this .build , getLegacySanitizedName ());
449- if (legacyBuildArchiveDir .exists ()) {
450- return legacyBuildArchiveDir ;
451- }
452423 return buildArchiveDir ;
453424 }
454425
0 commit comments