Skip to content

Commit

Permalink
Remove debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanpadams committed Apr 11, 2024
1 parent 2acc269 commit 3f159b8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public void doPost(HttpServletRequest req, HttpServletResponse res)
"POST requests are not supported by this API");
}

/**
* Generate query string from subset of allowable query parameters
*
*
* @param request
* @return
* @throws UnsupportedEncodingException
*/
private String getQueryString(HttpServletRequest request) throws UnsupportedEncodingException {
String queryString = "";

Expand Down Expand Up @@ -172,7 +180,6 @@ private String appendQueryParameters(String key, String[] parameterValues)
String queryString = "";
for (String v : Arrays.asList(parameterValues)) {
value = URLDecoder.decode(v, "UTF-8");
LOG.info(v);
queryString += String.format("%s=%s&", key, URLEncoder.encode(value, "UTF-8"));
}
return queryString;
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/gov/nasa/pds/search/util/XssUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package gov.nasa.pds.search.util;

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

public class XssUtils {

private XssUtils() {
}

// Patterns for Cross-Site Scripting filter.
private static Pattern[] xssPatterns = new Pattern[] {
// script fragments
Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE),
// src='...'
Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// lonely script tags
Pattern.compile("</script>", Pattern.CASE_INSENSITIVE),
Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// eval(...)
Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// expression(...)
Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// javascript:...
Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE),
// vbscript:...
Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE),
// onload(...)=...
Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// alert(...)
Pattern.compile("alert\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL) };

/**
* This method makes up a simple anti cross-site scripting (XSS) filter written
* for Java web applications. What it basically does is remove all suspicious
* strings from request parameters before returning them to the application.
*/
public static String clean(String value) {
if (value != null) {
// Avoid null characters
value = value.replaceAll("\0", "");

// Remove all sections that match a pattern
for (Pattern scriptPattern : xssPatterns) {
value = scriptPattern.matcher(value).replaceAll("");
}

// After all of the above has been removed just blank out the value
// if any of the offending characters are present that facilitate
// Cross-Site Scripting and Blind SQL Injection.
// We normally exclude () but they often show up in queries.
char badChars[] = { '|', ';', '$', '@', '\'', '"', '<', '>', ',', '\\', /* CR */ '\r', /* LF */ '\n',
/* Backspace */ '\b' };
try {
String decodedStr = URLDecoder.decode(value);
for (int i = 0; i < badChars.length; i++) {
if (decodedStr.indexOf(badChars[i]) >= 0) {
value = "";
}
}
} catch (IllegalArgumentException e) {
value = "";
}
}
return value;
}

}

0 comments on commit 3f159b8

Please sign in to comment.