Learning Center
Understand why these issues matter and how to prevent them in the future.
Keeping secrets out of code
Secrets (API keys, passwords) should live outside your code, in environment variables.
"Code gets copied, shared and pushed to GitHub. A key in code is a key in public."
const key = process.env.STRIPE_KEY; // set it in your host's settingsSQL injection
Attackers type database commands into forms. If you paste that text into a query, the database runs them.
"It can expose or erase every record you have."
db.query('SELECT * FROM users WHERE id = $1', [id]) // the value can never become a commandStoring passwords safely
Never store the password itself. Store a one-way scramble (a hash) and compare scrambles.
"If your database leaks, hashed passwords are useless to thieves; plain ones are not."
const ok = await bcrypt.compare(input, user.passwordHash);Why eval is dangerous
eval runs any text as code.
"If a user can influence that text, they control your app."
const data = JSON.parse(text); // reads data without running itCross-site scripting (XSS)
Inserting untrusted HTML lets attackers run their own scripts in your visitors' browsers.
"They can steal logins or impersonate users."
<p>{userText}</p> // React escapes this for youCORS
CORS decides which websites may talk to your server from a browser.
"'*' means every website, including malicious ones."
cors({ origin: 'https://your-site.com' })The N+1 problem
One request per item is slow: 100 items means 100 round trips.
"Pages get slower as your data grows, and hosting costs rise."
const rows = await db.from('items').select().in('id', ids); // one requestHandling errors
Catch errors, then report them and tell the user something helpful.
"Silent failures hide bugs until customers complain."
catch (err) { report(err); showMessage('Something went wrong'); }Rate Limiting
Rate limiting restricts how many requests one person can make in a short time.
"Without it, attackers can overload your server (DoS), brute-force passwords, or rack up your cloud bill."
app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 })); // 100 requests per 15 minutesInformation Exposure
Console.log or debug messages often contain sensitive data or internal application details.
"Attackers can read the browser console. Leaving logs in production exposes information that helps them plan an attack."
logger.info('User logged in'); // only goes to server logs, not the browserHTTPS Enforcement
HTTP sends data in plain text, meaning anyone on the network (like public Wi-Fi) can read it.
"HTTPS encrypts the data so only the user and your server can see it."
fetch('https://api.example.com/data')Input Validation
Validating input means checking that the user's data is the right type, format, and length before using it.
"Too-long input can crash your server or database, and unvalidated input leads to almost every major security flaw."
const parsed = z.string().max(200).parse(input); // using Zod to enforce a max lengthAuthentication and Authorization
Authentication verifies who the user is, and authorization checks if they are allowed to do that action.
"Without these checks, any visitor can delete data, change passwords, or access private pages."
if (!user || user.role !== 'admin') throw new Error('Unauthorized');