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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:47:46+00:00 2026-06-18T11:47:46+00:00

In Java, I find it straight forward to take a string and use it

  • 0

In Java, I find it straight forward to take a string and use it as a key in a LinkedHashMap. I can even translate it into JSON and back with no troubles.

I am using Node.JS/JavaScript now, and there is a special case that is not handled.

var makesSense = '{"__proto__":"foo","toString":"bar"}'
var noSense = JSON.stringify(JSON.parse('{"__proto__":"foo","toString":"bar"}'))
console.log(noSense) // outputs {"toString":"bar"}

What is the recommended way to handle __proto__ and other things like it. It would seem that toString is not causing any trouble, but supposing I needed consistent handling of untrusted data. What is the recommended solution?

  • Prepend an extra character before every key? If so, what character makes the most sense? I know it can’t be an underscore, so what about a space?
  • Use a module that handles this for me? I would want one that will handle this conveniently and without excessive features. (some features would be nice though)
  • Something else? Is there a solution that is compatible with JSON.parse?

Why does this matter? Surely nobody is actually going to type __proto__ by accident. But what if they were doing this on purpose. They learn I am using JavaScript, so what? – No problems except in the following situation:

  • Software has a array of strings. It just so happens one of these strings say __proto__ because someone was poking around trying to break my software.
  • Software creates a Map using those strings for a key, and fills the Map with some nice data.
  • Software later goes through the array of strings, and collects the information from the Map. The Map returns something null, and then boom: null pointer exception.
  • Software now does not work. This would qualify as something sort of like denial of service.

I know that that situation is absolutely vary rare, but I don’t like it. I cannot remember all the quirks of the programming language I am using, so given enough time, I am bound to write this kind of code.

I pride myself on creating code that is not subject to tampering. So, I am attempting to eliminate these pinholes from my software.

Yes, these are super-minor, but it is at least worth a StackOverflow question, to see if people have a better answer than I know. I learn a lot this way.

  • 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-18T11:47:47+00:00Added an answer on June 18, 2026 at 11:47 am

    Prepend an extra character before every key? If so, what character makes the most sense? I know it can’t be an underscore, so what about a space?

    I use an x, but it’s arbitrary. So long as you use something that’s unlikely to form a special property name like (on some engines) __proto__, or toString, or valueOf (and I’m not aware of any special property names starting with x), you’re fine.

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

Sidebar

Related Questions

How can I make it possible for a Java applet find xuggle path? I
I am trying to find my java class URL in order to use it
Well, I must be brain-damaged, because I can't find the java source for Sun's
How do I find groups a user belongs to? I can use GroupManager.findAllGroups() then
Note: I could not find a straight-forward answer to this problem so I will
I've searched for this but can't seem to find a straight answer for this.
I'm learning Java and find myself sending methods around while asking for help but
I would like to know if there's a way in java to find out
I need a Java code to find the length of a formatted decimal. Eg
I'm trying to find a Java library to highlight code. I don't want 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.