Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New multi-file app #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions multifile/javascript/DefEnsureJwtAlgo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import jwt from 'jsonwebtoken';

const SECRET = process.env.JWT_SECRET_KEY

function GenerateJWT(algo) {
const payload = {
Issuer: "server",
Subject: "Paz",
}
const token = jwt.sign(payload, SECRET, algo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM  Ensure Usage of JWT Algo
    Source File: UseEnsureJwtAlgo.js, Sink File: DefEnsureJwtAlgo.js | Checkov ID: CKV3_SAST_146

Data Flow

     UseEnsureJwtAlgo.js
     3 | let myInSecureAlgo = { algorithm: 'none' }
     UseEnsureJwtAlgo.js
     6 | GenerateJWT(myInSecureAlgo);
     DefEnsureJwtAlgo.js
    10 | const token = jwt.sign(payload, SECRET, algo);


Description

CWE: CWE-327: Use of a Broken or Risky Cryptographic Algorithm
OWASP: A02:2021-Cryptographic Failures

This policy detects the usage of JWT (JSON Web Token) with a non-secure algorithm.

Vulnerable code example:

const jwt = require('jsonwebtoken');

const payload = {
  user: 'admin',
  role: 'admin'
};

const token = jwt.sign(payload, 'secret', { algorithm: 'none' });

console.log(token);

In the above code, the algorithm option for JWT signing is set to 'none'. This means that the JWT token is not encrypted and can be easily tampered with or read by unauthorized parties.

return token
}


export default GenerateJWT;
12 changes: 12 additions & 0 deletions multifile/javascript/DefLoggingSensitiveInformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const AWS = require('aws-sdk');
const { Pool } = require('pg');
const sm = new AWS.SecretsManager({ region: 'us-west-2' });

function GetSecrets() {
const params = {
SecretId: process.env.DB_SECRET_NAME || 'aurora-pg-secret/bc-aurora-rdsv2-secret-rotation'
};
return sm.getSecretValue(params);
}

export default GetSecrets;
7 changes: 7 additions & 0 deletions multifile/javascript/UseEnsureJwtAlgo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import GenerateJWT from './DefEnsureJwtAlgo.js';

let myInSecureAlgo = { algorithm: 'none' }
let mySecureAlgo = { algorithm: 'sha254' }

GenerateJWT(myInSecureAlgo);
GenerateJWT(mySecureAlgo);
4 changes: 4 additions & 0 deletions multifile/javascript/UseLoggingSensitiveInformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import GetSecrets from './DefLoggingSensitiveInformation.js';

let retValue := GetSecrets();
console.log(retValue)