Writing custom static analysis rules has historically felt like writing a mini-compiler. If your application security team wanted to enforce an internal security policy—such as blocking direct calls to an unapproved cryptography library or catching missing tenant validation middleware—you had to write abstract syntax tree (AST) matchers, fiddle with Datalog queries, or wrestle with brittle regular expressions.
Snyk DeepCode AI approaches this problem differently. Through DeepCode AI Search, it translates natural language queries into semantic code queries, allowing security engineers to define compliance patterns in plain English. At 365Finds, we analyzed how this pipeline translates conversational prompts into deterministic AST searches, how engineers can build and tune custom rules, and where the practical limits lie.
How Snyk DeepCode AI Processes Natural Language into Code Rules
The core engine of Snyk DeepCode AI relies on a hybrid AI architecture. It does not simply feed your proprietary codebase into an off-the-shelf generative model. Instead, it pairs generative parsing with deterministic symbolic analysis:
- Intent Translation via Generative AI: When a security engineer types a query like "Find unescaped user input passed directly into internal RPC logging without passing through our maskPII sanitizer", the generative layer interprets the linguistic components. It identifies the target programming language, candidates for data sources (user inputs), sinks (logging sinks), and required intermediary transformations (sanitizers).
- Semantic Graph Mapping (Symbolic AI): Snyk DeepCode AI does not run lexical string searches. It builds code representation graphs—combining Abstract Syntax Trees (ASTs), Control Flow Graphs (CFGs), and Data Flow Graphs (DFGs). The generative translation maps onto these symbolic graphs to trace whether data actually flows from a source to a sink across method boundaries and module imports.
- Deterministic Verification: Because symbolic engines govern the code graph traversal, the rule avoids generative hallucination. Either a reachable path exists in the code graph, or it does not.
- Custom Rule Packaging: Once the semantic search identifies the targeted pattern, DeepCode AI allows the engineer to persist that query as a permanent custom rule within Snyk Code, enforcing it continuously across IDEs and CI/CD pipelines.
Step-by-Step Guide: Creating Custom Rules with DeepCode AI Search
Step 1: Define the Security Invariant
Before typing a query, establish the exact tripartite pattern of your rule:
- Source: Where does untrusted or sensitive data originate? (e.g., HTTP request parameters, environment variables, deserialized payloads).
- Sanitizer / Guard: What function or validation makes the data safe? (e.g.,
validateSessionToken(),sanitizeInput()). - Sink: Where must tainted data never arrive uninspected? (e.g., database execution, raw HTTP responses, system logs).
Step 2: Formulate the Natural Language Query in DeepCode AI Search
Open the DeepCode AI Search interface within your Snyk workspace. Formulate a prompt that specifies the contextual constraints rather than generic keywords.
- Suboptimal prompt: "Find SQL injection in Node.js"
- Targeted prompt: "Find express route handlers where req.query or req.body flows into queryRaw() without executing sanitizeSqlIdentifier()"
DeepCode AI Search interprets the structural intent and displays matching code snippets across your selected repositories in real time.
Step 3: Inspect AST Matches and Validate Precision
Review the surfaced snippets. Check for:
- False positives: Did the query flag legitimate utility scripts or mock data in test directories?
- False negatives: Did variations in function aliases or framework wrappers bypass the search?
DeepCode AI provides interactive query refinement hints and autocomplete tokens. Adjust the query to restrict scopes (e.g., filtering out *.test.ts files or specifying exact package imports).
Step 4: Configure Severity and Remediation Guidance
Once the pattern matches expected violations, click Save as Custom Rule. Configure the rule metadata:
- Rule Identifier: A unique naming convention (e.g.,
CORP-SEC-004-LOG-INJECTION). - Severity Level: Assign
Critical,High,Medium, orLowbased on real exploitability in your deployment architecture. - Custom Remediation Advice: Provide developer-facing remediation instructions, including links to approved internal helper libraries.
Step 5: Automate Rule Enforcement in Snyk Code
After saving, Snyk Code automatically distributes the custom rule:
- Developer IDEs: Plugins for VS Code, IntelliJ, and Eclipse highlight matching violations in-line as engineers type.
- Pull Request Checks: Git integration blocks or annotates pull requests that introduce new instances of the pattern.
- CI/CD Pipelines: Automated
snyk code testruns enforce the policy during build stages.
Practical Implementation Examples
| Compliance Scenario | Natural Language Query Input | Semantic Detection Logic |
|---|---|---|
| Bypassed Tenant Isolation | "Find multi-tenant database queries where organizationId is not present in where clause" | Checks that database model calls under ctx.db enforce org_id parameter binding in the query scope. |
| Insecure Cryptographic Primitives | "Find uses of crypto.createHash with md5 or sha1 outside of test fixtures" | Detects legacy hash algorithm invocations within production source files while ignoring test files. |
| PII Leakage in Logging | "Find user.password or user.ssn passed to logger.info without passing through maskField" | Traces data flow of designated model properties to logging sinks without an intermediary sanitizer. |
365Finds Institutional Evaluation
At 365Finds, our assessment of Snyk DeepCode AI's natural language rule creation highlights significant productivity advantages alongside critical AppSec caveats:
- What 365Finds Recommends: For mid-to-large engineering teams struggling to get developers to comply with internal framework-specific standards, DeepCode AI Search removes the steep learning curve of compiler-based query languages. Writing effective static rules previously required specialized AppSec researchers; now, product security engineers can draft targeted compliance guards within minutes.
- Where Discretion Is Required: Natural language carries inherent semantic ambiguity. A query that feels precise in conversational English may miss obfuscated data flows or over-match generic variable names. 365Finds advises treating initial natural language queries as interactive drafting tools: always inspect the underlying code graph matches and run pilot evaluations against reference repositories before promoting any custom rule to a blocking CI gate.