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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:10:48+00:00 2026-06-04T12:10:48+00:00

I maintain a PHP application. A user has recently reported the following code is

  • 0

I maintain a PHP application. A user has recently reported the following code is vulnerable to XSS.

from_name = jQuery("#from_name").val();
from_email = jQuery("#from_email").val();
subject = jQuery("#subject").val();
msg = "From: " + from_name + " (" + from_email + ")<br />";
msg = msg + "Subject: " + subject;
jQuery("#review").html(msg);

His suggestion follows.

from_name = jQuery("#from_name").val();
from_email = jQuery("#from_email").val();
subject = jQuery("#subject").val();
msg = "From: " + from_name.replace(/</g,"&lt;").replace(/>/g,"&gt;") + " (" + from_email.replace(/</g,"&lt;").replace(/>/g,"&gt;") + ")<br />";
msg = msg + "Subject: " + subject.replace(/</g,"&lt;").replace(/>/g,"&gt;");
jQuery("#review").html(msg);

If it isn’t obvious, this is significantly simplified. Regardless, his solution is just to clean up potential elements with .replace(/</g,"&lt;").replace(/>/g,"&gt;") which I don’t immediately have a problem with but seems either A) unnecessary or B) incomplete.

I’ve considered using .text instead of .html but then I can’t format my text appropriately. Unless I’m overlooking something stupid.

I can see how it might be vulnerable since the originating elements are input elements, but those input elements are filled from a database. The database was filled originally using $_POST, which is vulnerable, but I validate the data before committing it to the database, including stripping all HTML tags.

In my opinion, the only chance for XSS is literally on the page if the element is altered by the user (seems stupid) or JavaScript, either way, my review element could be temporarily compromised, but once the change is ‘saved’ my validation functions would strip out the malicious changes.

This is a long winded question, I hope my logic is reasonable.

  • 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-06-04T12:10:49+00:00Added an answer on June 4, 2026 at 12:10 pm

    While you may be correct that you are probably not vulnerable if you are sanitizing the input to the database. It’s always better to sanitize on the way out as well for any content that has been posted to your database. A better way to handle it would be to use $.text like the following.

    from_name = jQuery("#from_name").val();
    from_email = jQuery("#from_email").val();
    subject = jQuery("#subject").val();
    var subjectDiv = jQuery('<div>').attr('id','subjectDiv').text('Subject:'+subject);
    var fromDiv = jQuery('<div>').attr('id','fromDiv').text('From: '+from_name+ ' (' +from_email +')');
    jQuery("#review").empty();
    jQuery('#review').append(fromDiv);
    jQuery('#review').append(subjectDiv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm about to code a php/mysql platform that does the following: Admin panel User
In a recent project, I have to maintain some PHP code. I set up
I have a PHP MySQL application which has a modular design. There are about
I've got a PHP-driven site that has a recordkeeping form. The user chooses a
I maintain a PHP application with SQL Server backend. The DB structure is roughly
I maintain an application that uses a (to me) surprising PHP quirk/bug/feature. Consider this
I am writing a PHP/MySQL application that maintains a masterlist of user preferences and
I maintain a PHP driven application with Oracle backend (OCI8 functions). The app is
I maintain a legacy application that runs on PHP/5.2.6 under Windows Server 2003 and
I am rewriting a web application and will be porting procedural PHP code to

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.