mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
requested changes to verifyFieldLinks
Co-authored-by: dakkar <dakkar@thenautilus.net>
This commit is contained in:
parent
20482888b0
commit
46fa99fc28
3 changed files with 34 additions and 52 deletions
|
@ -42,7 +42,7 @@ import type { AccountMoveService } from '@/core/AccountMoveService.js';
|
||||||
import { ApUtilityService } from '@/core/activitypub/ApUtilityService.js';
|
import { ApUtilityService } from '@/core/activitypub/ApUtilityService.js';
|
||||||
import { MemoryKVCache } from '@/misc/cache.js';
|
import { MemoryKVCache } from '@/misc/cache.js';
|
||||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||||
import { verifyFieldLink } from '@/misc/verify-field-link.js';
|
import { verifyFieldLinks } from '@/misc/verify-field-link.js';
|
||||||
import { getApId, getApType, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
|
import { getApId, getApType, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
|
||||||
import { extractApHashtags } from './tag.js';
|
import { extractApHashtags } from './tag.js';
|
||||||
import type { OnModuleInit } from '@nestjs/common';
|
import type { OnModuleInit } from '@nestjs/common';
|
||||||
|
@ -337,7 +337,6 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
this.logger.info(`Creating the Person: ${person.id}`);
|
this.logger.info(`Creating the Person: ${person.id}`);
|
||||||
|
|
||||||
const fields = this.analyzeAttachments(person.attachment ?? []);
|
const fields = this.analyzeAttachments(person.attachment ?? []);
|
||||||
const field_urls = fields.filter(x => x.value.startsWith('https://'));
|
|
||||||
|
|
||||||
const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32);
|
const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32);
|
||||||
|
|
||||||
|
@ -366,15 +365,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
|
|
||||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||||
|
|
||||||
const verifiedLinks: string[] = [];
|
const verifiedLinks = url ? await verifyFieldLinks(fields, url, this.httpRequestService) : [];
|
||||||
if (url) {
|
|
||||||
for (const field_url of field_urls) {
|
|
||||||
const includesProfileLinks = await verifyFieldLink(field_url.value, url, this.httpRequestService);
|
|
||||||
if (includesProfileLinks) {
|
|
||||||
verifiedLinks.push(field_url.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
let user: MiRemoteUser | null = null;
|
let user: MiRemoteUser | null = null;
|
||||||
|
@ -566,7 +557,6 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
const emojiNames = emojis.map(emoji => emoji.name);
|
const emojiNames = emojis.map(emoji => emoji.name);
|
||||||
|
|
||||||
const fields = this.analyzeAttachments(person.attachment ?? []);
|
const fields = this.analyzeAttachments(person.attachment ?? []);
|
||||||
const field_urls = fields.filter(x => x.value.startsWith('https://'));
|
|
||||||
|
|
||||||
const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32);
|
const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32);
|
||||||
|
|
||||||
|
@ -595,15 +585,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown {
|
||||||
|
|
||||||
const url = this.apUtilityService.findBestObjectUrl(person);
|
const url = this.apUtilityService.findBestObjectUrl(person);
|
||||||
|
|
||||||
const verifiedLinks: string[] = [];
|
const verifiedLinks = url ? await verifyFieldLinks(fields, url, this.httpRequestService) : [];
|
||||||
if (url) {
|
|
||||||
for (const field_url of field_urls) {
|
|
||||||
const includesProfileLinks = await verifyFieldLink(field_url.value, url, this.httpRequestService);
|
|
||||||
if (includesProfileLinks) {
|
|
||||||
verifiedLinks.push(field_url.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updates = {
|
const updates = {
|
||||||
lastFetchedAt: new Date(),
|
lastFetchedAt: new Date(),
|
||||||
|
|
|
@ -5,14 +5,16 @@
|
||||||
|
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||||
import { safeForSql } from './safe-for-sql.js';
|
|
||||||
|
|
||||||
|
type Field = { name: string, value: string };
|
||||||
|
|
||||||
export async function verifyFieldLink(field_url: string, profile_url: string, httpRequestService: HttpRequestService): Promise<boolean | undefined> {
|
export async function verifyFieldLinks(fields: Field[], profile_url: string, httpRequestService: HttpRequestService): Promise<string[]> {
|
||||||
if (!safeForSql(field_url)) return;
|
const verified_links = [];
|
||||||
|
for (const field_url of fields
|
||||||
|
.filter(x => URL.canParse(x.value) && ['http:', 'https:'].includes((new URL(x.value).protocol)))) {
|
||||||
|
console.log('fortnite ' + field_url);
|
||||||
try {
|
try {
|
||||||
const html = await httpRequestService.getHtml(field_url);
|
const html = await httpRequestService.getHtml(field_url.value);
|
||||||
|
|
||||||
const { window } = new JSDOM(html);
|
const { window } = new JSDOM(html);
|
||||||
const doc: Document = window.document;
|
const doc: Document = window.document;
|
||||||
|
@ -21,12 +23,13 @@ export async function verifyFieldLink(field_url: string, profile_url: string, ht
|
||||||
const linkEls = Array.from(doc.getElementsByTagName('link'));
|
const linkEls = Array.from(doc.getElementsByTagName('link'));
|
||||||
|
|
||||||
const includesProfileLinks = [...aEls, ...linkEls].some(link => link.rel === 'me' && link.href === profile_url);
|
const includesProfileLinks = [...aEls, ...linkEls].some(link => link.rel === 'me' && link.href === profile_url);
|
||||||
|
if (includesProfileLinks) { verified_links.push(field_url.value); }
|
||||||
|
|
||||||
window.close();
|
window.close();
|
||||||
|
|
||||||
return includesProfileLinks;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// なにもしない
|
// don't do anything.
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return verified_links;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.j
|
||||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||||
import type { Config } from '@/config.js';
|
import type { Config } from '@/config.js';
|
||||||
import { safeForSql } from '@/misc/safe-for-sql.js';
|
import { safeForSql } from '@/misc/safe-for-sql.js';
|
||||||
import { verifyFieldLink } from '@/misc/verify-field-link.js'
|
import { verifyFieldLinks } from '@/misc/verify-field-link.js';
|
||||||
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
|
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
|
||||||
import { notificationRecieveConfig } from '@/models/json-schema/user.js';
|
import { notificationRecieveConfig } from '@/models/json-schema/user.js';
|
||||||
import { userUnsignedFetchOptions } from '@/const.js';
|
import { userUnsignedFetchOptions } from '@/const.js';
|
||||||
|
@ -585,9 +585,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.globalEventService.publishInternalEvent('localUserUpdated', { id: user.id });
|
this.globalEventService.publishInternalEvent('localUserUpdated', { id: user.id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const verified_links = await verifyFieldLinks(newFields, `${this.config.url}/@${user.username}`, this.httpRequestService);
|
||||||
|
|
||||||
await this.userProfilesRepository.update(user.id, {
|
await this.userProfilesRepository.update(user.id, {
|
||||||
...profileUpdates,
|
...profileUpdates,
|
||||||
verifiedLinks: [],
|
verifiedLinks: verified_links,
|
||||||
});
|
});
|
||||||
|
|
||||||
const iObj = await this.userEntityService.pack(user.id, user, {
|
const iObj = await this.userEntityService.pack(user.id, user, {
|
||||||
|
@ -612,19 +614,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
this.accountUpdateService.publishToFollowers(user.id);
|
this.accountUpdateService.publishToFollowers(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const urls = updatedProfile.fields.filter(x => x.value.startsWith('https://'));
|
if (verified_links.length > 0) {
|
||||||
for (const url of urls) {
|
|
||||||
// this is a different, broader implementation so we can support remote users.
|
|
||||||
const includesProfileLinks = await verifyFieldLink(url.value, `${this.config.url}/@${user.username}`, this.httpRequestService);
|
|
||||||
if (includesProfileLinks) {
|
|
||||||
await userProfilesRepository.createQueryBuilder('profile').update()
|
await userProfilesRepository.createQueryBuilder('profile').update()
|
||||||
.where('userId = :userId', { userId: user.id })
|
.where('userId = :userId', { userId: user.id })
|
||||||
.set({
|
.set({
|
||||||
verifiedLinks: () => `array_append("verifiedLinks", '${url}')`, // ここでSQLインジェクションされそうなのでとりあえず safeForSql で弾いている
|
verifiedLinks: verified_links.filter(x => safeForSql(x)), // ここでSQLインジェクションされそうなのでとりあえず safeForSql で弾いている
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return iObj;
|
return iObj;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue