Custom sanitizers
How to define custom sanitizers as Snyk Code Rule Extensions to reduce false positives in taint flow analysis
How custom sanitizers work
Types of sanitizers
Flow Through
package com.company.utils;
public class SecurityUtils {
public static String escapeHtml(String data) {
if (data == null) return "";
return data.replace("<", "<").replace(">", ">");
}
}import com.company.utils.SecurityUtils;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CommentServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
var userComment = request.getParameter("comment");
var safeComment = SecurityUtils.escapeHtml(userComment);
response.getWriter().println("<html><body>" + safeComment + "</body></html>");
}
}If True
If False
Any Usage
Last updated
Was this helpful?

