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

HTTP Headers server side validation #24379

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public HttpRequestSessionContext(HttpServletRequest servletRequest, SqlParserOpt
public HttpRequestSessionContext(HttpServletRequest servletRequest, SqlParserOptions sqlParserOptions, TracerProvider tracerProvider, Optional<SessionPropertyManager> sessionPropertyManager)
throws WebApplicationException
{
catalog = trimEmptyToNull(servletRequest.getHeader(PRESTO_CATALOG));
schema = trimEmptyToNull(servletRequest.getHeader(PRESTO_SCHEMA));
catalog = filterSpecialCharacters(trimEmptyToNull(servletRequest.getHeader(PRESTO_CATALOG)));
schema = filterSpecialCharacters(trimEmptyToNull(servletRequest.getHeader(PRESTO_SCHEMA)));
assertRequest((catalog != null) || (schema == null), "Schema is set but catalog is not");

String user = trimEmptyToNull(servletRequest.getHeader(PRESTO_USER));
Expand All @@ -168,7 +168,7 @@ public HttpRequestSessionContext(HttpServletRequest servletRequest, SqlParserOpt
certificates = ImmutableList.of();
}

source = servletRequest.getHeader(PRESTO_SOURCE);
source = filterSpecialCharacters(servletRequest.getHeader(PRESTO_SOURCE));
userAgent = servletRequest.getHeader(USER_AGENT);
remoteUserAddress = !isNullOrEmpty(servletRequest.getHeader(X_FORWARDED_FOR)) ? servletRequest.getHeader(X_FORWARDED_FOR) : servletRequest.getRemoteAddr();
timeZoneId = servletRequest.getHeader(PRESTO_TIME_ZONE);
Expand Down Expand Up @@ -392,6 +392,11 @@ private static String trimEmptyToNull(String value)
return emptyToNull(nullToEmpty(value).trim());
}

private static String filterSpecialCharacters(String value)
{
return emptyToNull(nullToEmpty(value).replaceAll("[;&|><*?$\\[\\](){}/!#%=\\\\]", ""));
}

private static String urlDecode(String value)
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public void testSessionContext()
HttpServletRequest request = new MockHttpServletRequest(
ImmutableListMultimap.<String, String>builder()
.put(PRESTO_USER, "testUser")
.put(PRESTO_SOURCE, "testSource")
.put(PRESTO_CATALOG, "testCatalog")
.put(PRESTO_SCHEMA, "testSchema")
.put(PRESTO_SOURCE, "testSo$%$urce")
.put(PRESTO_CATALOG, "testC#ata;log$$$")
.put(PRESTO_SCHEMA, "testSchem$#!a")
.put(PRESTO_LANGUAGE, "zh-TW")
.put(PRESTO_TIME_ZONE, "Asia/Taipei")
.put(PRESTO_CLIENT_INFO, "client-info")
Expand Down
Loading