# Writing Detekt Security Rules for Kotlin

> Write custom detekt rules that catch framework-specific vulnerabilities: the five rule archetypes, precision without type resolution, three-layer tests, and the release cadence that stops bulk additions from hiding defects.

Writing Detekt Security Rules for Kotlin is a free AI agent skill on Agensi by Jasmin Guberinic, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Jasmin Guberinic](https://www.agensi.io/creators/jasmin-guberinic)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-19
- Security: scan passed (2026-10-19); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/writing-detekt-security-rules-for-kotlin
- Tags: code-review, kotlin, detekt, static-analysis, security, owasp

## About this skill

Generic scanners find hardcoded passwords. They do not find a @PreAuthorize on a
suspend fun — which Spring silently ignores, because coroutine desugaring creates
a state machine the proxy never instruments. The annotation compiles, reads as
protection, and the endpoint is unauthenticated.

That class of bug is framework-specific, invisible to bytecode analysis, and
exactly what a custom detekt rule is for.

This is the method behind a 216-rule ruleset across seven frameworks — including
the mistakes it made getting there.

· The doctrine: one false positive is worse than ten missing rules, because
suppression is not per-rule in practice — people disable the plugin, and your
accurate rules die with the noisy one
· Five archetypes that collapse most of the design decision
· The five files a rule touches, all of which fail silently if missed
· Precision without type resolution: exclude the constant case, check the
argument not the call, bail out when you cannot tell
· Three-layer tests, including the isolation test almost no ruleset has — a
different rule's positive fixture must be silent in yours, which is what
catches the over-broad predicate that quietly claims its neighbours' findings
· A shared SafeExamples file at zero findings, as a release blocker
· The cadence lesson: a push from 178 to 201 rules in large batches produced
roughly 45 defects found in a later audit. Bulk addition hides bugs.
· Scanning application.properties from a Kotlin visitor, with the per-file
instance trap and reporting at the config file's own line
· The near-misses that cost real credibility: DES matching DESede, auth
matching author, server.ssl matching server.ssl.enabled

Working Kotlin throughout, plus references on PSI patterns and their pitfalls,
testing, false positives, ruleset structure, and config-file scanning.

## Known limitations

Requires detekt. Does not support type resolution or cross-function dataflow analysis. Limited to single-file AST inspection without a full compilation context.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Writing Detekt Security Rules for Kotlin skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill differ from using the default detekt security ruleset?

This skill provides a structured methodology and boilerplate for creating high-precision security rules that target Kotlin-specific vulnerabilities, such as coroutine authentication gaps, which generic scanners often miss.

### Can these rules perform cross-file taint analysis or track variables across different functions?

No, this skill focuses on 'Syntax-based' analysis of the PSI tree to ensure high performance and zero false positives; it does not support cross-file dataflow or complex type resolution.

### Which AI agents or development environments are compatible with this skill?

The skill is designed for use with any LLM capable of processing Kotlin code (such as GPT-4, Claude 3.5, or specialized coding assistants) and requires a standard detekt environment for rule execution.

### What specific assets are included in the purchase?

You receive the 'Five-Archetype' framework, a standardized KDoc template for rule documentation, the 'Five-File' wiring checklist, and a specific testing strategy to prevent rule crosstalk.

### How does this skill help reduce the high number of false positives common in custom security rules?

By enforcing a 'Three-Layer' testing suite and a 'Precision Doctrine,' the skill ensures rules only trigger on high-confidence matches, preventing the noise that often leads teams to disable security plugins.

### Is this skill applicable to Java projects, or is it strictly for Kotlin?

While optimized for Kotlin and detekt, the underlying archetypes and testing logic can be adapted for other JVM-based static analysis tools like ArchUnit or Checkstyle with minor modifications.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
