fix(server): the provided password must use unique value (#1506)

This commit is contained in:
Danil Shaymurzin ⚡️ 2024-02-13 01:05:07 +05:00 committed by GitHub
parent 9779f5dc5f
commit ceca3d617c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 0 deletions

View file

@ -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`
);
}
}

View file

@ -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) => {

View file

@ -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();