Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6a1da5

Browse files
Protect readLine() against DoS (#4)
Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
1 parent bd35ce8 commit b6a1da5

File tree

8 files changed

+45
-7
lines changed

8 files changed

+45
-7
lines changed

xwiki-platform-core/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
org.xwiki.contrib:authservice-backport-api,
4747
org.xwiki.contrib:authservice-backport-default
4848
</xwiki.platform.oldcore.extension.features>
49+
<versions.java-security-toolkit>1.2.0</versions.java-security-toolkit>
4950
</properties>
5051
<build>
5152
<pluginManagement>
@@ -380,4 +381,14 @@
380381
</build>
381382
</profile>
382383
</profiles>
384+
<dependencyManagement>
385+
<dependencies>
386+
<dependency>
387+
<groupId>io.github.pixee</groupId>
388+
<artifactId>java-security-toolkit</artifactId>
389+
390+
<version>${versions.java-security-toolkit}</version>
391+
</dependency>
392+
</dependencies>
393+
</dependencyManagement>
383394
</project>

xwiki-platform-core/xwiki-platform-mailsender/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
<type>pom</type>
5757
<scope>test</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>io.github.pixee</groupId>
61+
<artifactId>java-security-toolkit</artifactId>
62+
</dependency>
5963
</dependencies>
6064
<build>
6165
<plugins>

xwiki-platform-core/xwiki-platform-mailsender/src/main/java/com/xpn/xwiki/plugin/mailsender/MailSenderPlugin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.xpn.xwiki.plugin.mailsender;
2121

22+
import io.github.pixee.security.BoundedLineReader;
2223
import java.io.BufferedReader;
2324
import java.io.File;
2425
import java.io.FileOutputStream;
@@ -404,17 +405,17 @@ protected void parseRawMessage(String rawMessage, Mail toMail)
404405
PrintWriter output = new PrintWriter(result);
405406
boolean headersFound = false;
406407

407-
line = input.readLine();
408+
line = BoundedLineReader.readLine(input, 5_000_000);
408409
// Additional headers are at the start. Parse them and put them in the Mail object.
409410
// Warning: no empty lines are allowed before the headers.
410411
Matcher m = SMTP_HEADER.matcher(line);
411412
while (line != null && m.matches()) {
412413
String header = m.group(1);
413414
String value = m.group(2);
414-
line = input.readLine();
415+
line = BoundedLineReader.readLine(input, 5_000_000);
415416
while (line != null && (line.startsWith(" ") || line.startsWith("\t"))) {
416417
value += line;
417-
line = input.readLine();
418+
line = BoundedLineReader.readLine(input, 5_000_000);
418419
}
419420
if (header.equals(SUBJECT)) {
420421
toMail.setSubject(value);
@@ -431,7 +432,7 @@ protected void parseRawMessage(String rawMessage, Mail toMail)
431432

432433
// There should be one empty line here, separating the body from the headers.
433434
if (headersFound && line != null && StringUtils.isBlank(line)) {
434-
line = input.readLine();
435+
line = BoundedLineReader.readLine(input, 5_000_000);
435436
} else {
436437
if (headersFound) {
437438
LOGGER.warn("Mail body does not contain an empty line between the headers and the body.");
@@ -447,7 +448,7 @@ protected void parseRawMessage(String rawMessage, Mail toMail)
447448
do {
448449
// Mails always use \r\n as EOL
449450
output.print(line + "\r\n");
450-
} while ((line = input.readLine()) != null);
451+
} while ((line = BoundedLineReader.readLine(input, 5_000_000)) != null);
451452

452453
toMail.setTextPart(result.toString());
453454
} catch (IOException ioe) {

xwiki-platform-core/xwiki-platform-oldcore/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@
638638
<artifactId>xwiki-platform-index-api</artifactId>
639639
<version>${project.version}</version>
640640
</dependency>
641+
<dependency>
642+
<groupId>io.github.pixee</groupId>
643+
<artifactId>java-security-toolkit</artifactId>
644+
</dependency>
641645
</dependencies>
642646
<build>
643647
<plugins>

xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R35100XWIKI7564DataMigration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.xpn.xwiki.store.migration.hibernate;
2222

23+
import io.github.pixee.security.BoundedLineReader;
2324
import java.io.BufferedReader;
2425
import java.io.IOException;
2526
import java.io.InputStreamReader;
@@ -115,7 +116,7 @@ public void execute(Connection connection) throws SQLException
115116
new InputStreamReader(this.getClass().getResourceAsStream("R35100XWIKI7564.sql"),
116117
StandardCharsets.UTF_8))) {
117118
String line;
118-
while ((line = in.readLine()) != null) {
119+
while ((line = BoundedLineReader.readLine(in, 5_000_000)) != null) {
119120
stmt.addBatch(line);
120121
}
121122
}

xwiki-platform-core/xwiki-platform-webjars/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,16 @@
4242
</modules>
4343
</profile>
4444
</profiles>
45+
<dependencyManagement>
46+
<dependencies>
47+
<dependency>
48+
<groupId>io.github.pixee</groupId>
49+
<artifactId>java-security-toolkit</artifactId>
50+
<version>${versions.java-security-toolkit}</version>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
<properties>
55+
<versions.java-security-toolkit>1.2.0</versions.java-security-toolkit>
56+
</properties>
4557
</project>

xwiki-platform-core/xwiki-platform-webjars/xwiki-platform-webjars-api/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,9 @@
127127
<artifactId>xwiki-platform-lesscss-api</artifactId>
128128
<version>${project.version}</version>
129129
</dependency>
130+
<dependency>
131+
<groupId>io.github.pixee</groupId>
132+
<artifactId>java-security-toolkit</artifactId>
133+
</dependency>
130134
</dependencies>
131135
</project>

xwiki-platform-core/xwiki-platform-webjars/xwiki-platform-webjars-api/src/main/java/org/xwiki/webjars/internal/FilesystemResourceReferenceCopier.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.xwiki.webjars.internal;
2121

22+
import io.github.pixee.security.BoundedLineReader;
2223
import java.io.BufferedReader;
2324
import java.io.File;
2425
import java.io.FileOutputStream;
@@ -152,7 +153,7 @@ private void processCSSfile(String resourcePrefix, String targetPrefix, JarEntry
152153
// Limitation: we only support url() constructs located on a single line
153154
try (BufferedReader br = new BufferedReader(new InputStreamReader(jar.getInputStream(entry), "UTF-8"))) {
154155
String line;
155-
while ((line = br.readLine()) != null) {
156+
while ((line = BoundedLineReader.readLine(br, 5_000_000)) != null) {
156157
Matcher matcher = URL_PATTERN.matcher(line);
157158
while (matcher.find()) {
158159
String url = matcher.group(1);

0 commit comments

Comments
 (0)