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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:27:06+00:00 2026-05-16T23:27:06+00:00

What are the risks of using Javascript and how to avoid them?

  • 0

What are the risks of using Javascript and how to avoid them?

  • 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-16T23:27:07+00:00Added an answer on May 16, 2026 at 11:27 pm

    One of the most common errors is HTML injection, allowing third parties to inject JavaScript into your security context. That allows an attacker to control what a user does on your site, completely breaking account security.

    Whilst there has been some slow progress trying to get web authors to remember to HTML-encode strings they output into web pages at the server side (eg htmlspecialchars in PHP), a new generation of webapps are using the same dumb string-concatenation hacks to create content at the client-side using JavaScript:

    somediv.innerHTML= '<p>Hello, '+name+'</p>';
    

    often using jQuery:

    $('table').append('<tr title="'+row.title+'"><td>'+row.description+'</td></tr>');
    

    This is just as vulnerable as server-side HTML injection and authors really need to stop building content this way. You can HTML-encode text content at the client side, but since JS doesn’t have a built-in HTML encoder you’d have to do it yourself:

    function encodeHTML(s) {
        return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
    }
    
    somediv.innerHTML= '<p>Hello, '+encodeHTML(name)+'</p>';
    

    However it’s usually much better to use the available DOM methods and properties that obviate the need for escaping:

    var p= document.createElement('p');
    p.appendChild(document.createTextNode('Hello, '+name);
    

    and with jQuery use attr(), text() and the creation shortcuts:

    $('table').append(
        $('<tr>', {title: row.title}).append(
            $('<td>', {text: row.description})
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I post a message to twitter using only javascript (no serverside authentification).
I am using javascript to determine the visitors ip address. For what ever reason,
We have created an invite function at our site in JavaScript using the Graph
The official way of preventing security risks with mass-assignment is using attr_accessible . However,
Is there any way to crop a photo using client side JavaScript only? When
I need to know, are there any risks using the realloc() function to get
Is there a risk in using @Html.Raw ? It seems to me there shouldn't
I got a simple question about jQuery but rather javascript approaches in general... Is
I'm curious what's the view on things that compile into javascript e.g. GWT, Script#
I am using GSON to parse a Java bean and pass the JSON string

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.