Skip to content

Commit

Permalink
Merge tag '10.102.699-m544' into custom/atsuchan
Browse files Browse the repository at this point in the history
10.102.699-m544
  • Loading branch information
atsu1125 committed May 1, 2024
2 parents cdf2b2d + c8e6c50 commit 531f1e0
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 105 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "misskey",
"author": "mei23 <m@m544.net>",
"version": "10.102.698-m544",
"version": "10.102.699-m544",
"codename": "m544",
"repository": {
"type": "git",
Expand Down Expand Up @@ -95,7 +95,7 @@
"jsdom": "20.0.3",
"json5": "2.2.3",
"json5-loader": "4.0.1",
"jsonld": "5.2.0",
"jsonld": "8.3.2",
"katex": "0.16.10",
"koa": "2.15.2",
"koa-bodyparser": "4.4.1",
Expand Down
133 changes: 73 additions & 60 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/queue/processors/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import resolveUser from '../../remote/resolve-user';
import config from '../../config';
import { publishInstanceModUpdated } from '../../services/server-event';
import { StatusError } from '../../misc/fetch';
import { FIXED_CONTEXT } from '../../remote/activitypub/misc/contexts';

const logger = new Logger('inbox');

Expand All @@ -37,7 +38,7 @@ type ApContext = {

export const tryProcessInbox = async (data: InboxJobData, ctx?: ApContext): Promise<string> => {
const signature = data.signature;
const activity = data.activity;
let activity = data.activity;

const resolver = ctx?.resolver || new Resolver();

Expand Down Expand Up @@ -111,6 +112,11 @@ export const tryProcessInbox = async (data: InboxJobData, ctx?: ApContext): Prom
return `skip: LD-Signatureの検証に失敗しました`;
}

const activity2 = JSON.parse(JSON.stringify(activity));
delete activity2.signature;
const compacted = await ldSignature.compact(activity2, FIXED_CONTEXT);
activity = compacted as any;

// もう一度actorチェック
if (user.uri !== activity.actor) {
return `skip: LD-Signature user(${user.uri}) !== activity.actor(${activity.actor})`;
Expand Down
35 changes: 35 additions & 0 deletions src/remote/activitypub/misc/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,38 @@ export const CONTEXTS: Record<string, any> = {
"https://w3id.org/security/v1": security_v1,
"https://www.w3.org/ns/activitystreams": activitystreams,
};

export const FIXED_CONTEXT = [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{
Key: 'sec:Key',
// as non-standards
manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
sensitive: 'as:sensitive',
Hashtag: 'as:Hashtag',
// Mastodon
toot: 'http://joinmastodon.org/ns#',
Emoji: 'toot:Emoji',
featured: 'toot:featured',
discoverable: 'toot:discoverable',
indexable: 'toot:indexable',
// schema
schema: 'http://schema.org#',
PropertyValue: 'schema:PropertyValue',
value: 'schema:value',
// Misskey
misskey: 'https://misskey-hub.net/ns#',
'_misskey_content': 'misskey:_misskey_content',
'_misskey_quote': 'misskey:_misskey_quote',
'_misskey_reaction': 'misskey:_misskey_reaction',
'_misskey_votes': 'misskey:_misskey_votes',
'isCat': 'misskey:isCat',
// vcard
vcard: 'http://www.w3.org/2006/vcard/ns#',
// Fedibird
fedibird: 'http://fedibird.com/ns#',
quoteUri: 'fedibird:quoteUri',
searchableBy: { '@id': 'fedibird:searchableBy', '@type': '@id' },
}
];
7 changes: 7 additions & 0 deletions src/remote/activitypub/misc/ld-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export class LdSignature {
});
}

public async compact(data: any, context: any) {
const customLoader = this.getLoader();
return await jsonld.compact(data, context, {
documentLoader: customLoader
});
}

private getLoader() {
return async (url: string): Promise<any> => {
if (!url.match('^https?\:\/\/')) throw `Invalid URL ${url}`;
Expand Down
4 changes: 2 additions & 2 deletions src/remote/activitypub/models/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createImage(actor: IRemoteUser, value: IObject): Promise<I
if (!isDocument(image)) return null;

if (typeof image.url !== 'string') {
throw new Error('invalid image: url not privided');
return null;
}

logger.info(`Creating the Image: ${image.url}`);
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function createImage(actor: IRemoteUser, value: IObject): Promise<I
* Misskeyに対象のImageが登録されていればそれを返し、そうでなければ
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
*/
export async function resolveImage(actor: IRemoteUser, value: IObject): Promise<IDriveFile> {
export async function resolveImage(actor: IRemoteUser, value: IObject): Promise<IDriveFile | null | undefined> {
// TODO

// リモートサーバーからフェッチしてきて登録
Expand Down
Loading

0 comments on commit 531f1e0

Please sign in to comment.