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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:30:28+00:00 2026-05-26T02:30:28+00:00

Is it 100% safe to do the following?: var untrusted_input_from_3rd_party = ‘<script>alert(xss)<\/script>’; document.getElementsByTagName(‘body’)[0].appendChild(document.createTextNode(untrusted_input_from_3rd_party)); Considering

  • 0

Is it 100% safe to do the following?:

var untrusted_input_from_3rd_party = '<script>alert("xss")<\/script>';
document.getElementsByTagName('body')[0].appendChild(document.createTextNode(untrusted_input_from_3rd_party));

Considering that the third party can input anything (HTML, CSS, etc.), can I be sure it won’t do any harm if I pass it through createTextNode and then add it to the dom?

  • 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-26T02:30:28+00:00Added an answer on May 26, 2026 at 2:30 am

    This is a fine way to prevent XSS. DOM manipulation via createTextNode is widely used to safely embed third party text.

    That said, there are problems besides XSS.
    It doesn’t do anything to stop social engineering attempts if the untrusted input is something like:

    ALERT: We have detected malware on your computer. Copy and paste http://evil.org/ into your browser URL bar to fix the problem.

    The best way to prevent social engineering (besides not including third-party content) is to make it clear that the content comes from a third party.

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

Sidebar

Related Questions

Question is simple. How can I make 100% safe photo upload script with php?
Is this 100% safe against XSS? If not, can you please provide example bad
Is this code 100% safe from sql injection: $id = $_GET['id'] mysql_query('SELECT * FROM
I'm wondering if editing remote files via ssh is 100% safe on public networks.
Is it safe to cast from double to decimal in the following manner in
As in C++ iterator.remove() is not 100% safe or robust does java guarantees 100%
Now I do know that obfuscation is never 100% safe, but it's better than
I stumbled on a piece of Ajax code that is not 100% safe since
here is my js code <script type='text/javascript'> // Browser safe opacity handling function function
I'm pretty sure this is 100% safe, but I don't want to miss anything.

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.