Security Review of a Code Snippet: Ranked Findings With Exploit Path and Fix

Reviews pasted code for injection, broken authorization, secrets, SSRF and similar flaws, and returns only real findings ranked by severity, each with a one-line exploit path and fixed code.

You geta table with Severity (Critical, High, Medium, Low), Line, Issue, Exploit path, Fix. Under it, the fixed code for each Critical or High finding. End with what you could not check…

The prompt

Prompt
Act as an application security engineer reviewing code before it ships. Review the Python 3.11 / Flask 3.0 with Flask-Login session auth, sqlite3 (example value for {language and framework}) code below. If I have not said where its input comes from (public request, logged-in user, admin, internal job) and how users are authenticated, ask me in one short question first.

Check for: injection (SQL, command, template), missing authorization and IDOR, hardcoded secrets, SSRF, unsafe deserialization, path traversal, weak or misused crypto, risky dependencies, and personal data written to logs.

Rules:
1. Report only issues you can point to in this code. No generic advice such as "add rate limiting" unless the code shows the gap.
2. For each finding, give the exploit path in one sentence: who sends what, and what they get.
3. If a finding depends on code I did not paste, mark it "needs context" and say what you need to see.
4. If nothing serious is found, say so plainly instead of padding the list.

Output format: a table with Severity (Critical, High, Medium, Low), Line, Issue, Exploit path, Fix. Under it, the fixed code for each Critical or High finding. End with what you could not check from this snippet alone.

{paste the code}

Dashed parts are example values, so the prompt runs as copied. Change them in Fill in the blanks.

Example output

At a glanceSecurity findings by severitySix findings in one Flask invoice route, ranked by severity
Critical: SQL injection
1
f-string query on line 4
High: missing auth and IDOR
2
No login check, no ownership check
Medium: email in logs
1
Personal data written to logs
Low: error handling and SELECT *
2
Unhandled missing row, extra columns

Example for: a public Flask route behind Flask-Login session auth; users should only see their own invoices.

SeverityLineIssueExploit pathFix
Critical4SQL injection via f-stringAn unauthenticated attacker requests /invoice?id=0 UNION SELECT ... and reads arbitrary tables, including password hashes.Use a parameterized query with ? and cast id to int.
High1–2No authentication on the routeAnyone on the internet calls /invoice?id=1 without a session and receives a customer's invoice.Add @login_required.
High4, 6IDOR, with no ownership checkA logged-in user increments id from 1041 to 1042 and receives another customer's invoice, email included.Filter by owner_id = current_user.id and return 404 on no match.
Medium5Personal data (email) written to logsAnyone with log access, such as the support team or a log SaaS vendor, collects customer emails in bulk.Log the invoice ID and user ID only.
Low5–6Unhandled missing rowA request for a nonexistent ID makes row['email'] raise a TypeError, which returns a 500 and leaks a stack trace if debug is on.Return 404 when row is None.
Low6Returns every column (SELECT *)Any user who can view an invoice also receives internal columns such as stripe_customer_id (needs context: invoice table schema).Select and return only the fields you need.
Fixed code (Critical and High findings)
from flask import abort, jsonify, request
from flask_login import login_required, current_user

@app.route("/invoice")
@login_required                                   # High: authentication
def invoice():
    try:
        inv_id = int(request.args["id"])          # reject non-numeric input
    except (KeyError, ValueError):
        abort(400)

    row = db.execute(
        "SELECT id, number, amount_cents, currency, issued_at, email "
        "FROM invoices WHERE id = ? AND owner_id = ?",   # Critical: parameterized
        (inv_id, current_user.id),                        # High: ownership check
    ).fetchone()

    if row is None:
        abort(404)                                # avoids revealing that the ID exists

    log.info("invoice viewed", extra={"invoice_id": inv_id,
                                      "user_id": current_user.id})  # no email
    return jsonify(dict(row))
What I could not check from this snippet
  • db driver and placeholder style. ? fits sqlite3. psycopg uses %s and SQLAlchemy uses :id. I need to see how db is created.
  • Debug mode and error handlers. Whether a 500 response exposes tracebacks depends on app.debug and your global handlers.
  • Admin or support access. If staff need to view any invoice, show me how roles are stored so the ownership filter can allow an explicit exception.
  • Log destination and retention. These affect how serious the email-logging finding is.
Written by AI from this prompt. Your results will vary.

Paste a function, route handler or file into ChatGPT or Claude, or run it in Claude Code, Codex or Copilot chat with the file open. Say where the input comes from to get fewer 'needs context' rows.

Make it repeatable

Keep using this prompt without pasting it in every time.

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

Keep exploring

More in Coding
Coding

Pull Request Review with Merge Recommendation

Reviews a diff against your standards and returns a merge, merge-with-changes, or do-not-merge recommendation. Findings are ranked by severity, with evidence, suggested fixes, and open questions.