Skip to main content

Learning Center

Understand why these issues matter and how to prevent them in the future.

Progress: 0 of 13 completed0%

Keeping secrets out of code

What is it?

Secrets (API keys, passwords) should live outside your code, in environment variables.

Why does it matter?

"Code gets copied, shared and pushed to GitHub. A key in code is a key in public."

Good Example:
const key = process.env.STRIPE_KEY; // set it in your host's settings

SQL injection

What is it?

Attackers type database commands into forms. If you paste that text into a query, the database runs them.

Why does it matter?

"It can expose or erase every record you have."

Good Example:
db.query('SELECT * FROM users WHERE id = $1', [id]) // the value can never become a command

Storing passwords safely

What is it?

Never store the password itself. Store a one-way scramble (a hash) and compare scrambles.

Why does it matter?

"If your database leaks, hashed passwords are useless to thieves; plain ones are not."

Good Example:
const ok = await bcrypt.compare(input, user.passwordHash);

Why eval is dangerous

What is it?

eval runs any text as code.

Why does it matter?

"If a user can influence that text, they control your app."

Good Example:
const data = JSON.parse(text); // reads data without running it
Read more:

Cross-site scripting (XSS)

What is it?

Inserting untrusted HTML lets attackers run their own scripts in your visitors' browsers.

Why does it matter?

"They can steal logins or impersonate users."

Good Example:
<p>{userText}</p> // React escapes this for you
Read more:

CORS

What is it?

CORS decides which websites may talk to your server from a browser.

Why does it matter?

"'*' means every website, including malicious ones."

Good Example:
cors({ origin: 'https://your-site.com' })
Read more:

The N+1 problem

What is it?

One request per item is slow: 100 items means 100 round trips.

Why does it matter?

"Pages get slower as your data grows, and hosting costs rise."

Good Example:
const rows = await db.from('items').select().in('id', ids); // one request

Handling errors

What is it?

Catch errors, then report them and tell the user something helpful.

Why does it matter?

"Silent failures hide bugs until customers complain."

Good Example:
catch (err) { report(err); showMessage('Something went wrong'); }

Rate Limiting

What is it?

Rate limiting restricts how many requests one person can make in a short time.

Why does it matter?

"Without it, attackers can overload your server (DoS), brute-force passwords, or rack up your cloud bill."

Good Example:
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 })); // 100 requests per 15 minutes

Information Exposure

What is it?

Console.log or debug messages often contain sensitive data or internal application details.

Why does it matter?

"Attackers can read the browser console. Leaving logs in production exposes information that helps them plan an attack."

Good Example:
logger.info('User logged in'); // only goes to server logs, not the browser

HTTPS Enforcement

What is it?

HTTP sends data in plain text, meaning anyone on the network (like public Wi-Fi) can read it.

Why does it matter?

"HTTPS encrypts the data so only the user and your server can see it."

Good Example:
fetch('https://api.example.com/data')

Input Validation

What is it?

Validating input means checking that the user's data is the right type, format, and length before using it.

Why does it matter?

"Too-long input can crash your server or database, and unvalidated input leads to almost every major security flaw."

Good Example:
const parsed = z.string().max(200).parse(input); // using Zod to enforce a max length

Authentication and Authorization

What is it?

Authentication verifies who the user is, and authorization checks if they are allowed to do that action.

Why does it matter?

"Without these checks, any visitor can delete data, change passwords, or access private pages."

Good Example:
if (!user || user.role !== 'admin') throw new Error('Unauthorized');