Counterweight Labs

Research

Security requirements for spec-driven development

Turn security requirements into enforceable behavior and negative tests before an AI coding agent starts implementation. A tenant-isolation example shows the full chain.

A security requirement connects to its enforcement boundary, a negative test, and evidence that the denied operation stays denied.
In this guide

A useful security specification names an actor, an operation, a resource, and the condition under which access must be denied. It also identifies where that rule is enforced and how someone will verify it. Give an AI coding agent those constraints before it proposes the implementation, then review the resulting code and tests against the same requirements.

GitHub's Spec Kit describes a workflow that refines intent and specifications before implementation. That structure provides a place to record security requirements. It does not supply missing requirements automatically, and its documentation is not evidence that adopting spec-driven development produces a particular reduction in vulnerabilities.Source: GitHub Spec Kit: spec-driven development

Write the denied behavior first

Consider an illustrative SaaS feature that lets a finance user download an invoice. A functional requirement might say that the user can download a PDF from the invoice page. That leaves the security decision unresolved: which invoices, for which users, through which interfaces?

For this example, define a rule that a user can download an invoice only when the user has invoice-read permission in the invoice's tenant. State that the rule applies to the browser flow, direct API access, and any export job that performs the same operation. Decide how support access works separately instead of assuming that an administrator label settles it.

Illustrative security acceptance criterion
Given a user authorized to read invoices in tenant A
And an invoice belonging to tenant B
When the user requests that invoice through any download path
Then the service returns no invoice content
And it creates no downloadable artifact for that user

The final line prevents an easy testing mistake: asserting that the HTTP response is denied while an asynchronous job still creates the export. Write requirements around the protected result, including side effects, rather than a particular error message.

Name the enforcement boundary

OWASP's authorization guidance recommends denying access by default, checking permissions on each request, and applying controls in the appropriate server-side location. In the invoice example, specify which trusted component establishes the user's identity and tenant membership, and which component checks access to the requested invoice.Source: OWASP authorization guidance

Do not leave the origin of tenant context implicit. A tenant identifier supplied by a client is a request for access, not proof of membership. Describe how the backend validates that selection and obtains the resource's tenant. If a job runs later, decide whether it rechecks permission at execution time and what happens when membership has changed.

Acceptance cases for the example invoice feature
Actor and requestExpected resultWhat to inspect
Tenant A reader, tenant A invoiceDownload succeedsCorrect invoice content
Tenant A reader, tenant B invoiceDownload deniedNo response content or export artifact
Tenant A member without read permissionDownload deniedPermission checked beyond membership
Removed member with a queued exportBehavior matches the revocation policyWorker revalidation and artifact access
Unauthenticated requestNo protected invoice accessAPI and storage download path
A reader with invoice permission in tenant A requests two resources. Its tenant A invoice is allowed; a tenant B invoice is denied without a downloadable artifact.
Illustrative acceptance cases for the invoice feature. Test both the legitimate read and the forbidden cross-tenant read, including any background export or downloadable artifact.

Review the tests independently

A generated test can encode the same mistaken assumption as generated code. Ask a reviewer to trace each acceptance case to the actual boundary being exercised. A unit test with a mocked authorization decision cannot show that the route calls authorization correctly. Keep a smaller number of integration tests that exercise the route, identity setup, resource ownership, and observable result together.

Include a legitimate success case alongside each restriction. Otherwise a test suite may pass because the feature denies all requests or fails before reaching the relevant decision. For an existing bug, confirm that the regression case detects the issue in the pre-fix version and passes with the correction. Preserve that evidence in the change review.

Keep the specification connected to changes

Attach stable requirement identifiers to the specification, implementation review, and test cases. When a feature adds bulk downloads or delegated access, review which existing requirements apply and which need refinement. Record deliberate exceptions with an owner and the behavior they permit. A specification that survives only as the first prompt will drift as the application evolves.

For the next feature review, ask the engineer to bring one normal workflow and one forbidden workflow, including the data they affect. Agree on the access decision and its evidence before discussing which library or agent will generate the code.

Sources

  1. GitHub Spec Kit: spec-driven development github.github.com
  2. OWASP authorization guidance cheatsheetseries.owasp.org

Bring a feature specification and the application boundaries it touches. We can review the security requirements, implementation, and evidence needed to ship it.

Explore application security
Book a consultation