-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlScanner.ts
More file actions
22 lines (18 loc) · 846 Bytes
/
Copy pathsqlScanner.ts
File metadata and controls
22 lines (18 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import * as vscode from 'vscode';
export function checkSQLInjection(document: vscode.TextDocument, diagnosticCollection: vscode.DiagnosticCollection){
const text = document.getText();
const diagnostics: vscode.Diagnostic[] = [];
cons sqlPattern = /db\.execute\s*\(\s*["'].*["']\s*\+\s*[a-zA-Z0-9_]+\s*\)/g;
let match;
while((match = sqlPattern.exec(text)) !== null){
const startPos = document.positionAt(match.index);
const endPos = document.positionAt(match.index + match[0].length);
const diagnostic = new vscode.Diagnostic(
new vscode.Range(startPos, endPos),
"Güvenlik Uyarısı: SQL Injection riski String birleştirme yerine 'Parametrized Query' kullanmalısın",
vscode.DiagnosticSeverity.Error
);
diagnostic.push(diagnostic);
}
diagnosticCollection.set(document.uri, diagnostics);
}