Skip to content

rebeccabas/js-code-vulnerability-detection-with-GraphCodeBERT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Vulnerability Detection

AI-powered security analysis using GraphCodeBERT with AST+DFG features

Detects SQL injection, XSS, command injection, and other vulnerabilities in JavaScript code through deep learning.


Performance

Accuracy Precision Recall F1 Score
79.21% 59.42% 88.40% 69.40%

Architecture

Pipeline: Code → Feature Extraction → GraphCodeBERT Encoder → Graph Reasoning → Classification

Model Architecture

How It Works

The model processes JavaScript code through 6 main layers:

Layer 0 - Data Processing

Layer 1 - Feature Extraction

  • AST (Abstract Syntax Tree): Captures code structure using Tree-sitter
  • DFG (Data Flow Graph): Tracks how data flows between variables

Layer 2 - GraphCodeBERT Encoder (125M parameters)

  • Pre-trained on 2.3M code samples with data flow awareness
  • 12 transformer layers process code tokens
  • Outputs contextualized embeddings that understand code semantics

Layer 3 - Graph Attention Network

  • 2 GAT layers use the adjacency matrix to reason about code structure
  • Learns which code relationships matter for security
  • Residual connections maintain information flow

Layer 4 - Multi-Modal Fusion

  • Combines learned code embeddings (768-dim)
  • With traditional code metrics (15 features: complexity, LOC, Halstead, etc.)
  • Creates rich 832-dimensional representation

Layer 5 - Classification

  • 3-layer neural network processes fused features
  • Outputs probability: Safe vs Vulnerable
  • Uses Focal Loss to handle class imbalance

( Currently working on balancing precision and recall for better performance)


About

Deep learning-based vulnerability detector for JavaScript code using GraphCodeBERT, Abstract Syntax Trees (AST), Data Flow Graphs (DFG), and Graph Attention Networks for automated static security analysis.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages