Writing Security Requirements for AI Coding Prompts
Write AI coding prompts that state trust boundaries, permissions and failure behaviour. Include concrete security requirements and independent acceptance tests.
A useful AI coding prompt describes the security behaviour the application must preserve. “Make this secure” leaves the important decisions unstated: who may act, which data they may reach and what should happen when a check fails.
Treat the prompt as a brief for an implementation that still needs review. Clear requirements improve the starting point, but the resulting code and deployed behaviour provide the evidence.
Describe the trust boundary
Identify the actor, entry point, resource and external systems. State which values are trusted and where that trust is established. Distinguish authenticated session context from request parameters that a user can alter.
For example, a tenant identifier taken from an API body should not establish the caller's tenant membership. Explain how the application obtains the authoritative identity and what existing policy helpers must be used.
State positive and negative permissions
Describe allowed behaviour and the cases that must be refused. Include ordinary users, administrators, other tenants, suspended accounts and missing identities where relevant.
Specify whether a denied request should leave records unchanged, avoid sending messages or prevent a background job from being queued. These state requirements help reviewers catch controls applied after an irreversible side effect.
Give concrete implementation constraints
The following is an illustrative brief for a record endpoint:
Implement invoice retrieval using the existing authenticated session.
Use the established tenant-membership and read-invoice policy helpers.
Never trust owner, role or tenant values supplied by the client.
Use parameterised queries and return only the permitted response fields.
Refuse missing membership and cross-tenant records without disclosing data.
Preserve the application's existing error and audit conventions.
Add tests for permitted access, another tenant, suspended access and logout.
Explain assumptions and identify any requirement the patch cannot verify.
Adapt the brief to the actual application. Naming a helper that does not exist or requiring a mechanism incompatible with the architecture can lead to invented code or unsafe workarounds.
Include operational requirements
Specify timeouts, request limits, logging exclusions and safe failure behaviour when relevant. Describe how secrets are retrieved without providing their values. Identify integrations that must not be called during tests.
If the change affects deployment configuration, require the corresponding configuration review and rollback plan. Source changes alone may not enforce the control in a differently configured production environment.
Define acceptance evidence independently
| Requirement | Evidence to request |
|---|---|
| Tenant separation | Cross-tenant request tests with controlled records. |
| Limited updates | Protected fields remain unchanged after hostile input. |
| Secret handling | No credentials in source, errors or test artefacts. |
| Transaction safety | Failed operations preserve the intended business state. |
| Deployment | The assessed build and configuration are identified. |
Review whether the tests establish the requirement rather than merely repeating the implementation. Maintain the important cases as regression tests after the initial task.
Keep the human decision visible
Ask for a concise account of changed behaviour, assumptions and verification limits. Have an appropriate reviewer examine the diff and evidence before merging. For high-impact permission or transaction changes, include runtime assessment where the objective requires it.
Related resources
Read our testing methodology or discuss your assessment.