Skip to content

Commit

Permalink
Fix known XSS vulnerabilities
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <[email protected]>
  • Loading branch information
Astralidea committed Oct 18, 2024
1 parent 5dd0cc5 commit dca26b0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions fe/fe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ under the License.
<artifactId>odps-sdk-table-api</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.owasp.encoder/encoder -->
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
</dependency>

<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>junit-benchmarks</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.owasp.encoder.Encode;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -55,9 +56,9 @@ public static void registerAction(ActionController controller) throws IllegalArg
public void executeGet(BaseRequest request, BaseResponse response) {
getPageHeader(request, response.getContent());

// get parameters
addVerboseName = request.getSingleParameter("add_verbose");
delVerboseName = request.getSingleParameter("del_verbose");
// HTML encode the add_verbose and del_verbose to prevent XSS
addVerboseName = Encode.forHtml(request.getSingleParameter("add_verbose"));
delVerboseName = Encode.forHtml(request.getSingleParameter("del_verbose"));
LOG.info("add verbose name: {}, del verbose name: {}", addVerboseName, delVerboseName);

appendLogConf(response.getContent());
Expand Down Expand Up @@ -141,9 +142,10 @@ private void appendLogInfo(StringBuilder buffer) {
raf.seek(startPos);
buffer.append("<p>Showing last " + webContentLength + " bytes of log</p>");
buffer.append("<pre>");
String fileBuffer = null;
String fileBuffer;
while ((fileBuffer = raf.readLine()) != null) {
buffer.append(fileBuffer).append("\n");
// HTML encode to prevent XSS
buffer.append(Encode.forHtml(fileBuffer)).append("\n");
}
buffer.append("</pre>");
} catch (FileNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import com.starrocks.http.IllegalArgException;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.owasp.encoder.Encode;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void executeGet(BaseRequest request, BaseResponse response) {
}

// HTML encode the queryId to prevent XSS
String encodedQueryId = StringEscapeUtils.escapeHtml4(queryId);
String encodedQueryId = Encode.forHtml(queryId);
String queryProfileStr = ProfileManager.getInstance().getProfile(queryId);
if (queryProfileStr != null) {
appendCopyButton(response.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.owasp.encoder.Encode;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -77,7 +78,9 @@ public void executeGet(BaseRequest request, BaseResponse response) {
if (Strings.isNullOrEmpty(currentPath)) {
currentPath = "/";
}
appendSystemInfo(response.getContent(), currentPath, currentPath);
// HTML encode the path to prevent XSS
String encodePath = Encode.forHtml(currentPath);
appendSystemInfo(response.getContent(), encodePath, encodePath);

getPageFooter(response.getContent());
writeResponse(request, response);
Expand Down
7 changes: 7 additions & 0 deletions fe/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,13 @@ under the License.
<version>${odps.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.owasp.encoder/encoder -->
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
<version>1.3.1</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit dca26b0

Please sign in to comment.