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

Vulnerabilities Dashboard - JavaScript #409

Open
mantel-group-nullify bot opened this issue Nov 11, 2023 · 0 comments
Open

Vulnerabilities Dashboard - JavaScript #409

mantel-group-nullify bot opened this issue Nov 11, 2023 · 0 comments
Assignees

Comments

@mantel-group-nullify
Copy link

10 Potential vulnerability sources found in JavaScript files within this repo

⚠️ CRITICAL 🔴 HIGH 🔵 MEDIUM ⚪ LOW
0 0 10 0

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-327

Node insecure random generator

crypto.pseudoRandomBytes()/Math.random() is a cryptographically weak random number generator.

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-327

Node insecure random generator

crypto.pseudoRandomBytes()/Math.random() is a cryptographically weak random number generator.

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-185

Regex dos

Ensure that the regex used to compare with user supplied input is safe from regular expression denial of service.

var dir = path.dirname(file);
var match = /^\w+:\/\/[^\/]*/.exec(dir);

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-327

Node insecure random generator

crypto.pseudoRandomBytes()/Math.random() is a cryptographically weak random number generator.

return Math.round(low + (Math.random() * (high - low)));

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-770

Detect new buffer

The application was found calling the new Buffer constructor which has been deprecated
since Node 8.
By passing in a non-literal value, an adversary could allocate large amounts of memory.

Other issues also exist with the Buffer constructor:

  • Older versions would return uninitialized memory, which could contain sensitive information
  • Unable to easily determine what a Buffer contained if passed a non-literal value

To remediate this issue, use Buffer.alloc or Buffer.from instead to allocate a new
Buffer.

Example using Buffer.alloc instead of new Buffer(...):

// Create a new buffer using Buffer.from
const buf = Buffer.from([1, 2, 3, 4]);
// Work with buf

For more information on migrating to Buffer.from()/Buffer.alloc() see:

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-770

Detect new buffer

The application was found calling the new Buffer constructor which has been deprecated
since Node 8.
By passing in a non-literal value, an adversary could allocate large amounts of memory.

Other issues also exist with the Buffer constructor:

  • Older versions would return uninitialized memory, which could contain sensitive information
  • Unable to easily determine what a Buffer contained if passed a non-literal value

To remediate this issue, use Buffer.alloc or Buffer.from instead to allocate a new
Buffer.

Example using Buffer.alloc instead of new Buffer(...):

// Create a new buffer using Buffer.from
const buf = Buffer.from([1, 2, 3, 4]);
// Work with buf

For more information on migrating to Buffer.from()/Buffer.alloc() see:

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-185

Regex dos

Ensure that the regex used to compare with user supplied input is safe from regular expression denial of service.

var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
// The regex chunks
var brackets = /(\[[^[\]]*])/;
var child = /(\[[^[\]]*])/g;
// Get the parent
var segment = options.depth > 0 && brackets.exec(key);

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-327

Node insecure random generator

crypto.pseudoRandomBytes()/Math.random() is a cryptographically weak random number generator.

Math.round(Math.random() * 1e16) + Math.round(Math.random() * 1e16)

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-208

Detect possible timing attacks

The application was found executing string comparisons using one of ===, !==, == or !=
against security sensitive values. String comparisons like this are not constant time, meaning
the
first character found not to match in the two strings will immediately exit the conditional
statement.
This allows an adversary to calculate or observe small timing differences depending on the
strings
passed to this comparison. This potentially allows an adversary the ability to brute force a
string
that will match the expected value by monitoring different character values.

To remediate this issue, use the crypto.timingSafeEqual method when comparing strings.

Example using crypto.timingSafeEqual to safely compare strings:

function constantTimeIsPasswordEqual(userInput) {
    // Retrieve the password from a secure data store such as a KMS or Hashicorp's vault.
    const password = getPasswordFromSecureDataStore();
    // Use crypto timingSafeEqual to ensure the comparison is done in constant time.
    return crypto.timingSafeEqual(Buffer.from(userInput, 'utf-8'), Buffer.from(password,
'utf-8'));
}

For more information on constant time comparison see:

if (hash !== clientHash) {
// Increment failedRetrievaals counter, update lastFailedRetrievalAt data and send error to client
let incrementFailedRetrievals = 1;
if (failedRetrievals) {
incrementFailedRetrievals = failedRetrievals + 1;
}
const now = Date.now();
console.log(typeof(incrementfailedRetrievals));
console.log(typeof(now));
console.log(typeof(id));
const expiresAt = data.Item.expiresAt;
const x = {
TableName: process.env.tableName,
// 'Key' defines the key of the item to be retrieved
Key: {

Nullify Code - JavaScript 🔵 MEDIUM Severity CWE-208

Detect possible timing attacks

The application was found executing string comparisons using one of ===, !==, == or !=
against security sensitive values. String comparisons like this are not constant time, meaning
the
first character found not to match in the two strings will immediately exit the conditional
statement.
This allows an adversary to calculate or observe small timing differences depending on the
strings
passed to this comparison. This potentially allows an adversary the ability to brute force a
string
that will match the expected value by monitoring different character values.

To remediate this issue, use the crypto.timingSafeEqual method when comparing strings.

Example using crypto.timingSafeEqual to safely compare strings:

function constantTimeIsPasswordEqual(userInput) {
    // Retrieve the password from a secure data store such as a KMS or Hashicorp's vault.
    const password = getPasswordFromSecureDataStore();
    // Use crypto timingSafeEqual to ensure the comparison is done in constant time.
    return crypto.timingSafeEqual(Buffer.from(userInput, 'utf-8'), Buffer.from(password,
'utf-8'));
}

For more information on constant time comparison see:

if (token === clientToken) {
// Delete entry from parameter store prior to sending back to client
// Consider addng a counter or rate limit to prevent brute forcing
secret = data.Parameter.Value.slice(0,-36); // strip the last 36 characters (token)
message = "Token matched successfully";
//console.debug(`Debug: Client Token: ${clientToken}, Token: ${token}, Message: ${message}`);
}
else {
// Return an Error
err = true;
message = "Incorrect Token";
console.warn(`Token did not match, Client provided token: ${clientToken}`);
//console.debug(`Token did not match, Client Token: ${clientToken}, Token: ${token}, Message: ${message}`);
}

@mantel-group-nullify mantel-group-nullify bot pinned this issue Nov 11, 2023
@ciaran-finnegan ciaran-finnegan self-assigned this Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant