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

add more limits #329

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
limit Actor properties
  • Loading branch information
xtuc committed Feb 22, 2023
commit d43a5d316d0f79d49381d066da0eb33fb4092a80
9 changes: 9 additions & 0 deletions backend/src/activitypub/actors/index.ts
Original file line number Diff line number Diff line change
@@ -47,12 +47,21 @@ export async function get(url: string | URL): Promise<Actor> {

if (actor.summary) {
actor.summary = await sanitizeContent(actor.summary)
if (actor.summary.length > 500) {
actor.summary = actor.summary.substring(0, 500)
}
}
if (actor.name) {
actor.name = await getTextContent(actor.name)
if (actor.name.length > 30) {
actor.name = actor.name.substring(0, 30)
}
}
if (actor.preferredUsername) {
actor.preferredUsername = await getTextContent(actor.preferredUsername)
if (actor.preferredUsername.length > 30) {
actor.preferredUsername = actor.preferredUsername.substring(0, 30)
}
}

// This is mostly for testing where for convenience not all values
22 changes: 22 additions & 0 deletions backend/test/activitypub.spec.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,28 @@ describe('ActivityPub', () => {
assert.equal(actor.name, 'hi hey')
assert.equal(actor.preferredUsername, 'sven alert(1)')
})

test('Actor properties limits', async () => {
globalThis.fetch = async (input: RequestInfo) => {
if (input === 'https://example.com/actor') {
return new Response(
JSON.stringify({
id: 'https://example.com/actor',
type: 'Person',
summary: 'a'.repeat(612),
name: 'b'.repeat(50),
preferredUsername: 'c'.repeat(50),
})
)
}
throw new Error(`unexpected request to "${input}"`)
}

const actor = await actors.get('https://example.com/actor')
assert.equal(actor.summary, 'a'.repeat(500))
assert.equal(actor.name, 'b'.repeat(30))
assert.equal(actor.preferredUsername, 'c'.repeat(30))
})
})

describe('Outbox', () => {