Team Ai
Apppublic

Lahiru-LK/codebert-vulnerability-api

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
README.md84 linesDownload Raw Back to root
1---2title: CodeBERT Vulnerability Detection3emoji: ๐Ÿ”’4colorFrom: red5colorTo: pink6sdk: docker7pinned: false8---9 10# CodeBERT Vulnerability Detection API11 12FastAPI-based code vulnerability detection using CodeBERT model trained for identifying SQL Injection and Certificate Validation vulnerabilities.13 14## ๐Ÿš€ API Endpoints15 16- **GET /** - API information17- **GET /health** - Health check status18- **GET /docs** - Interactive API documentation (Swagger UI)19- **POST /detect** - Detect vulnerabilities in code20 21## ๐Ÿ“ Example Usage22 23### Python24```python25import requests26 27url = "https://your-username-codebert-vulnerability-api.hf.space/detect"28 29response = requests.post(url, json={30    "code": """31    String query = "SELECT * FROM users WHERE id = '" + userId + "'";32    Statement stmt = connection.createStatement();33    ResultSet rs = stmt.executeQuery(query);34    """,35    "max_length": 51236})37 38result = response.json()39print(f"Vulnerable: {result['is_vulnerable']}")40print(f"Type: {result['vulnerability_type']}")41print(f"Confidence: {result['confidence']:.2%}")42```43 44### cURL45```bash46curl -X POST "https://your-username-codebert-vulnerability-api.hf.space/detect" \47  -H "Content-Type: application/json" \48  -d '{49    "code": "SELECT * FROM users WHERE id = " + user_input,50    "max_length": 51251  }'52```53 54## ๐Ÿ” Response Format55 56```json57{58  "vulnerability_type": "SQL Injection",59  "confidence": 0.95,60  "is_vulnerable": true,61  "label": "s0"62}63```64 65## ๐Ÿท๏ธ Vulnerability Labels66 67- **s0** / **s1** - SQL Injection vulnerabilities68- **v0** / **v1** - Certificate Validation vulnerabilities69 70## ๐Ÿง  Model Details71 72- **Base Model:** microsoft/codebert-base73- **Architecture:** RoBERTa with custom classification head74- **Model Size:** 487 MB75- **Task:** Binary classification for vulnerability detection76- **Categories:** SQL Injection, Certificate Validation77 78## โšก Performance79 80The model uses CPU inference on Hugging Face Spaces free tier. For faster inference, consider upgrading to GPU hardware.81 82## ๐Ÿ“„ License83 84Apache 2.0