Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6883621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:24:20+00:00 2026-05-27T05:24:20+00:00

i need to write a generic routine which will filter cross site scripting related

  • 0

i need to write a generic routine which will filter cross site scripting related character.
i found one that is in java. i dont know java.

here is java code

package com.greatwebguy.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class CrossScriptingFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
}
public void destroy() {
    this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
    chain.doFilter(new RequestWrapper((HttpServletRequest) request), response);
}

}

package com.greatwebguy.filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
public final class RequestWrapper extends HttpServletRequestWrapper {
public RequestWrapper(HttpServletRequest servletRequest) {
    super(servletRequest);
}
public String[] getParameterValues(String parameter) {
  String[] values = super.getParameterValues(parameter);
  if (values==null)  {
              return null;
      }
  int count = values.length;
  String[] encodedValues = new String[count];
  for (int i = 0; i < count; i++) {
             encodedValues[i] = cleanXSS(values[i]);
   }
  return encodedValues;
}
public String getParameter(String parameter) {
      String value = super.getParameter(parameter);
      if (value == null) {
             return null;
              }
      return cleanXSS(value);
}
public String getHeader(String name) {
    String value = super.getHeader(name);
    if (value == null)
        return null;
    return cleanXSS(value);
}
private String cleanXSS(String value) {
            //You'll need to remove the spaces from the html entities below
    value = value.replaceAll("<", "& lt;").replaceAll(">", "& gt;");
    value = value.replaceAll("\\(", "& #40;").replaceAll("\\)", "& #41;");
    value = value.replaceAll("'", "& #39;");
    value = value.replaceAll("eval\\((.*)\\)", "");
    value = value.replaceAll("[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']", "\"\"");
    value = value.replaceAll("script", "");
    return value;
}

}

<filter>
<filter-name>XSS</filter-name>
<display-name>XSS</display-name>
<description></description>
<filter-class>com.greatwebguy.filter.CrossScriptingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>XSS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

the url from where i got this code
http://greatwebguy.com/programming/java/simple-cross-site-scripting-xss-servlet-filter/

anyone can give me the tips to convert the code to asp.net & c# or write class from scratch which mimic the above functionality.
thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:24:21+00:00Added an answer on May 27, 2026 at 5:24 am

    Cross-site scripting can be avoided easily by ensuring that any user submitted content is HTML encoded prior to being rendered in the page. Usually this would be achieved by consistently using the <%: instead of the <%= ASPX tag to ensure that encoding is applied to the content. Attempting to “clean” input is doomed to failure. Rendering that input correctly is all that is required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a generic procedure that set value for one column or
I need write an update statement that used multiple tables to determine which rows
I need to write a Java Comparator class that compares Strings, however with one
I need to write a program that will take a existing local windows user,
I need to write java generic method that gets no parameter and returns a
I need to write a generic class where the type parameter must be something
I need to write AVL-tree with generic type in C. The best way I
I need to write a program used internally where different users will have different
I need to write a Delphi application that pulls entries up from various tables
I need to write code that picks up PGP-encrypted files from an FTP location

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.