Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Decode Parameter for Proxy History #168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

final def extensionName = 'burp-rest-api'
version = '2.2.0'
version = '2.2.1'

def updateVersion() {
def configFile = new File('src/main/resources/application.yml')
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/vmware/burp/extension/domain/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.vmware.burp.extension.utils.URLDecoderUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

Expand All @@ -33,8 +36,8 @@ private Parameter() {
}

public Parameter(IParameter iParameter) throws UnsupportedEncodingException {
this.name = URLDecoder.decode(iParameter.getName(), "UTF-8");
this.value = URLDecoder.decode(iParameter.getValue(), "UTF-8");
this.name = URLDecoderUtil.safeDecode(iParameter.getName());
this.value = URLDecoderUtil.safeDecode(iParameter.getValue());
this.type = ParameterType.getEnum(iParameter.getType());
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/vmware/burp/extension/utils/URLDecoderUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.vmware.burp.extension.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.regex.Pattern;

public class URLDecoderUtil {

// Regex pattern to validate hexadecimal sequences in URLs
private static final Pattern HEX_PATTERN = Pattern.compile("%[0-9A-Fa-f]{2}");

public static String safeDecode(String input) throws UnsupportedEncodingException {
// Validate hexadecimal sequences

StringBuffer decodedInput = new StringBuffer();

if (input.contains("%") && !HEX_PATTERN.matcher(input).find()) {

String[] splittedInput = input.split("%");
for (String partialInput : splittedInput) {
if (!HEX_PATTERN.matcher("%" + partialInput).find()){
decodedInput.append("%" + partialInput);
}else{
decodedInput.append(URLDecoder.decode("%" + partialInput, "UTF-8"));
}
}

}else{
decodedInput.append(URLDecoder.decode(input, "UTF-8"));
}

// Decode the input
return decodedInput.toString();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ server:
headless:
mode: ${java.awt.headless}

build.version: 2.2.0
build.version: 2.2.1