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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:41:49+00:00 2026-06-05T17:41:49+00:00

I have JavaScript application, where I use client-side templates (underscore.js, Backbone.js). Data for initial

  • 0

I have JavaScript application, where I use client-side templates (underscore.js, Backbone.js).

Data for initial page load is strapped into the page like this (.cshtml Razor-file):

<div id="model">@Json.Encode(Model)</div>

Razor engine performs escaping, so, if the Model is

new { Title = "<script>alert('XSS');</script>" }

, in output we have:

<div id="model">{&quot;Title&quot;:&quot;\u003cscript\u003ealert(\u0027XSS\u0027)\u003c/script\u003e&quot;}</div>

Which after “parse” operation:

var data = JSON.parse($("#model").html());

we have object data with "Title" field exactly "<script>alert('XSS');</script>"!

When this goes to underscore template, it alerts.

Somehow \u003c-like symbols are treated like proper “<” symbols.

How do I escape “<” symbols to &lt; and &gt; from DB (if they somehow got there)?

Maybe I can tune Json.Encode serialization for escaping these symbols?
Maybe I can set up Entity Framework which I`m using, for automatically escape these symbols absolutely all the time when getting data from DB?

  • 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-05T17:41:51+00:00Added an answer on June 5, 2026 at 5:41 pm

    \u003c and similar codes are perfectly valid for JS. You can obfuscate whole JS files using this syntax, if you so choose. Essentially, you’re seeing an escape character \, u for unicode, and then a 4-character Hex code which relates to a symbol.

    http://javascript.about.com/library/blunicode.htm

    \u003c – as you’ve noted, is the < character.

    One approach to “fixing” this on the MVC side would be to write a RegEx which looks for the pattern \u – and then captures the next 4 characters. You could then un-encode them into actual unicode characters – and run the resultant text through your XSS prevention algorithms.

    As you’ve noted in your question – just looking for “<” doesn’t help. You also can’t just look for “\u003cscript” – because this assumes the potential hacker hasn’t simply unicode-encoded the entire “script” tag word. The safer approach is to un-escape all of these kinds of codes and then cleanse your HTML in plain-text.

    Incidentally, it might make you feel better to note that this is one of the common (and thusfar poorly resolved) issues in XSS prevention. So you aren’t alone in wanting a better solution…

    You might check out the following libraries to assist in the actual html cleansing:

    http://wpl.codeplex.com/ (Microsoft’s attempt at a solution – though very bad user feedback)
    https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project_.NET (A private project which is designed to do a lot of this kind of prevention. I find it hard to use, and poorly implemented in .NET)

    Both are good references, though.

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

Sidebar

Related Questions

I have gwt web project, which must use application.properties (on client side) loaded as
I have a PHP application that makes extensive use of Javascript on the client
I have a Host Javascript Application, which not use AMD, BackboneJS or RequireJS but
I have a web application where a client side editor is editing a really
To amliorate my application i have activeted the Client Side Validation and it works
I'm writing an application with some client-side JS that I use to update the
I have an MVC 2 application. On the client side there is a function
I have a javascript application and when I run it on firefox I am
I have a web-view running JavaScript application, and sometimes it freezes/hangs when the main
I have a html + css + javascript application. I want to be able

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.