Services
Service Routes Analysis
routes/service-routes.js
const router = express.Router();
router.use(verifyToken); // Requires authentication
router.post("/generate", generateQR);
module.exports = router;Key Observations:
Single endpoint:
POST /api/service/generateRequires authentication (
verifyTokenmiddleware)Calls
generateQRfunction
Service Controllers
controllers/service-controllers.js
Contains two functions:
validateString
Input validation
generateQR
QR code generation
generateQR Function
Data Flow
External Package: qrcode
Hovering over QRCode.toDataURL:
"Returns a Data URI containing a representation of the QR Code image"
Note: Testing external packages is usually outside whitebox scope, except for checking public vulnerabilities with npm audit.
validateString Function π¨
Validation Checks
typeof input !== "string"
Must be string type
input.length == 0
Cannot be empty
input.match(/['";]/g)`
Cannot contain ', ", `, ;
Regular Expression Analysis
Matches: Single quote, double quote, backtick, semicolon
Purpose: Filter against exploitation - block "bad characters" before QR generation.
The Vulnerability
Problem: onError is passed as a parameter and executed via eval()!
How It's Called
Parameters:
input=text(user-controlled via POST body)onError=throw new Error('Invalid input for role: ${role}')(containsrolefrom JWT)
Attack Vector Analysis
text
req.body.text
β Direct control
role
req.user.role
β οΈ From JWT token
Question: Can we control role in the JWT token?
Vulnerability Summary
validateString Issues
eval() usage
π΄ Critical
Executes arbitrary code
User input in eval
π΄ Critical
role ends up in eval
Blacklist filtering
π‘ Medium
Can potentially be bypassed
Attack Chain (Hypothesis)
Prioritization
Shortlisted Findings
eval(onError) in validateString
Code Injection
High
External packages
Public CVEs
Medium
Why High Priority?
eval()with partially user-controlled inputCould lead to Remote Code Execution (RCE)
Requires understanding of JWT token generation
External Package Audit
Check for known vulnerabilities in dependencies.
Next Steps
Local Testing - Set up environment
Trace role parameter - How is it generated?
Test JWT manipulation - Can we inject into role?
Bypass filters - Can we avoid
['";]` regex?Achieve code execution - Exploit eval
Key Takeaways
eval()is dangerous - Especially with user inputTrace all parameters - Even indirect ones (JWT claims)
Blacklists can be bypassed - Look for alternatives
Authentication β Safe - Authenticated endpoints can still be vulnerable
Small codebases - May have fewer findings, but can be critical
Last updated