Skip to content

Commit

Permalink
fix(server): the provided password must use unique value (Jigsaw-Code…
Browse files Browse the repository at this point in the history
  • Loading branch information
murka authored Feb 12, 2024
1 parent 9779f5d commit ceca3d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/shadowbox/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ export class AccessKeyConflict extends OutlineError {
super(`Access key "${accessKeyId}" conflict`);
}
}

export class PasswordConflict extends OutlineError {
constructor(accessKeyId?: AccessKeyId) {
super(
`Access key ${accessKeyId} has the same password. Please specify a unique password for each access key`
);
}
}
10 changes: 10 additions & 0 deletions src/shadowbox/server/server_access_key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ describe('ServerAccessKeyRepository', () => {
done();
});

it('createNewAccessKey throws on creating keys with existing passwords', async (done) => {
const repo = new RepoBuilder().build();
await repo.createNewAccessKey({password: 'P@$$w0rd'});
await expectAsyncThrow(
repo.createNewAccessKey.bind(repo, {password: 'P@$$w0rd'}),
errors.PasswordConflict
);
done();
});

it('New access keys have the correct default encryption method', (done) => {
const repo = new RepoBuilder().build();
repo.createNewAccessKey().then((accessKey) => {
Expand Down
9 changes: 9 additions & 0 deletions src/shadowbox/server/server_access_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ export class ServerAccessKeyRepository implements AccessKeyRepository {
} else {
id = this.generateId();
}

const isPasswordConflict = this.listAccessKeys().some(
(accessKey) => accessKey.proxyParams.password == params?.password
);

if (isPasswordConflict) {
throw new errors.PasswordConflict(id);
}

const metricsId = uuidv4();
const password = params?.password ?? generatePassword();

Expand Down

0 comments on commit ceca3d6

Please sign in to comment.