SSMS Copilot: Database Instructions Turn Read-Only Tools into SYSADMIN
Johann Rehberger tested Copilot, the AI query assistant in SQL Server Management Studio (SSMS), and made a database owner's stored instructions induce execution under another user's more privileged SQL connection. A regex-based read-only check failed to contain dynamic SQL, and the final demonstration added the attacker's login to sysadmin. Separate direct-prompt experiments sent table data over SMB; these are distinct demonstrations, not evidence of a single observed intrusion.
Threat Analysis
The attack crosses two boundaries. First, a database owner controls instructions that Copilot later reads as database metadata. Second, a supposedly read-only tool submits SQL using the victim's authenticated connection. An attacker with ALTER permission on one object can write its AGENTS.md property, but the final server-level escalation demonstration used db_owner control of the database constitution. Those privileges must not be reduced to an unauthenticated attack.
ReadFromDatabase classified SQL using regular expressions. Calling EXEC through a variable allowed dynamic SQL to evade that classifier. Copilot then executed with the connection's existing permissions. In the final test, that authority was sufficient to grant the attacker's login membership in sysadmin. Separately, directly prompted ReadFromDatabase and RestoreVerifyBackupFile tests demonstrated arbitrary SQL and table-row exfiltration through SMB. The flow preserves the backup demonstration separately rather than presenting exfiltration as a proven sequel to the escalation.
The vulnerability identifier CVE-2026-65669 covers SSMS 22.0 inclusive to 22.8.2 exclusive in Microsoft's record. Version 22.8.2 was released July 28; the CVE was published September 8. The research is controlled validation, not evidence of exploitation against an operational victim.
Microsoft documents agentExecuteAsUser in CONSTITUTION.md, implemented with EXECUTE AS. A missing IMPERSONATE grant fails execution, but an absent constitution reverts to the connected user. Because the threat includes an attacker who controls that metadata, this setting cannot be the sole boundary protecting an administrator connection.
Applicable AIDEFEND Defenses (5)
What Defenders Should Do Now
- Inventory the SSMS version actually launched. Upgrade affected installations to a supported fixed build, verify the running version, and repeat negative tests for the database and backup tool paths. Disable Copilot through managed controls on hosts awaiting remediation.
- Use a dedicated low-privilege SQL connection for Copilot. Test denied role grants, impersonation, dynamic SQL side effects and dangerous stored procedures with that exact principal; do not rely on the model's read-only statement.
- Review who can change database-wide CONSTITUTION.md and object-level AGENTS.md properties. Keep an owner-and-approved-content manifest of every database allowed to carry them, reconcile it against the live extended properties, and audit sp_addextendedproperty and sp_updateextendedproperty calls so a planted instruction is seen before the next administrator session. Keep the actual login low privilege even if agentExecuteAsUser is configured, and test behavior after metadata removal.
- Take sysadmin off the logins people use for everyday SSMS work. Route server-level elevation through PAM or just-in-time role assignment in a separate session with Copilot agent mode off, and recertify sysadmin and db_owner membership.
- Push Copilot settings centrally with group policy or Intune: turn off agent mode or Copilot where tool execution is not needed, and alert when a host drifts from the approved configuration.
- At the SQL Server host, restrict outbound SMB to the exact destinations needed by the service. Confirm the actual server route is blocked; restricting the desktop's browser traffic does not cover this path.
Conclusion
Last updated: