Abstract
The Java libraries JCA and JSSE offer cryptographic APIs to facilitate secure coding. When developers misuse some of the APIs, their code becomes vulnerable to cyber-attacks. To eliminate such vulnerabilities, people built tools to detect security-API misuses via pattern matching. However, most tools do not (1) fix misuses or (2) allow users to extend tools' pattern sets. To overcome both limitations, we created Seader—an example-based approach to detect and repair security-API misuses. Given an exemplar code pair, Seader compares the snippets to infer any API-misuse template and corresponding fixing edit. Based on the inferred info, given a program, Seader performs inter-procedural static analysis to search for security-API misuses and to propose customized fixes. For evaluation, we applied Seader to 28 code pairs; Seader successfully inferred 21 unique API-misuse templates and related fixes. With these patterns, we applied SEADER to a program benchmark that has 86 known vulnerabilities. Seader detected vulnerabilities with 95% precision, 72% recall, and 82% F-score. We also applied Seader to 100 open-source projects and manually checked 77 suggested repairs; 76 of the repairs were correct. Seader can help developers correctly use security APIs.
Introduction
Modern Java applications rely heavily on the Java Cryptography Architecture (JCA) and Java Secure Socket Extension (JSSE). However, these APIs are notoriously difficult to use correctly due to poor documentation and the high level of security expertise required. Developers often resort to "copy-pasting" insecure code from forums like StackOverflow, leading to vulnerabilities like hardcoded encryption keys or weak SSL protocols.
Existing tools for detecting these misuses suffer from two main flaws: Inextensibility and Lack of Repair. Most rely on hardcoded, "built-in" rules, making it difficult for users to add new patterns. Furthermore, many tools flag a problem but leave the developer guessing how to fix it. Seader addresses these gaps by providing an example-based framework that both detects and repairs vulnerabilities.
The Seader Framework
Seader operates in two distinct phases: Pattern Inference and Pattern Application. This workflow allows the tool to learn from a single pair of insecure and secure code snippets and then apply that knowledge to complex, real-world programs.
Phase I: Pattern Inference
In this phase, a security expert provides a single pair of code snippets: one showing the insecure usage ($I$) and one showing the secure fix ($S$).
- Change Recognition: Seader uses Abstract Syntax Tree (AST) differencing to identify exactly what changed (deletions, insertions, or updates) between the two snippets.
- Critical API Identification: It performs intra-procedural data-dependency analysis to find the "Critical API"—the specific security method call that is the root of the vulnerability.
- Abstraction: To make the pattern reusable, Seader replaces concrete variable names with abstract placeholders (e.g.,
$v_0$). It also uses "Stub Classes" (likeByteLiterals.CONSTANT_ARRAY) to represent abstract concepts that are hard to capture in plain Java, such as "any hardcoded byte array."
Phase II: Pattern Application
When Seader scans a new program ($P$):
- Inter-procedural Analysis: Unlike simpler tools that only look at a single method, Seader uses the WALA framework to perform backward slicing. This allows it to trace data flow across different methods and classes to see if a parameter (like a password) originated from an insecure source (like a hardcoded string).
- Customized Repair: If a match is found, Seader concretizes the abstract fix it learned in Phase I, tailoring variable names to fit the target program's context.
Key Results and Evaluation
The authors evaluated Seader using an inference dataset of 28 code pairs, a detection benchmark of 86 known vulnerabilities, and a repair dataset of 100 open-source projects.
- Detection Performance: On the 86-vulnerability benchmark, Seader achieved 95% precision and 72% recall (82% F-score), outperforming established tools like CogniCrypt, CryptoGuard, and FindSecBugs.
- Repair Accuracy: The authors manually inspected 77 repairs suggested by Seader in open-source projects; 76 out of 77 (99%) were correct.
- Efficiency: Seader analyzed the entire benchmark suite in just 262 seconds, proving it is performant enough for integration into CI/CD pipelines.
Conclusion
Seader demonstrates that a single, well-crafted example is often enough to generate a robust detection and repair template. By combining AST-based pattern inference with inter-procedural static analysis, it significantly lowers the barrier for security researchers to contribute new rules while providing developers with actionable, accurate code repairs.
Summary updated