Amazon Q Security Review Prompt Template
You get the real vulnerabilities in the code ranked by severity, each with how it could be exploited and a specific fix. This version is set up for Amazon Q: name the AWS services, regions and resources involved, and paste the relevant code or configuration. Below you'll find the prompt, how to run it in Amazon Q, a worked example and answers to common questions.
Do a security review of the code below. ## Context Language and framework: [e.g. Python, Flask] What this code does: [e.g. public endpoint that looks up a user by name] Who can reach it: [e.g. anyone on the internet, logged-in users only, internal only] Data it handles: [e.g. emails, payment info, none sensitive] ## Code [paste the code] ## Instructions - Check for injection, broken access control, exposed secrets, unsafe deserialization, missing input validation and sensitive data leaks. - For each finding, explain how an attacker would exploit it in one or two sentences. - Show the fixed code for each finding. - Do not list generic advice that does not apply to this code. - Say clearly if you cannot judge something without seeing more code (e.g. auth middleware). ## Output format Findings grouped as High, Medium, Low. Each with: issue, line, exploit, fix. Context - Reference material: [paste it below, or attach the file]
How to use this prompt
- 1
Open Amazon Q
Open Amazon Q in your IDE or the AWS console and paste the prompt.
- 2
Give it context
Name the AWS services, regions and resources involved, and paste the relevant code or configuration.
- 3
Review and iterate
Ask follow-ups in the same chat, and test changes in a non-production account first.
Working in Amazon Q
- •Amazon Q is built for AWS work, so name the services (for example Lambda, S3, IAM) your question involves.
- •Never paste credentials or secret values; describe the IAM setup instead.
- •For infrastructure changes, ask for the change as code (CloudFormation, CDK or Terraform) so you can review it.
Worked example
What you give it
Framework: Python, Flask, sqlite3
What it does: returns a user's id and email by name.
Who can reach it: anyone on the internet.
@app.route("/user")
def get_user():
name = request.args.get("name")
row = db.execute("SELECT id, email FROM users WHERE name = '" + name + "'").fetchone()
return {"id": row[0], "email": row[1]}What a good answer looks like (shortened)
High: SQL injection (the db.execute line)
Exploit: a request with name set to ' OR '1'='1 returns the first user, and crafted UNION payloads can read other tables.
Fix: use a parameterized query.
row = db.execute("SELECT id, email FROM users WHERE name = ?", (name,)).fetchone()
Medium: email exposed with no authentication
Exploit: anyone can collect user emails by guessing names.
Fix: require login and return email only to the account owner or an admin.
Low: unhandled missing user
If no row matches, row[0] raises and returns a 500 that may leak a stack trace in debug mode.
Fix: if row is None: return {"error": "not found"}, 404Tips for better results
- •Fill in "Who can reach it" and "Data it handles" honestly. They decide whether a finding is High or Low.
- •Paste the auth middleware or permission checks if they live elsewhere. Otherwise the AI will rightly flag access control as unknown.
- •Never paste credentials or secret values; describe the IAM setup instead.
- •Avoid this: Leaving out who can reach the code, so the AI cannot tell an internal admin script from a public endpoint.
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.
Variations
Threat model first
Add this line to Instructions: Before reviewing, list the three most likely attackers and what each would want from this code.
Dependency check
Add this section: ## Dependencies [paste package.json or requirements.txt] and flag packages that are commonly misconfigured or need pinning.
Checklist output
Change Output format to: A table with columns: check, pass or fail, line, fix.
Save it as a Retext snippet
Retext is a free text expander for Mac. Save this prompt once, then type ;secreview in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.
- Click Add to Retext. The prompt installs as a snippet with the trigger ;secreview.
- Change the trigger in Retext if you prefer a different one.
- Type the trigger wherever you want the prompt, then fill in the brackets.
Frequently asked questions
Is an AI security review enough before launch?
No. It is a useful first pass that catches common mistakes like injection and missing auth checks. Sensitive systems still need a dependency scan, a review by someone with security experience, and testing.
Is this prompt only for AWS projects?
Amazon Q is most useful when the work involves AWS services. The prompt still works for general code, but say what stack you use.
Is it safe to paste code into an AI for a security review?
Remove secrets, keys and customer data first, and follow your company's policy on sharing source code. The review works just as well with placeholder values.
How do I reuse this prompt without copying it every time?
Click Add to Retext to save it as a snippet. Then type ;secreview in any Mac app, including your AI tool, and the full prompt is pasted in.
Related Templates
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.