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

Crypto fix #72

Merged
merged 2 commits into from
Sep 8, 2023
Merged
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
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=MercuryWorkshop_anuraOS&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=MercuryWorkshop_anuraOS)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=MercuryWorkshop_anuraOS&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=MercuryWorkshop_anuraOS)

# Security Policy

## Supported Versions(Will be added in prod)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"typescript": "=5.0.4"
},
"devDependencies": {
"@types/node": "^20.4.2",
"@types/node": "^20.5.9",
"prettier": "^3.0.0"
}
}
12 changes: 11 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import basicAuth from "express-basic-auth";

import { readFileSync } from "fs";

import * as crypto from "crypto";

const useAuth = process.argv.includes("--auth");
const useParanoidAuth = process.argv.includes("--paranoid-auth");
// paranoid auth requests the user to send the server a passkey instead of a password, it's recommended to generate this passkey
Expand All @@ -26,6 +28,13 @@ spawn(
},
);

function cryptoRandom() {
const typedArray = new Uint8Array(1);
const randomValue = crypto.getRandomValues(typedArray)[0];
const randomFloat = randomValue / Math.pow(2, 8);
return randomFloat;
}

function shutdown() {
console.log();
// https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html
Expand Down Expand Up @@ -180,9 +189,10 @@ function sessionPassword(length: number) {
let counter = 0;
while (counter < length) {
result += characters.charAt(
Math.floor(Math.random() * charactersLength),
Math.floor(cryptoRandom() * charactersLength),
);
counter += 1;
}
console.log("The username for this session is: demouser");
return result;
}