Not every database receives SQL text. A NoSQL document store may receive a structured query containing fields and operators. A document is a record; an operator tells the database how to compare or transform values. The exact query language depends on the database.
JSON represents values such as strings, objects and arrays. A quoted value is a string; braces enclose an object with named properties. A schema states which types and fields an application accepts. Here username must be a string, so a well-formed object is still the wrong input type.
Before you begin
- Recommended first
- Notes: scope, command, result, time, HTTP methods, headers, status codes, cookies, How a web app is put together, Same-origin policy, XXE
- Estimated time
- 18 min reading, 12 min activity. Setup and optional practice may take longer.
- Where you work
- Read the original fictional requests, source fragments and state tables in a current desktop or mobile browser. The required activity needs no server, database, account or installed security tool. Do not send the printed requests to any service.
- Without a lab
- Use the complete printed evidence to trace the data or state on paper. Write the decision, the fact supporting it and one limit of the model, then compare with the activity rubric. This does not establish live service behavior. Reading works without JavaScript. Checking requires JavaScript and a secure browser context; saving also requires usable browser storage.
After this lesson you can:
- Tell a JSON string from a JSON object.
- Accept the activity username lane and refuse the operator-shaped object.
01Example
Read the worked username and schema, then classify the fresh activity values in the supplied JSON. No database is required.
Schema: username must be a string
Worked value: "ada"
JSON type: string
Decision: meets this type requirement
This does not establish identity or permission.02Type before meaning
The card accepts ada and lane as strings and rejects the object containing kind. An application that merges arbitrary caller objects into a query may let their structure change query behavior. These cards do not use a real database operator; they isolate the type boundary so you can explain why valid JSON alone is insufficient.
Validate types and allowed keys on the server, build the intended query through the database's supported API, and keep caller values from becoming query structure. This schema check addresses the demonstrated type confusion; complete prevention also depends on the chosen database and how its query is constructed.
Accept a username only when it is a string, and refuse an object even when the JSON is well formed.Model. A teaching model drawn by hand. It shows the idea, not real tool output.
Read the full explanation below.
Schema: username must be a string
met · JSON type: string.This does not establish identity or permission.
unknown · No identity evidence supplied.The supplied ada string meets this schema line only.
Well-formed data and a matching type do not authenticate a user or prove a safe full query.
The supplied ada string meets this schema line only.
Follow the explanation
- The supplied ada string meets this schema line only.
- The model does not turn a schema pass into authentication or permission.
Read every state and value
1. The supplied ada string meets this schema line only.
- Case
- type
- Conditions inspected
- type · identity
- Decision shown
- Yes
2. The model does not turn a schema pass into authentication or permission.
- Case
- identity
- Conditions inspected
- type · identity
- Decision shown
- Yes
03Classify the activity values
Read the evidence before comparing your reasoning with the activity rubric. Do not start a database.
{
"schema": {"username": "string"},
"worked": {"username": "ada"},
"activity_string": {"username": "lane"},
"activity_object": {"username": {"kind": "operator"}},
"field_note": "The question uses two other requests, A and B."
}
JSON types on this card.
A value in quotes is a string.
A value in braces is an object.
An object can be well-formed JSON and still violate a schema that requires a string.
worked username ada: string. Meets the schema.
activity username lane: string. Meets the schema.
activity username object with kind: object. Does not meet the schema.
This card does not use a database product's operator names.
The server rejects the object because the type is wrong.
A check that runs only in the browser is not this decision.
- Write the JSON type of username lane and the type of the value that contains kind.
- Compare each with the schema line.
- Check: lane meets the string schema. The object does not. ada is the worked string.
- Stop. Do not send these bodies to a real store.
04Optional challenge
Explain why a check that runs only in the browser cannot enforce this schema. The rubric is: the caller can send the object without that browser check, and the server still has to refuse the type. About ten minutes.
05Fresh cases for the checks
Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.
JSON case A: fresh valuesOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
P: "reed"
Q: {"kind":"filter"}
R: ["reed"]
A quoted value is a string; braces enclose an object; brackets enclose an array.
JSON case B: independent requestsOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
Server schema: username must be a string. No coercion or query-structure merge is allowed.
M: {"username":"fern"}
N: {"username":{"kind":"filter"}}
O: {"username":["fern"]}
All are syntactically valid JSON; no database is involved.
06Explain your evidence
Optional written self-check: explain one decision using the supplied case. No tool run is required.
Check your explanation: classify the complete value and the username field separately; apply the string schema on the server; distinguish valid JSON, valid application input and authenticated identity; avoid merging caller structure into queries.
07Common mistakes
If you accept the object because it is valid JSON, you skipped the schema. The type is wrong.
If you look for the letters A and B in the file, those labels are only in the question.
If you invent a product operator name, you left the card. The card refuses the object by type.
References
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
Sections 1 and 3. JSON has primitive types plus objects and arrays. Strings use quotation marks. This lesson uses that distinction. No database was started.
- PortSwigger: NoSQL injection
Explains the failure mechanism and prevention. Use it for further reading after reasoning from this page's original model; a topic page is not evidence that a lab was launched.