Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit 2bb4b30

Browse files
wa0x6eclaude
andcommitted
fix: ensure alias address can only be linked to a single parent address
Adds a check that rejects alias creation if the alias address is already associated with a different parent address, preventing one alias from acting on behalf of multiple addresses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5e4e3e5 commit 2bb4b30

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/writer/alias.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ export async function verify(message): Promise<any> {
1010
log.warn(`[writer] Wrong alias format ${JSON.stringify(schemaIsValid)}`);
1111
return Promise.reject('wrong alias format');
1212
}
13-
if (message.address === msg.payload.alias) {
13+
if (message.address.toLowerCase() === msg.payload.alias.toLowerCase()) {
1414
return Promise.reject('alias cannot be the same as the address');
1515
}
1616

17-
const existing = await db.queryAsync(
18-
'SELECT 1 FROM aliases WHERE address = ? AND alias = ? LIMIT 1',
19-
[message.address, msg.payload.alias]
20-
);
21-
if (existing.length > 0) {
22-
return Promise.reject('alias already exists');
17+
const results = await db.queryAsync('SELECT address FROM aliases WHERE alias = ?', [
18+
msg.payload.alias
19+
]);
20+
for (const row of results) {
21+
if (row.address.toLowerCase() === message.address.toLowerCase()) {
22+
return Promise.reject('alias already exists');
23+
}
24+
}
25+
if (results.length > 0) {
26+
return Promise.reject('alias is already linked to another address');
2327
}
2428

2529
return true;

test/integration/helpers/alias.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ describe('alias', () => {
4141
).rejects.toMatch('alias already exists');
4242
});
4343

44+
it('should reject when alias is already linked to another address', async () => {
45+
const alias = aliasesSqlFixtures[0].alias;
46+
const differentAddress = '0x0000000000000000000000000000000000000099';
47+
const msg = {
48+
version: '0.1.4',
49+
timestamp: Math.floor(Date.now() / 1000),
50+
type: 'alias',
51+
from: differentAddress,
52+
payload: { alias }
53+
};
54+
55+
await expect(
56+
verify({ address: differentAddress, from: differentAddress, msg: JSON.stringify(msg) })
57+
).rejects.toMatch('alias is already linked to another address');
58+
});
59+
4460
it('should pass when alias does not exist', async () => {
4561
const msg = {
4662
version: '0.1.4',

0 commit comments

Comments
 (0)