Skip to content

Commit d1b953b

Browse files
kakkokari-gtyihu1-liquid
authored andcommitted
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> (cherry picked from commit 3a6c2aa)
1 parent ed68245 commit d1b953b

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
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
@@ -164,13 +164,16 @@ export class ApPersonService implements OnModuleInit {
164164
}
165165

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

packages/backend/test/unit/activitypub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('ActivityPub', () => {
173173
resolver.register(actor.id, actor);
174174
resolver.register(post.id, post);
175175

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

178178
assert.deepStrictEqual(note?.uri, post.id);
179179
assert.deepStrictEqual(note.visibility, 'public');
@@ -333,7 +333,7 @@ describe('ActivityPub', () => {
333333
resolver.register(actor.featured, featured);
334334
resolver.register(firstNote.id, firstNote);
335335

336-
const note = await noteService.createNote(firstNote.id as string, resolver);
336+
const note = await noteService.createNote(firstNote.id as string, undefined, resolver);
337337
assert.strictEqual(note?.uri, firstNote.id);
338338
});
339339
});

0 commit comments

Comments
 (0)