Kotlin Multiplatform library providing bindings for the Gitleaks secret detection engine.
Note: This library is a Kotlin wrapper around the original Gitleaks project. For the original Go-based CLI tool and documentation, please visit the official Gitleaks repository.
angryscan-gitleaks provides Kotlin Multiplatform bindings over the Go libgitleaks shared library. It implements the IMatcher interface from org.angryscan:core, allowing you to use Gitleaks' powerful secret detection capabilities in your Kotlin/JVM applications.
The library uses JNA (Java Native Access) to load and interact with the native libgitleaks shared library, which is built from the Go source code in this repository.
- Kotlin Multiplatform Support: Currently supports JVM target (Native targets coming soon)
- Default and Custom Configurations: Use Gitleaks' default detection rules or provide your own TOML configuration
- Seamless Integration: Implements
org.angryscan:coreIMatcherinterface for easy integration - Cross-Platform Native Libraries: Bundled native libraries for Windows, Linux, and macOS (x86-64 and ARM64)
dependencies {
implementation("org.angryscan:gitleaks:0.1.0")
}dependencies {
implementation 'org.angryscan:gitleaks:0.1.0'
}<dependency>
<groupId>org.angryscan</groupId>
<artifactId>gitleaks</artifactId>
<version>0.1.0</version>
</dependency>import org.angryscan.gitleaks.matcher.GitleaksMatcher
// Initialize the matcher with default Gitleaks configuration
GitleaksMatcher.init(useDefaultConfig = true)
try {
// Scan text for secrets
val text = "GITHUB_TOKEN=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"
val matches = GitleaksMatcher.scan(text)
matches.forEach { match ->
println("Found secret: ${match.value}")
println("Position: ${match.startPosition}-${match.endPosition}")
println("Context: ...${match.before}${match.value}${match.after}...")
}
} finally {
// Clean up resources
GitleaksMatcher.close()
}import org.angryscan.gitleaks.matcher.GitleaksMatcher
// Define custom detection rules
val customConfig = """
[[rules]]
id = 'custom-api-key'
description = 'Custom API Key Pattern'
regex = '''api_key_[A-Z0-9]{32}'''
""".trimIndent()
// Initialize with custom configuration
GitleaksMatcher.init(useDefaultConfig = false, configToml = customConfig)
try {
val text = "api_key_ABCD1234EFGH5678IJKL9012MNOP3456"
val matches = GitleaksMatcher.scan(text)
// Process matches...
} finally {
GitleaksMatcher.close()
}import org.angryscan.common.engine.IMatcher
import org.angryscan.gitleaks.matcher.GitleaksMatcher
// GitleaksMatcher implements IMatcher from org.angryscan:core
val matcher: IMatcher = GitleaksMatcher
// Initialize before use
GitleaksMatcher.init(useDefaultConfig = true)
try {
// Use with angryscan-core engine
val matches = matcher.scan("Your text to scan here")
// Process matches...
} finally {
GitleaksMatcher.close()
}- Java: JDK 8 or higher
- Native Libraries: The library includes bundled native libraries for supported platforms. For custom builds, you may need to build the native
libgitleakslibrary from the Go source code.
To build the library from source:
-
Build the native library (required):
# For your platform bash build-scripts/build-linux.sh # Linux bash build-scripts/build-windows.sh # Windows bash build-scripts/build-darwin.sh # macOS # Or build all platforms bash build-scripts/build-all.sh
-
Build the Kotlin library:
cd kotlin ./gradlew build -
Run tests:
cd kotlin ./gradlew test
The library follows this high-level architecture:
- Native Library: The Go
libgitleaksshared library (libgitleaks.so/.dll/.dylib) provides the core detection engine - JNA Bridge: JVM implementation uses JNA to load and call native functions
- Kotlin API:
GitleaksMatcherprovides a clean Kotlin API implementingIMatcher - Resource Bundling: Native libraries are bundled in JAR resources for cross-platform support
The library supports both default and custom Gitleaks configurations:
- Default Configuration: Uses Gitleaks' built-in detection rules for common secrets (API keys, tokens, passwords, etc.)
- Custom Configuration: Provide your own TOML configuration file with custom rules
For more information about Gitleaks configuration format, see the official Gitleaks documentation.
This project is licensed under the MIT License. See the LICENSE file for details.
- Gitleaks: The original Go-based secret detection tool
- angryscan-core: Core scanning engine interface
Contributions are welcome! Please feel free to submit a Pull Request.
For issues related to:
- This Kotlin library: Please open an issue in this repository
- Gitleaks detection engine: Please refer to the official Gitleaks repository