Skip to content

Commit 3a6c2aa

Browse files
fix(backend): fix type error(s) in security fixes (misskey-dev#15009)
* Fix type error in security fixes (cherry picked from commit fa3cf6c) * Fix error in test function calls (cherry picked from commit 1758f29) * Fix style error (cherry picked from commit 23c4aa2) * Fix another style error (cherry picked from commit 36af07a) * Fix `.punyHost` misuse (cherry picked from commit 6027b51) * attempt to fix test: make yaml valid --------- Co-authored-by: Julia Johannesen <julia@insertdomain.name>
1 parent 53e827b commit 3a6c2aa

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

packages/backend/src/core/HttpRequestService.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ class HttpRequestServiceAgent extends http.Agent {
5454
}
5555
});
5656
return socket;
57-
};
57+
}
5858

5959
@bindThis
6060
private isPrivateIp(ip: string): boolean {
6161
const parsedIp = ipaddr.parse(ip);
62-
62+
6363
for (const net of this.config.allowedPrivateNetworks ?? []) {
6464
const cidr = ipaddr.parseCIDR(net);
6565
if (cidr[0].kind() === parsedIp.kind() && parsedIp.match(ipaddr.parseCIDR(net))) {
6666
return false;
6767
}
6868
}
69-
69+
7070
return parsedIp.range() !== 'unicast';
7171
}
7272
}
@@ -93,19 +93,19 @@ class HttpsRequestServiceAgent extends https.Agent {
9393
}
9494
});
9595
return socket;
96-
};
96+
}
9797

9898
@bindThis
9999
private isPrivateIp(ip: string): boolean {
100100
const parsedIp = ipaddr.parse(ip);
101-
101+
102102
for (const net of this.config.allowedPrivateNetworks ?? []) {
103103
const cidr = ipaddr.parseCIDR(net);
104104
if (cidr[0].kind() === parsedIp.kind() && parsedIp.match(ipaddr.parseCIDR(net))) {
105105
return false;
106106
}
107107
}
108-
108+
109109
return parsedIp.range() !== 'unicast';
110110
}
111111
}

packages/backend/src/core/RemoteUserResolveService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class RemoteUserResolveService {
5454
}) as MiLocalUser;
5555
}
5656

57-
host = this.utilityService.punyHost(host);
57+
host = this.utilityService.toPuny(host);
5858

5959
if (host === this.utilityService.toPuny(this.config.host)) {
6060
this.logger.info(`return local user: ${usernameLower}`);

packages/backend/src/core/activitypub/models/ApPersonService.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,16 @@ export class ApPersonService implements OnModuleInit {
163163
}
164164

165165
for (const collection of ['outbox', 'followers', 'following'] as (keyof IActor)[]) {
166-
const collectionUri = getApId((x as IActor)[collection]);
167-
if (typeof collectionUri === 'string' && collectionUri.length > 0) {
168-
if (this.utilityService.punyHost(collectionUri) !== expectHost) {
169-
throw new Error(`invalid Actor: ${collection} has different host`);
166+
const xCollection = (x as IActor)[collection];
167+
if (xCollection != null) {
168+
const collectionUri = getApId(xCollection);
169+
if (typeof collectionUri === 'string' && collectionUri.length > 0) {
170+
if (this.utilityService.punyHost(collectionUri) !== expectHost) {
171+
throw new Error(`invalid Actor: ${collection} has different host`);
172+
}
173+
} else if (collectionUri != null) {
174+
throw new Error(`invalid Actor: wrong ${collection}`);
170175
}
171-
} else if (collectionUri != null) {
172-
throw new Error(`invalid Actor: wrong ${collection}`);
173176
}
174177
}
175178

packages/backend/test-federation/.config/example.default.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ proxyBypassHosts:
1919
- challenges.cloudflare.com
2020
proxyRemoteFiles: true
2121
signToActivityPubGet: true
22-
allowedPrivateNetworks: [
23-
'127.0.0.1/32',
24-
'172.20.0.0/16'
25-
]
22+
allowedPrivateNetworks:
23+
- 127.0.0.1/32
24+
- 172.20.0.0/16

packages/backend/test/unit/activitypub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('ActivityPub', () => {
176176
resolver.register(actor.id, actor);
177177
resolver.register(post.id, post);
178178

179-
const note = await noteService.createNote(post.id, resolver, true);
179+
const note = await noteService.createNote(post.id, undefined, resolver, true);
180180

181181
assert.deepStrictEqual(note?.uri, post.id);
182182
assert.deepStrictEqual(note.visibility, 'public');
@@ -336,7 +336,7 @@ describe('ActivityPub', () => {
336336
resolver.register(actor.featured, featured);
337337
resolver.register(firstNote.id, firstNote);
338338

339-
const note = await noteService.createNote(firstNote.id as string, resolver);
339+
const note = await noteService.createNote(firstNote.id as string, undefined, resolver);
340340
assert.strictEqual(note?.uri, firstNote.id);
341341
});
342342
});

0 commit comments

Comments
 (0)