CVE-2020-26282 (Java, published 2020-12-24T21:15Z)
Description: value: 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 v3 base score: 10)
Weakness: CWE-74 \u2014 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
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.
Repository: https://github.com/browserup/browserup-proxy
Files changed:
browserup-proxy-rest/src/main/java/com/browserup/bup/rest/validation/LongPositiveConstraint.java
browserup-proxy-rest/src/main/java/com/browserup/bup/rest/validation/NotBlankConstraint.java
browserup-proxy-rest/src/main/java/com/browserup/bup/rest/validation/PatternConstraint.java
browserup-proxy-rest/src/main/java/com/browserup/bup/rest/validation/PortWithExistingProxyConstraint.java
browserup-proxy-rest/src/main/java/com/browserup/bup/rest/validation/util/MessageSanitizer.java
Commit message: Fix Critical Java EL Injection RCE vulnerability from GHSL-2020-213


Vulnerable code:
        errorMessage = String.format("Invalid integer value: '%s'", value);
        errorMessage = String.format("Expected positive integer value, got: '%s'", value);
}
      String errorMessage = String.format("Expected not empty value, got '%s'", value);
}
        String errorMessage = String.format("URL parameter '%s' is not a valid regexp", value);
}
      String errorMessage = String.format("No proxy server found for specified port %d", value);
}

Fixed code:
import com.browserup.bup.rest.validation.util.MessageSanitizer;
        String escapedValue = MessageSanitizer.escape(value);
        errorMessage = String.format("Invalid integer value: '%s'", escapedValue);
        String escapedValue = MessageSanitizer.escape(value);
        errorMessage = String.format("Expected positive integer value, got: '%s'", escapedValue);
}
import com.browserup.bup.rest.validation.util.MessageSanitizer;

      String escapedValue = MessageSanitizer.escape(value == null ? null : value.toString());
      String errorMessage = String.format("Expected not empty value, got '%s'", escapedValue);
}
import com.browserup.bup.rest.validation.util.MessageSanitizer;
        String escapedValue = MessageSanitizer.escape(value);
        String errorMessage = String.format("URL parameter '%s' is not a valid regexp", escapedValue);
}
import com.browserup.bup.rest.validation.util.MessageSanitizer;
      String escapedValue = MessageSanitizer.escape(value.toString());
      String errorMessage = String.format("No proxy server found for specified port %s", escapedValue);
}
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" );
  }
}