Skip to content

Commit b77a5c8

Browse files
authored
Remove workaround for long patched CVE in javadoc (#388)
* Remove workaround for long patched CVE in javadoc * remove src/main/resources/org/apache/maven/plugins/javadoc/frame-injection-fix.txt
1 parent c74b8df commit b77a5c8

File tree

3 files changed

+7
-105
lines changed

3 files changed

+7
-105
lines changed

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,6 @@ under the License.
441441
<!-- Javadoc package list files cannot contain a license header -->
442442
<exclude>**/*element-list*</exclude>
443443
<exclude>**/*package-list*</exclude>
444-
<!-- This file is used to patch the generated Javadoc html files -->
445-
<exclude>src/main/resources/org/apache/maven/plugins/javadoc/frame-injection-fix.txt</exclude>
446444
<!-- Original POM file that is used in a repository -->
447445
<exclude>src/test/resources/unit/test-javadoc-test/junit/junit/3.8.1/junit-3.8.1.pom</exclude>
448446
<!-- temporary file that sometimes stays after a failure then completely blocks build -->

src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugins.javadoc;
2020

2121
import java.io.File;
22-
import java.io.FileNotFoundException;
2322
import java.io.IOException;
2423
import java.io.InputStream;
2524
import java.io.Writer;
@@ -118,9 +117,7 @@
118117
import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
119118
import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
120119
import org.codehaus.plexus.languages.java.version.JavaVersion;
121-
import org.codehaus.plexus.util.DirectoryScanner;
122120
import org.codehaus.plexus.util.FileUtils;
123-
import org.codehaus.plexus.util.IOUtil;
124121
import org.codehaus.plexus.util.WriterFactory;
125122
import org.codehaus.plexus.util.cli.CommandLineException;
126123
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -735,6 +732,7 @@ public AbstractJavadocMojo(
735732
/**
736733
* This option creates documentation with the appearance and functionality of documentation generated by
737734
* Javadoc 1.1. This is no longer supported since Javadoc 1.4 (shipped with JDK 1.4)
735+
*
738736
* @see <a href="https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#a1.1">Javadoc option 1.1</a>.
739737
*/
740738
@Parameter(property = "old", defaultValue = "false")
@@ -1567,10 +1565,13 @@ public AbstractJavadocMojo(
15671565
private List<String> sourceFileExcludes;
15681566

15691567
/**
1570-
* To apply a security fix on generated javadoc, see
1571-
* <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-1571>CVE-2013-157</a>.
1568+
* No-op.
1569+
*
1570+
* @deprecated the security fix this applied is not needed in Java 8+ or the most recent
1571+
* versions of JDK 6 and 7.
15721572
* @since 2.9.1
15731573
*/
1574+
@Deprecated
15741575
@Parameter(defaultValue = "true", property = "maven.javadoc.applyJavadocSecurityFix")
15751576
private boolean applyJavadocSecurityFix = true;
15761577

@@ -2079,20 +2080,6 @@ protected void executeReport(Locale unusedLocale) throws MavenReportException {
20792080
scriptFile.delete();
20802081
}
20812082
}
2082-
if (applyJavadocSecurityFix) {
2083-
// finally, patch the Javadoc vulnerability in older Javadoc tools (CVE-2013-1571):
2084-
try {
2085-
final int patched = fixFrameInjectionBug(javadocOutputDirectory, getDocencoding());
2086-
if (patched > 0) {
2087-
getLog().info(String.format(
2088-
"Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in %d files.", patched));
2089-
}
2090-
} catch (IOException e) {
2091-
throw new MavenReportException("Failed to patch javadocs vulnerability: " + e.getMessage(), e);
2092-
}
2093-
} else {
2094-
getLog().info("applying javadoc security fix has been disabled");
2095-
}
20962083
}
20972084

20982085
/**
@@ -5197,53 +5184,7 @@ private boolean isInformationalOutput(String str) {
51975184
}
51985185

51995186
/**
5200-
* Patches the given Javadoc output directory to work around CVE-2013-1571
5201-
* (see http://www.kb.cert.org/vuls/id/225657).
5202-
*
5203-
* @param javadocOutputDirectory directory to scan for vulnerabilities
5204-
* @param outputEncoding encoding used by the javadoc tool (-docencoding parameter).
5205-
* If {@code null}, the platform's default encoding is used (like javadoc does).
5206-
* @return the number of patched files
5207-
*/
5208-
private int fixFrameInjectionBug(File javadocOutputDirectory, String outputEncoding) throws IOException {
5209-
final String fixData;
5210-
5211-
try (InputStream in = this.getClass().getResourceAsStream("frame-injection-fix.txt")) {
5212-
if (in == null) {
5213-
throw new FileNotFoundException("Missing resource 'frame-injection-fix.txt' in classpath.");
5214-
}
5215-
fixData = org.codehaus.plexus.util.StringUtils.unifyLineSeparators(IOUtil.toString(in, "US-ASCII"))
5216-
.trim();
5217-
}
5218-
5219-
final DirectoryScanner ds = new DirectoryScanner();
5220-
ds.setBasedir(javadocOutputDirectory);
5221-
ds.setCaseSensitive(false);
5222-
ds.setIncludes(new String[] {"**/index.html", "**/index.htm", "**/toc.html", "**/toc.htm"});
5223-
ds.addDefaultExcludes();
5224-
ds.scan();
5225-
int patched = 0;
5226-
for (String f : ds.getIncludedFiles()) {
5227-
final File file = new File(javadocOutputDirectory, f);
5228-
// we load the whole file as one String (toc/index files are
5229-
// generally small, because they only contain frameset declaration):
5230-
final String fileContents = FileUtils.fileRead(file, outputEncoding);
5231-
// check if file may be vulnerable because it was not patched with "validURL(url)":
5232-
if (!StringUtils.contains(fileContents, "function validURL(url) {")) {
5233-
// we need to patch the file!
5234-
final String patchedFileContents =
5235-
StringUtils.replaceOnce(fileContents, "function loadFrames() {", fixData);
5236-
if (!patchedFileContents.equals(fileContents)) {
5237-
FileUtils.fileWrite(file, outputEncoding, patchedFileContents);
5238-
patched++;
5239-
}
5240-
}
5241-
}
5242-
return patched;
5243-
}
5244-
5245-
/**
5246-
* @param outputFile not nul
5187+
* @param outputFile not null
52475188
* @param inputResourceName a not null resource in <code>src/main/java</code>, <code>src/main/resources</code> or
52485189
* <code>src/main/javadoc</code> or in the Javadoc plugin dependencies.
52495190
* @return the resource file absolute path as String

src/main/resources/org/apache/maven/plugins/javadoc/frame-injection-fix.txt

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)