Skip to content

Commit

Permalink
feat(security): prefix argos token by "argos_"
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Dec 30, 2024
1 parent e0423f0 commit cb719a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion apps/backend/src/database/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ export class Project extends Model {
return false;
}

/**
* Generate a new token for the project.
*/
static async generateToken() {
return generateRandomHexString();
const token = await generateRandomHexString(34);
return `argos_${token}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/database/models/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class Team extends Model {

async $getInviteLink() {
if (!this.inviteSecret) {
this.inviteSecret = await generateRandomHexString();
this.inviteSecret = await generateRandomHexString(20);
await Team.query()
.findById(this.id)
.patch({ inviteSecret: this.inviteSecret });
Expand Down
9 changes: 6 additions & 3 deletions apps/backend/src/database/services/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { promisify } from "node:util";

const generateRandomBytes = promisify(randomBytes);

export const generateRandomHexString = async () => {
const token = await generateRandomBytes(20);
/**
* Generates a random hex string of the given length.
*/
export async function generateRandomHexString(length: number): Promise<string> {
const token = await generateRandomBytes(length / 2);
return token.toString("hex");
};
}

0 comments on commit cb719a5

Please sign in to comment.