Detecting GPL and AGPL Snippets in Cursor-Generated Code Before Merge
Dependency-based scanning reads manifests and declared packages, so it does not see copyleft code pasted inline into a source file. To detect GPL and AGPL code in AI-generated code, add snippet-level checks (matching, similarity or fingerprinting, and provenance metadata) at a pre-merge enforcement point. Define what happens on a match: allow, block, or escalate to a human reviewer. Retain a record of each detection and decision. Similarity matching is probabilistic and licence determination is not legal advice, so human review stays in the loop.
A pre-merge detection and escalation workflow
- 1
1. Scan the diff, not the repository
Run snippet matching and similarity checks on added and changed lines in each pull request. Flag files that were assistant-generated where that information is available.
- 2
2. Normalize and score matches
Record the matched source, its licence, the match type (exact or similar) and a similarity score for each hit.
- 3
3. Apply policy by licence and confidence
Strong matches to GPL or AGPL sources are blocked or escalated. Weak matches go to a lower-priority queue. Permissively licensed matches can be allowed with attribution.
- 4
4. Route to a named reviewer
Escalations go to a defined reviewer group, with engineering and legal roles separated. Consider two-person approval for the highest-risk cases, a pattern drawn from NIST code-signing guidance.
- 5
5. Resolve with a recorded outcome
The reviewer chooses to rewrite, remove, attribute, or accept, and records the reason. Confirmed false positives feed back into threshold tuning.
- 6
6. Retain the evidence
Store the match record, reviewer identity, decision and timestamp alongside the pull request, with a retention period set by your compliance team.
Criteria for evaluating snippet-level detection tooling
- Match coverage: does it match inline snippets in source files, or only declared dependencies? What corpus and licence data does it use, and is coverage disclosed?
- Match quality: does it handle renamed identifiers and restructured code, and how are similarity scores presented?
- False-positive handling: can reviewers dismiss, suppress or tune matches, and are those actions recorded?
- Enforcement points: can policy run in the assistant's execution path, in pre-commit, and in CI at pull request?
- Evidence retention: is the match, source, licence, reviewer and outcome retained per detection, with configurable retention?
- Deployment and data handling: can it run in your own environment, and what code leaves it during scanning?
Why dependency scanning leaves a gap
Software composition analysis (SCA) works from declared inputs: package manifests, lock files and build metadata. It maps those entries to known components and their licences. That model fits code that arrives as a dependency. It does not fit code that arrives as text.
When an AI coding assistant writes a function into a file, nothing is added to a manifest. The output carries no attribution and no licence signal. If that function reproduces or closely resembles copyleft-licensed code, including GPL or AGPL code, a manifest-based scan has nothing to match against. The code looks like first-party code, and it is reviewed as such.
This is a different control problem from dependency management. The question changes from "which packages do we ship?" to "where did this block of code come from?" Older NIST material on software security tooling describes this idea as pedigree analysis: tools that scan software within an organization and highlight its original source, so licensing concerns can be resolved against a known project name and version. The principle carries over to AI-generated code, although a pedigree tool built for whole components should not be assumed to catch inline snippets. Test that against your own samples.
Detection layers and where each fits
Four approaches are commonly combined. Each covers a different part of the workflow and each has limits.
Snippet matching compares code text, often after normalizing whitespace and identifiers, against an index of known open source code with licence data. It works well for near-verbatim copies. It is weaker when the assistant has renamed variables or restructured logic, and its coverage is only as broad as the index behind it.
Similarity analysis and fingerprinting reduce code to structural or token-level fingerprints and score how close two pieces of code are. This catches modified copies that exact matching misses. The cost is that results are probabilistic. A score is a signal for review, not a finding of infringement, and short or idiomatic code will produce false positives.
Provenance metadata records origin, licence and security context for code when it is generated or introduced, rather than reconstructing it later. This is the most useful input for audit, but it only helps where the metadata is actually captured. NIST's generative AI guidance material lists metadata embedding and cryptographic hashes among content provenance techniques, as general approaches rather than licence-specific controls.
Pre-merge checks are not a detection method in themselves. They are the enforcement point where the other three run, typically in pre-commit hooks or in CI on the pull request. Placing the check before merge matches the principle in NIST CSF 2.0 (ID.RA-09) that the authenticity and integrity of software is assessed prior to use. Pre-merge checks also catch code regardless of which assistant or editor produced it, which makes them a sensible baseline.
Policy decisions and the evidence behind them
Obligations attached to GPL and AGPL code can differ depending on whether software is distributed or made available to users over a network. Which of those cases applies depends on how each product is delivered. That is a legal determination, not an engineering one. Platform teams should ask counsel to state the rule per product or repository type, then encode it as policy. Treat the detection output as input to that decision and not as the decision itself.
The decision record matters as much as the detection. A defensible record answers a few questions: what was detected, against which source and licence, who reviewed it, what they decided, and when. NIST code-signing guidance also recommends keeping a reviewed list of who can submit and approve code, and separating administrators from authorized submitters. Applied by analogy, the same discipline works for licence escalations: a defined approver list, reviewed periodically, with no self-approval.
False positives need an owner. Periodically testing detection processes, as general cybersecurity guidance advises, applies here. Sample dismissed matches, check that thresholds still reflect reviewer judgment, and record changes to the rules.
Where Trussed fits
Pre-merge checks catch code at the pull request. Trussed addresses an earlier point: the interaction between a developer and a coding assistant. Trussed enforces policy in the execution path of coding assistants, with allow, redact, block, or escalate for human approval applied to individual interactions and tool calls. Enforcement happens at runtime, not in a review after the fact.
Trussed also provides code provenance: the origin, licence and security context of code. That context gives policy something to act on. A policy can, for example, block output tied to a copyleft licence or send it for human approval, rather than leaving the question to a later review.
Each enforcement decision produces audit-ready evidence, which is mapped to frameworks including HIPAA, NAIC, NYDFS, the EU AI Act and NIST. Deployment is self-managed in the customer cloud, with configurable retention and data residency. Trussed has run in continuous production in a regulated enterprise for more than 18 months, and serves customers in insurance, pharma, healthcare and education.
This does not replace CI-level checks. Scope is per interaction and tool call, so a pull request gate remains a useful second control. Used together, the two give a regulated enterprise one policy decision at generation time and another at merge, each with its own evidence.
Pre-merge copyleft detection path
Generate
A coding assistant such as Cursor produces code with no licence signal attached.
Detect
Snippet-level checks compare the code against known sources and licence data.
Decide
Policy routes each match to allow, block, or human approval.
Record
Match, reviewer and outcome are retained as evidence.
Put an enforcement point in front of assistant-generated code
Talk to an expert about enforcing policy on coding assistants and retaining audit-ready evidence of each decision.
Talk to an ExpertHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.