Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
# 18.x is EOL and no longer satisfies the eslint 10.x devDependency's
# engines requirement (^20.19.0 || ^22.13.0 || >=24) introduced by
# this PR; test against the versions we actually support instead.
node-version: [20.x, 22.x, 24.x]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion backend/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const config = {

const env = process.env.NODE_ENV || 'development';

module.exports = config[env] || configs.development;
module.exports = config[env] || config.development;
24 changes: 2 additions & 22 deletions backend/middleware/adversarialGuard.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ function detectAdversarialPatterns(text) {
}
}

const normalizedScore = Math.min(score, 1.0);


// Normalize score
const normalizedScore = Math.min(score, 1.0);

// Check for extremely long text (potential DoS)

if (text.length > 10000) {
Expand All @@ -86,9 +83,6 @@ function detectAdversarialPatterns(text) {
};
}

function adversarialGuard(req, res, next) {
const text = req.body?.text || req.query?.text || '';

/**
* Middleware to check for adversarial patterns
*/
Expand All @@ -102,10 +96,6 @@ function adversarialGuard(req, res, next) {
return next();
}

const analysis = detectAdversarialPatterns(text);
req.adversarialAnalysis = analysis;


// Check for adversarial patterns
const analysis = detectAdversarialPatterns(text);
req.adversarialAnalysis = analysis;
Expand Down Expand Up @@ -145,14 +135,10 @@ function monitorConfidence(req, res, next) {
responseData = data;
}

if (responseData && typeof responseData === 'object') {
const confidence = responseData.confidence_score || responseData.confidence || 0;


// Check if it's a prediction response
if (responseData && typeof responseData === 'object') {
const confidence = responseData.confidence_score || responseData.confidence || 0;

// Add adversarial analysis

if (req.adversarialAnalysis) {
Expand All @@ -173,11 +159,6 @@ function monitorConfidence(req, res, next) {
console.log(`⚠️ [CONFIDENCE MONITOR] Low confidence prediction:`, {
confidence,
threshold: CONFIDENCE_THRESHOLD,
prediction: responseData.result || responseData.prediction
});
}


prediction: responseData.result || responseData.prediction,
textPreview: req.body?.text?.substring(0, 100)
});
Expand All @@ -195,7 +176,6 @@ function monitorConfidence(req, res, next) {
originalSend.call(this, jsonData);
return;
}
} catch (e) {}
} catch (e) {
// If parsing fails, just pass through
}
Expand Down
2 changes: 1 addition & 1 deletion backend/middleware/filevalidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function sanitizeCSVCell(value) {
let sanitized = value.replace(/</g, '&lt;').replace(/>/g, '&gt;');

// Neutralize formula injection: if starts with =, +, -, @, prefix with '
if (/^[=\+\-@]/.test(sanitized)) {
if (/^[=+\-@]/.test(sanitized)) {
sanitized = "'" + sanitized;
}

Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node server.js",
"dev": "nodemon server.js",
"worker": "node worker.js",
"test": "jest --testPathIgnorePatterns config --testPathIgnorePatterns avatarUpload --testPathIgnorePatterns keywordRules --testPathIgnorePatterns rateLimiter --testPathIgnorePatterns fileValidation && node --test tests/keywordRules.test.js tests/rateLimiter.test.js tests/avatarUpload.test.js tests/fileValidation.test.js",
"test": "jest --testPathIgnorePatterns config --testPathIgnorePatterns avatarUpload --testPathIgnorePatterns keywordRules --testPathIgnorePatterns rateLimiter --testPathIgnorePatterns fileValidation --testPathIgnorePatterns adminRuleEvaluator && node --test tests/keywordRules.test.js tests/rateLimiter.test.js tests/avatarUpload.test.js tests/adminRuleEvaluator.test.js",
"lint": "eslint ."
},
"keywords": [],
Expand Down
Loading
Loading