Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: truncate user information if it is too long #7629

Merged
merged 2 commits into from Aug 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/remote/activitypub/models/person.ts
Expand Up @@ -31,6 +31,9 @@ import { normalizeForSearch } from '@/misc/normalize-for-search';

const logger = apLogger;

const nameLength = 128;
const summaryLength = 2048;
Comment on lines +34 to +35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe these should be stored in misskey/src/misc/hard-limits.ts ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will to do so!


/**
* Validate and convert to actor object
* @param x Fetched object
Expand All @@ -52,11 +55,23 @@ function validateActor(x: IObject, uri: string): IActor {
if (e) throw new Error(`invalid Actor: ${name} ${e.message}`);
};

const truncate = (input: string | undefined, size: number) => {
if (!input || input.length <= size) {
return input;
} else {
return input.substring(0, size);
}
};

validate('id', x.id, $.str.min(1));
validate('inbox', x.inbox, $.str.min(1));
validate('preferredUsername', x.preferredUsername, $.str.min(1).max(128).match(/^\w([\w-.]*\w)?$/));
validate('name', x.name, $.optional.nullable.str.max(128));
validate('summary', x.summary, $.optional.nullable.str.max(2048));

// These fields are only informational, and some AP software allows these
// fields to be very long. If they are too long, we cut them off. This way
// we can at least see these users and their activities.
validate('name', truncate(x.name, nameLength), $.optional.nullable.str);
validate('summary', truncate(x.summary, summaryLength), $.optional.nullable.str);

const idHost = toPuny(new URL(x.id!).hostname);
if (idHost !== expectHost) {
Expand Down