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 6033413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:28:46+00:00 2026-05-23T05:28:46+00:00

I know that it might stupid but how to escape user input when I

  • 0

I know that it might stupid but how to escape user input when I show it in a form. I do not mean any output, but especially in the form inputs. Like for example if I have input tag and put the user text in the value.

<input type="text" value="'test' "test" <script>alert('hacked');</script>" />

When I leave it like that it appears correctly

'test' "test" <script>alert('hacked');</script>

no XSS happens, but I do not feel secure cause with other code it could break eventually. Is there something like a browser build-in methods for preventing XSS when putting data in the form or I am missing something?

Edit: I did not say the entire story. Sorry about that. When I use htmlentities or htmlspecialchars I get the escaped data which I do not want. I see this in the input, which is not what was entered 🙁

'test' &quot;test&quot; &lt;script&gt;alert('hacked');&lt;/script&gt;

I want to prevent XSS and to show the content without changing it at the same time. Is it possible in this case.enter image description here

  • 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-23T05:28:47+00:00Added an answer on May 23, 2026 at 5:28 am

    You should HTML encode the text, so that it ends up like this:

    <input type="text" value="'test' &quot;test&quot; &lt;script&gt;alert('hacked');&lt;/script&gt;" />
    

    You should use the server language to do this. There is no built in support for this in Javascript, so you would have to build a function for that yourself.

    In ASP.NET MVC for example it could look like this:

    <input type="text" value="<%= Server.HtmlEncode(Model.UserInput) %>" />
    

    MVC 2 also has the <%: %> tag that automatically encodes the text:

    <input type="text" value="<%: Model.UserInput %>" />
    

    Edit:

    Examine the source of the page in the browser to see what the result is.

    It looks like you are escaping the text twice, so that for example " is escaped into &quot; and then into &amp;quot;.

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

Sidebar

Related Questions

I realise that this might be a stupid question, but I have not come
I know that might sound like a stupid question since it's a trivial feature
This might be a stupid question, but I notice that in a good number
I know this might be a very stupid question but I am new to
this might be a stupid question, but I'm using asp.net list control that creates
it might be stupid question, but I dont know the answer to it and
As you all might know that the MIPS instruction set supports clz (count leading
im planning to create a movie file that might have over 16,000 frames?i know
I know that default cron's behavior is to send normal and error output to
I know that |DataDirectory| will resolve to App_Data in an ASP.NET application but is

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.