xypriss-security
Version:
XyPriss Security is an advanced JavaScript security library designed for enterprise applications. It provides military-grade encryption, secure data structures, quantum-resistant cryptography, and comprehensive security utilities for modern web applicatio
51 lines (47 loc) • 1.51 kB
JavaScript
'use strict';
var patterns = require('./patterns.js');
/**
* Function to test input against all patterns
* @example
* const testInput = "'; DROP TABLE users; --";
const result = detectInjection(testInput);
console.log(result);
// Output: { sql: true, xss: false, type: 'sql', matches: [...] }
*/
function detectInjection(input, patternType = "all") {
const results = {
sql: false,
xss: false,
type: null,
matches: [],
};
if (patternType === "all" || patternType === "sql") {
for (const pattern of patterns.sqlPatterns) {
if (pattern.test(input)) {
results.sql = true;
results.type = "sql";
results.matches.push({
type: "SQL",
pattern: pattern.toString(),
match: input.match(pattern),
});
}
}
}
if (patternType === "all" || patternType === "xss") {
for (const pattern of patterns.xssPatterns) {
if (pattern.test(input)) {
results.xss = true;
results.type = results.type ? "mixed" : "xss";
results.matches.push({
type: "XSS",
pattern: pattern.toString(),
match: input.match(pattern),
});
}
}
}
return results;
}
exports.detectInjection = detectInjection;
//# sourceMappingURL=detectInjection.js.map