Weak obfuscation of web requests makes your application vulnerable to unauthorized access. Using stronger obfuscation significantly reduces the chances of attacks due to unauthorized access.
1import jwt from "jsonwebtoken";
2function weakObfuscationOfRequestNoncompliant() {
3 // Noncompliant: secret is hardcoded.
4 const payload = "sss";
5 var secret = "secret";
6 jwt.sign(payload, secret);
7}
1import jwt from "jsonwebtoken";
2var payload: number;
3function weakObfuscationOfRequestCompliant() {
4 // Compliant: secret is properly loaded from environment variables.
5 var secret = process.env.JWT_TOKEN_SECRET;
6 jwt.sign(payload, secret);
7}