1

I have an ITS soap solution and I was wondering if I should use html.encode for the query string.

[ValidateInput(false)]
public ActionResult Sample()
{
    string testLogin = Request.QueryString["testLogin"];
    if (string.Equals(testLogin, "true"))
    {
        return View("TestLoginView");
    }
}

I have given the validateinput as false, does my page becomes more secure if I make it as true? In place of Request.QueryString["testLogin"] should I use html.encode(Request.QueryString["testLogin"]) to make it more secure?

4
  • "More secure" from what? What security problem are you looking to solve in this example? Commented Sep 15, 2022 at 11:01
  • @David I'm talking about cross site scripting attacks Commented Sep 15, 2022 at 11:04
  • 1
    @Coding_ninja xss usually involves writing a value back to the browser, to be executed by a client in an unexpected and malicious way; since you're not doing that here, xss does not apply. That doesn't mean other abuses don't need to be considered, but: xss is not one of them. Likewise, you don't need to worry about SQL injection because you're not doing SQL. If that sounds silly, sorry: but - you're not doing anything xss-related with this data. Commented Sep 15, 2022 at 11:06
  • 1
    @Coding_ninja Your best bet is to learn what that is, not just call random functions and hope for the best. "Security" doesn't come from calling a function that "makes it more secure", it comes from understanding the threats and when/how/why to apply the solutions. Commented Sep 15, 2022 at 11:06

1 Answer 1

2

You should only use Html.Encode when converting non-html data to html, i.e. encoding it as html. In your example, you're comparing a value against another value - not doing anything involving html; so no: you do not need to html-encode it. However, since you're comparing it to the literal "html" (which doesn't involve any escaped tokens), it also won't change the truthiness (or not) of that test - it is just unnecessary.

Typically you might use Html.Encode when rendering data in an html view, although it is usually easier to use the inbuilt encoding in modern razor.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.