HTML, JavaScript, DOM, JSON and SQL
A web page is built from several pieces, and each has its own job. HTML says which parts the page has. JavaScript changes it while you use it. JSON is a format for sending data. SQL is the language the server uses to ask its database for data.
New here? Try the first lesson without an accountHow it works
When the browser receives the HTML, it builds a live copy of the page in memory: the DOM, a kind of blueprint that JavaScript can read and edit. When you tap “Search,” JavaScript sends your text to the server as JSON. The server uses it in an SQL query to the database and returns the result, which JavaScript adds to the DOM so you can see it.
Expected behavior
You type “Sol” into a search box. JavaScript sends it as JSON, the server looks up “Sol” in the database with SQL, and the list that comes back appears on the page.
What can go wrong
The text you typed ends up pasted inside the SQL command or the HTML, and the piece that receives it reads it as part of its instructions.
What to observe
Follow the same text from the field where you typed it to every piece that uses it, and note where it changed its role.
Common false positive
Seeing a quote mark or an odd symbol on the screen does not confirm a flaw: what matters is where that text ended up and how each piece read it.
Why it matters
Problems appear when text someone typed stops being treated as data and another piece reads it as an instruction, for example a name the database takes as part of the SQL command.
How to fix it
Each piece must receive data through a path that keeps it as data: SQL queries that send the value separately, and text displayed as text, not as HTML.
Five pieces, five jobs
HTML describes the parts of the page: a title, a paragraph, a button. The DOM is the live version of that HTML inside the browser, like a blueprint that can keep being edited. JavaScript is the language that edits that blueprint: it adds a row or changes a text. JSON is a text format for sending organized data, such as {"titulo": "Sol"}. SQL is the language the database understands.
A concrete journey
You type “Sol” into a form. JavaScript sends it to the server as JSON. The server takes that value and asks the database with SQL. Then the page shows the result. If the query carries the value separately and the page displays it as text, “Sol” stays data all the way. If at some step the text is pasted inside the SQL command or the HTML, it can change its role.
How to read a result
Odd text appearing on the screen only proves that it arrived. To speak of a flaw you have to show that it changed what a piece does: that it altered the database query, which is called SQL injection, or that the browser ran it as code, which is called XSS. Both topics have their own chapter. The same character can be harmless in one place and decisive in another.
