CVE-2020-26282 (published 2020-12-24T21:15Z)

BrowserUp Proxy allows you to manipulate HTTP requests and responses, capture HTTP content, and export performance data as a HAR file. BrowserUp Proxy works well as a standalone proxy server, but it is especially useful when embedded in Selenium tests. A Server-Side Template Injection was identified in BrowserUp Proxy enabling attackers to inject arbitrary Java EL expressions, leading to unauthenticated Remote Code Execution (RCE) vulnerability. This has been patched in version 2.1.2.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 10.0, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/browserup/browserup-proxy
commit_details: repo_url: https://github.com/browserup/browserup-proxy
author: kirill.turutin
author_date: 2020-12-14 12:02:17+03:00
msg: Fix Critical Java EL Injection RCE vulnerability from GHSL-2020-213
repository: repo_url: https://github.com/browserup/browserup-proxy
repo_name: browserup/browserup-proxy
description: BrowserUp Proxy is a free utility to watch, test, and manipulate web application network traffic and performance.
repo_language: Java
owner: browserup
file_changes: filename: LongPositiveConstraint.java
change_type: ModificationType.MODIFY
diff: @@ -8,6 +8,7 @@ import javax.validation.ConstraintValidator;
 import javax.validation.ConstraintValidatorContext;
 import javax.validation.Payload;
 
+import com.browserup.bup.rest.validation.util.MessageSanitizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,12 +42,14 @@ public @interface LongPositiveConstraint {
         longValue = Long.parseLong(value);
       } catch (NumberFormatException ex) {
         failed = true;
-        errorMessage = String.format("Invalid integer value: '%s'", value);
+        String escapedValue = MessageSanitizer.escape(value);
+        errorMessage = String.format("Invalid integer value: '%s'", escapedValue);
       }
 
       if (!failed && longValue < 0) {
         failed = true;
-        errorMessage = String.format("Expected positive integer value, got: '%s'", value);
+        String escapedValue = MessageSanitizer.escape(value);
+        errorMessage = String.format("Expected positive integer value, got: '%s'", escapedValue);
       }
 
       if (!failed) {
@@ -59,4 +62,4 @@ public @interface LongPositiveConstraint {
       return false;
     }
   }
-}
\ No newline at end of file
+}

programming_language: Java
filename: NotBlankConstraint.java
change_type: ModificationType.MODIFY
diff: @@ -8,6 +8,7 @@ import javax.validation.ConstraintValidator;
 import javax.validation.ConstraintValidatorContext;
 import javax.validation.Payload;
 
+import com.browserup.bup.rest.validation.util.MessageSanitizer;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,11 +37,13 @@ public @interface NotBlankConstraint {
       if (value != null && StringUtils.isNotEmpty(String.valueOf(value))) {
         return true;
       }
-      String errorMessage = String.format("Expected not empty value, got '%s'", value);
+
+      String escapedValue = MessageSanitizer.escape(value == null ? null : value.toString());
+      String errorMessage = String.format("Expected not empty value, got '%s'", escapedValue);
       LOG.warn(errorMessage);
 
       context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
       return false;
     }
   }
-}
\ No newline at end of file
+}

programming_language: Java
filename: PatternConstraint.java
change_type: ModificationType.MODIFY
diff: @@ -9,6 +9,7 @@ import javax.validation.ConstraintValidator;
 import javax.validation.ConstraintValidatorContext;
 import javax.validation.Payload;
 
+import com.browserup.bup.rest.validation.util.MessageSanitizer;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,7 +43,8 @@ public @interface PatternConstraint {
         Pattern.compile(value);
         return true;
       } catch (Exception ex) {
-        String errorMessage = String.format("URL parameter '%s' is not a valid regexp", value);
+        String escapedValue = MessageSanitizer.escape(value);
+        String errorMessage = String.format("URL parameter '%s' is not a valid regexp", escapedValue);
         LOG.warn(errorMessage);
 
         context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
@@ -50,4 +52,4 @@ public @interface PatternConstraint {
       return false;
     }
   }
-}
\ No newline at end of file
+}

programming_language: Java
filename: PortWithExistingProxyConstraint.java
change_type: ModificationType.MODIFY
diff: @@ -11,6 +11,7 @@ import javax.ws.rs.core.Context;
 
 import com.browserup.bup.proxy.ProxyManager;
 
+import com.browserup.bup.rest.validation.util.MessageSanitizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,11 +48,12 @@ public @interface PortWithExistingProxyConstraint {
         return true;
       }
 
-      String errorMessage = String.format("No proxy server found for specified port %d", value);
+      String escapedValue = MessageSanitizer.escape(value.toString());
+      String errorMessage = String.format("No proxy server found for specified port %s", escapedValue);
       LOG.warn(errorMessage);
 
       context.buildConstraintViolationWithTemplate(errorMessage).addPropertyNode(PARAM_NAME).addConstraintViolation();
       return false;
     }
   }
-}
\ No newline at end of file
+}

programming_language: Java
filename: MessageSanitizer.java
change_type: ModificationType.ADD
diff: @@ -0,0 +1,33 @@
+package com.browserup.bup.rest.validation.util;
+/*
+ * Modifications Copyright (c) 2019 BrowserUp, Inc.
+ * Original from:
+ * https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/engine/messageinterpolation/util/InterpolationHelper.java
+ */
+/*
+ * License: Apache License, Version 2.0
+ * See the license file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
+ */
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MessageSanitizer {
+
+  public static final char BEGIN_CHAR = '{';
+  public static final char END_CHAR = '}';
+  public static final char EL_DESIGNATOR = '$';
+  public static final char ESCAPE_CHARACTER = '\\';
+
+  private static final Pattern ESCAPE_PATTERN = Pattern.compile( "([\\" + ESCAPE_CHARACTER + BEGIN_CHAR + END_CHAR + EL_DESIGNATOR + "])" );
+
+  private MessageSanitizer() {
+  }
+
+  public static String escape(String message) {
+    if ( message == null ) {
+      return null;
+    }
+    return ESCAPE_PATTERN.matcher( message ).replaceAll( Matcher.quoteReplacement( String.valueOf( ESCAPE_CHARACTER ) ) + "$1" );
+  }
+}

programming_language: Java