Skip to content

Some new vulns shortname #11

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

Open
wants to merge 9 commits 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
3 changes: 1 addition & 2 deletions .github/workflows/codeql-monorepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ jobs:

# You must use the 'republish' step to republish the results of missing analyses from the target branch to the PR, to pass required checks.
# It will also copy these results to the target branch on merge, so that the full results are available in the target branch.

republish:
runs-on: ubuntu-latest
permissions:
Expand All @@ -103,6 +102,6 @@ jobs:
needs: changes
steps:
- name: Republish results
uses: advanced-security/monorepo-code-scanning-action/republish-sarif@main
uses: advanced-security/monorepo-code-scanning-action/republish-sarif@republish-gt-20
with:
projects: ${{ needs.changes.outputs.projects }}
7 changes: 7 additions & 0 deletions packages/babel-cli/src/babel/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
fs.writeFileSync(filePath, data);
}

function insecurePassword(): string {
// BAD: the random suffix is not cryptographically secure
const suffix = Math.random();
const password = "myPassword" + suffix;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix

AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate a secure random suffix. This will ensure that the generated password is not easily predictable.

  • Import the crypto module at the beginning of the file.
  • Replace the Math.random() call with crypto.randomBytes to generate a secure random suffix.
  • Convert the random bytes to a suitable format for appending to the password string.
Suggested changeset 1
packages/babel-cli/src/babel/dir.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/babel-cli/src/babel/dir.ts b/packages/babel-cli/src/babel/dir.ts
--- a/packages/babel-cli/src/babel/dir.ts
+++ b/packages/babel-cli/src/babel/dir.ts
@@ -3,2 +3,3 @@
 import fs from "fs";
+import crypto from "crypto";
 
@@ -21,4 +22,4 @@
 function insecurePassword(): string {
-  // BAD: the random suffix is not cryptographically secure
-  const suffix = Math.random();
+  // GOOD: the random suffix is cryptographically secure
+  const suffix = crypto.randomBytes(4).toString('hex');
   const password = "myPassword" + suffix;
EOF
@@ -3,2 +3,3 @@
import fs from "fs";
import crypto from "crypto";

@@ -21,4 +22,4 @@
function insecurePassword(): string {
// BAD: the random suffix is not cryptographically secure
const suffix = Math.random();
// GOOD: the random suffix is cryptographically secure
const suffix = crypto.randomBytes(4).toString('hex');
const password = "myPassword" + suffix;
Copilot is powered by AI and may make mistakes. Always verify output.
return password;
}

export default async function ({
cliOptions,
babelOptions,
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
}
}

function insecurePassword(): string {
// BAD: the random suffix is not cryptographically secure
const suffix = Math.random();
const password = "myPassword" + suffix;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix

AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In a Node.js environment, we can use the crypto module's randomBytes method to generate secure random values. We will convert these bytes to a number to append to the password.

Specifically, we will:

  1. Import the crypto module.
  2. Replace the Math.random() call with a call to crypto.randomBytes.
  3. Convert the random bytes to a number suitable for appending to the password.
Suggested changeset 1
packages/babel-helpers/src/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/babel-helpers/src/index.ts b/packages/babel-helpers/src/index.ts
--- a/packages/babel-helpers/src/index.ts
+++ b/packages/babel-helpers/src/index.ts
@@ -4,2 +4,3 @@
 import type { HelperMetadata } from "./helpers-generated.ts";
+import { randomBytes } from "crypto";
 
@@ -27,4 +28,4 @@
 function insecurePassword(): string {
-  // BAD: the random suffix is not cryptographically secure
-  const suffix = Math.random();
+  // GOOD: the random suffix is cryptographically secure
+  const suffix = randomBytes(4).readUInt32BE(0);
   const password = "myPassword" + suffix;
EOF
@@ -4,2 +4,3 @@
import type { HelperMetadata } from "./helpers-generated.ts";
import { randomBytes } from "crypto";

@@ -27,4 +28,4 @@
function insecurePassword(): string {
// BAD: the random suffix is not cryptographically secure
const suffix = Math.random();
// GOOD: the random suffix is cryptographically secure
const suffix = randomBytes(4).readUInt32BE(0);
const password = "myPassword" + suffix;
Copilot is powered by AI and may make mistakes. Always verify output.
return password;
}

type AdjustAst = (
ast: t.Program,
exportName: string,
Expand Down
Loading