Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Commit 357995e

Browse files
committed
fix(Processor): make sure to only accept 16 byte UUIDs
1 parent 725ff00 commit 357995e

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ In order to use the server, you have to implement a processor first. Following i
1717
you started:
1818

1919
```typescript
20+
import {randomUUID} from 'crypto';
21+
import uuidBuffer from 'uuid-buffer';
2022
import {
2123
AudioFoundResult,
2224
AudioNotFoundResult,
@@ -46,8 +48,8 @@ class MyProcessor implements Processor {
4648
if (hexUid === '00000000000002') {
4749
// This is a valid UID, return an array of achievement IDs, if any were achieved.
4850
return new ValidUidResult([
49-
Buffer.from('0000000000000000000000000000000000000001'),
50-
Buffer.from('0000000000000000000000000000000000000002'),
51+
uuidBuffer.toBuffer(randomUUID()),
52+
uuidBuffer.toBuffer(randomUUID()),
5153
]);
5254
}
5355

src/Processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export class ValidUidResult {
99
}
1010

1111
for (const achievementId of achievementIds) {
12-
if (achievementId.length !== 20) {
13-
throw new Error(`Length of achievement ID "${achievementId.toString('hex')}" is not 20 bytes`);
12+
if (achievementId.length !== 16) {
13+
throw new Error(`Length of achievement ID "${achievementId.toString('hex')}" is not 16 bytes`);
1414
}
1515
}
1616
}

test/authenticate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {TLSSocket} from 'tls';
22
import type BufferedStream from '../src/BufferedStream';
3-
import {AuthResponse} from '../src/client.js';
3+
import {AuthResponse} from '../src/client';
44
import {testServer} from './server-tester';
55

66
describe('Authenticate', () => {

test/check-uid.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe('CheckUid', () => {
3434
checkUid: async (clientId, uid) => {
3535
result = {clientId, uid};
3636
return Promise.resolve(new ValidUidResult([
37-
Buffer.from('0'.repeat(40), 'hex'),
38-
Buffer.from('1'.repeat(40), 'hex'),
37+
Buffer.from('0'.repeat(32), 'hex'),
38+
Buffer.from('1'.repeat(32), 'hex'),
3939
]));
4040
},
4141
}, async stream => {
@@ -48,11 +48,11 @@ describe('CheckUid', () => {
4848
const numAchievements = await stream.readUint8();
4949
expect(numAchievements).toBe(2);
5050

51-
const firstAchievement = await stream.readExact(20);
52-
const secondAchievement = await stream.readExact(20);
51+
const firstAchievement = await stream.readExact(16);
52+
const secondAchievement = await stream.readExact(16);
5353

54-
expect(firstAchievement).toEqual(Buffer.from('0'.repeat(40), 'hex'));
55-
expect(secondAchievement).toEqual(Buffer.from('1'.repeat(40), 'hex'));
54+
expect(firstAchievement).toEqual(Buffer.from('0'.repeat(32), 'hex'));
55+
expect(secondAchievement).toEqual(Buffer.from('1'.repeat(32), 'hex'));
5656
});
5757

5858
expect(result).toEqual({clientId: 'foo', uid: Buffer.from('0'.repeat(14), 'hex')});

test/processor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ describe('Processor', () => {
1414

1515
expect(() => {
1616
new ValidUidResult([id]);
17-
}).toThrow('Length of achievement ID "000000000000000000000000000000000000000000" is not 20 bytes');
17+
}).toThrow('Length of achievement ID "000000000000000000000000000000000000000000" is not 16 bytes');
1818
});
1919
});

0 commit comments

Comments
 (0)