Skip to content

Commit

Permalink
Guard against polynomial regular expression used on uncontrolled data in
Browse files Browse the repository at this point in the history
IMAPReply.TAGGED_RESPONSE
  • Loading branch information
garydgregory committed Feb 23, 2024
1 parent f6717be commit 1745292
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.11.0" date="202Y-MM-DD" description="Maintenance and bug fix release (Java 8 or above).">
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in UnixFTPEntryParser.preParse(List&lt;String&gt;).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Guard against polynomial regular expression used on uncontrolled data in VMSVersioningFTPEntryParser.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Guard against polynomial regular expression used on uncontrolled data in VMSVersioningFTPEntryParser.REGEX.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Guard against polynomial regular expression used on uncontrolled data in IMAPReply.TAGGED_RESPONSE.</action>
<!-- ADD -->
<action type="add" issue="NET-726" dev="ggregory" due-to="PJ Fanning, Gary Gregory">Add protected getters to FTPSClient #204.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SubnetUtils.toString().</action>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/apache/commons/net/imap/IMAPReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ public final class IMAPReply {
// Start of line for continuation replies
private static final String IMAP_CONTINUATION_PREFIX = "+";

private static final String TAGGED_RESPONSE = "^\\w+ (\\S+).*"; // TODO perhaps be less strict on tag match?
/**
* Guard against Polynomial regular expression used on uncontrolled data.
*
* Don't look for more than 80 letters.
* Don't look for more than 80 non-whitespace.
* Don't look for more than 80 character.
*/
private static final String TAGGED_RESPONSE = "^\\w{1,80} (\\S{1,80}).{0,80}";

// tag cannot contain: + ( ) { SP CTL % * " \ ]
/**
* Tag cannot contain: + ( ) { SP CTL % * " \ ]
*/
private static final Pattern TAGGED_PATTERN = Pattern.compile(TAGGED_RESPONSE);

private static final String UNTAGGED_RESPONSE = "^\\* (\\S+).*";
Expand Down

0 comments on commit 1745292

Please sign in to comment.