Secure Notes API
A FastAPI notes service built for a backend engineer technical evaluation, where the real deliverable was proving that one user can never see another user's data — and explaining why, in writing.
- Solo — API, tests, written security review
- Python · FastAPI · PostgreSQL · SQLAlchemy · Pydantic · python-jose (JWT) · Passlib · pytest
- Technical evaluation · runs locally

What it is
A REST API for storing personal notes: register, log in, create, read and update notes. I built it for a backend engineer technical evaluation, which came with a second part — a security review of a deliberately broken endpoint.
The feature list is small on purpose. The evaluation was really asking one question: can you build an API where user B can never touch user A's data, and can you prove it?
Ownership comes from the token
Every note query is filtered by the owner's ID at the database level. That ID comes from the verified JWT — never from the request body — so a client can't claim to be someone else by editing a field.
When user B asks for a note that belongs to user A, the API answers 404 Not Found, not 403 Forbidden. A 403 would confirm the note exists; a 404 gives an attacker nothing to probe.
Login returns the same "Invalid credentials" message for a wrong password and for an email that doesn't exist, so the endpoint can't be used to find out who has an account.
Passwords are hashed with pbkdf2_sha256 through Passlib, the JWT signing key is loaded from the environment rather than the source, and tokens expire after a configurable 30 minutes.
Proving isolation
14 tests, run with pytest against an in-memory SQLite database so they don't need PostgreSQL running:
- Authentication (6): registration, duplicate email, invalid email format, successful login, wrong password, nonexistent user
- Notes CRUD (5): create, list own notes, get by ID, partial update, unauthenticated access rejected
- Cross-user isolation (3): user B can't read user A's note by ID, user B's list doesn't include user A's notes, user B can't update user A's note
The last three are the point of the project. Each registers two real users, creates notes as A, and checks that every one of B's requests is refused.

The security review
The second part of the task was a search endpoint that built its SQL with an f-string, had no authentication and returned every column. I identified three problems and ranked them:
- SQL injection — critical. User input went straight into the query string.
- No authentication or ownership filter — high. Anyone could call it, and it returned every user's notes.
- Uncontrolled data exposure — medium.
SELECT *returned internal fields likeuser_id.
My rewrite binds the search term as a parameter, requires a valid token, scopes results to the caller, and selects only the fields the caller should see:
@app.get("/notes/search")
def search_notes(
q: str,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user)
):
query = text(
"SELECT id, title, content FROM notes "
"WHERE user_id = :uid AND title LIKE :pattern"
)
rows = db.execute(
query,
{"uid": current_user.id, "pattern": f"%{q}%"}
).fetchall()
return {"results": [dict(r._mapping) for r in rows]}
The review also covers stored XSS if notes were ever rendered as HTML, and why CSRF doesn't apply to an API that uses bearer tokens in a header — and when it would, if the token moved into a cookie.
I mapped the API's defences to three OWASP Top 10 categories: A01 Broken Access Control, A03 Injection and A07 Identification and Authentication Failures.
How I used AI
The README says exactly where AI helped — boilerplate, test scaffolding, a second opinion on the security review — and how I verified it: running every endpoint by hand in Swagger UI, running the full suite after each change, tracing the auth dependency chain line by line, and checking suggestions against the FastAPI and SQLAlchemy docs.
What's not in it
I listed these in the README rather than leaving a reviewer to find them:
- No DELETE endpoint — it wasn't in the requirements, and it would follow the same ownership check.
- No pagination on the notes list.
- No rate limiting on login.
- No refresh tokens.
- No HTTPS in development; production would need TLS termination.