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

  • SEARCH
  • Home
  • 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 3442886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:43:27+00:00 2026-05-18T08:43:27+00:00

I have a system which allows users to enter HTML-reserved characters into a text

  • 0

I have a system which allows users to enter HTML-reserved characters into a text area, then post that to my application. That information is then saved to a database for later retrieval and display. Alarms are (should be) going off in your head. I need to make sure that I avoid XSS attacks, because I will display this data somewhere else in the application. Here are my options as I see it:

Encode before save to DB

I can HTML-encode the data on the way in to the database, so no HTML characters ever are entered in the database.

Pros:

  • Developers don’t have to remember to HTML encode the data when its displayed on the web page.

Cons:

  • The data now doesn’t make sense for desktop-based applications (or anything other than HTML). Stuff shows up like < > & etc.

Don’t HTML encode before saving to DB

I can HTML encode the data whenever I need to display it on a web page.

Pros:

  • Feels right because it keeps the integrity of the data that was entered by the user.
  • Allows non-HTML based applications to just display this data without having to worry about HTML encoding.

Cons:

  • We might display this data in a lot of places, and we’ll have to make sure that every developer knows that when you display this field, you’ll need to HTML encode it.
  • People forget things. There WILL be at least once instance when we forget to HTML encode the data.

Scrub the data before saving to DB (don’t HTML encode)

I can use a well-tested third party library to remove potentially dangerous HTML and get a safe HTML fragment to save the database, not HTML encoded.

Pros:

  • Preserves most of the original input so that display in a non-HTML format makes sense.
  • Less catastrophic if the developer forgets to HTML encode this information for display on a web page.

Cons:

  • Still messes with the data as the user originally entered it. If they really want to type a <script> or <object> tag, it won’t make it, and we’ll get support calls and emails because of that.

My question is: What is the best option, or if there is another way of going about this, what is it?

  • 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-18T08:43:28+00:00Added an answer on May 18, 2026 at 8:43 am

    The right thing to do is not mangle/change user input.

    So, do not encode before saving.

    Yes, this puts the onus on the developers to remember and know that they need to encode anything coming out of the DB, but this is good practice regardless.

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

Sidebar

Related Questions

I need to develop a CRM system which will allow users to have a
I have a personal details form that allows you to enter a certain number
I have a searchfield which allows a member to enter a portion of a
We have a jquery/php/mysql system that allows a user to log in and review
I'm developing an email marketing system which allows users to send emails to multiple
We are in the process of building a system which allows users to upload
I have a system which sits on a web server and generates files on
I have a system which is writing files to a folder using FTP. I
I have a web system which has a classical parent-children menu saved in a
I have a system in which different server processes are handling requests passed as

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.