MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 1 min read

JSON Security Best Practices β€” Interview Questions

Asked inAmazonMicrosoftGoogleDeloitte
#json#security#validation#injection#mass assignment
Report issue

⚑ Short Answer

Treat all inbound JSON as untrusted: never eval() it (use JSON.parse), validate against a schema, cap body size and nesting depth (to stop DoS), allow-list fields to prevent mass assignment, and never echo it into SQL/HTML/OS commands without escaping. On output, don't leak sensitive fields (password hashes, tokens, internal ids).

β˜•Coffee Chat Question

Concept Made Simple

β€œWhat are JSON security best practices?”

🧠Mind Map Answer

Remember It Faster

Parse safely→JSON.parse, never eval()
Validate + limit→schema, max size & depth
Allow-list→block mass assignment (isAdmin)
Output→don't leak secrets; escape when reusing

⌨️Hands-on Keyboard

Learn by Doing

javascript
// Express: cap body size to blunt DoS via giant payloads
app.use(express.json({ limit: "100kb" }));

// Allow-list fields β€” never spread req.body onto the entity
const { name, email } = req.body;   // ignore id, role, isAdmin
await users.create({ name, email });

πŸ”₯What If?

Think Beyond the Expected

How can a maliciously crafted JSON payload cause a denial of service?

Several ways: an enormous body exhausts memory/bandwidth; extremely deep nesting can blow the parser's stack; and huge arrays/strings spike CPU during parse. Defenses: enforce a max request size, limit nesting depth, set parse timeouts, and reject oversized/over-deep payloads with a 413/400 before processing.

πŸ˜‚Real World

Mass assignment (binding req.body straight onto a model so a user sets isAdmin=true) and 'parse an HTML page as JSON via eval' are real, repeatedly-exploited bugs. Size/depth limits and schema validation are standard hardening at the API edge.

🎯Interviewer's Expectation

Keywords they're listening for:

βœ“ never evalβœ“ validate + size/depth limitsβœ“ prevent mass assignmentβœ“ escape when reusing (SQLi/XSS)βœ“ don't leak sensitive fields

⚠️Common Mistakes

  • βœ—Using eval() to parse JSON
  • βœ—Spreading req.body directly onto entities
  • βœ—No size/depth limits on request bodies

βœ…Best Practices

  • βœ“Validate, size-limit, and depth-limit input
  • βœ“Allow-list fields; own privileged fields server-side
  • βœ“Escape on reuse; never leak secrets in responses

πŸ”Follow-up Questions

  • 1What is a mass-assignment vulnerability?
  • 2How does deep nesting enable a DoS?
  • 3Why must you escape JSON before putting it in HTML/SQL?

🧩Related Technologies

OWASPmass assignmentinput validationrate limiting

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β€” AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Security (JSON)
Interview question: "What are JSON security best practices?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission β€” at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions