ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix TypeError crash when receiving actors without publicKey via federation
lawrence3699528034b095ff
diff --git a/packages/tests/src/server-helpers/validator.ts b/packages/tests/src/server-helpers/validator.tsindex 21ca0fd5bd..df27eb4b15 100644--- a/packages/tests/src/server-helpers/validator.ts+++ b/packages/tests/src/server-helpers/validator.ts@@ -2,9 +2,49 @@import { isStableOrUnstableVersionValid, isStableVersionValid } from '@peertube/peertube-server/core/helpers/custom-validators/misc.js'import {} from '@peertube/peertube-server/core/helpers/custom-validators/plugins.js'+import {+ isActorPublicKeyObjectValid,+ sanitizeAndCheckActorObject+} from '@peertube/peertube-server/core/helpers/custom-validators/activitypub/actor.js'import { expect } from 'chai'describe('Validators', function () {++ describe('ActivityPub actor validators', function () {++ it('Should return false for null/undefined publicKey without crashing', async function () {+ expect(isActorPublicKeyObjectValid(null)).to.be.false+ expect(isActorPublicKeyObjectValid(undefined)).to.be.false+ expect(isActorPublicKeyObjectValid(0)).to.be.false+ expect(isActorPublicKeyObjectValid('')).to.be.false+ })++ it('Should return false for a publicKey object with missing fields', async function () {+ expect(isActorPublicKeyObjectValid({})).to.be.false+ expect(isActorPublicKeyObjectValid({ id: 'not-a-url' })).to.be.false+ expect(isActorPublicKeyObjectValid({ id: 'https://example.com/key', owner: 'not-a-url' })).to.be.false+ })++ it('Should return true for a valid publicKey object', async function () {+ const validKey = {+ id: 'https://example.com/accounts/user#main-key',+ owner: 'https://example.com/accounts/user',+ publicKeyPem: '-----BEGIN PUBLIC KEY-----\nMIIBIjANB...fake...key\n-----END PUBLIC KEY-----'+ }+ expect(isActorPublicKeyObjectValid(validKey)).to.be.true+ })++ it('Should return false for sanitizeAndCheckActorObject with missing publicKey', async function () {+ const actorWithoutPublicKey: any = {+ type: 'Person',+ id: 'https://example.com/accounts/user',+ inbox: 'https://example.com/accounts/user/inbox',+ preferredUsername: 'user',+ publicKey: null+ }+ expect(sanitizeAndCheckActorObject(actorWithoutPublicKey)).to.be.false+ })+ })it('Should correctly check stable plugin versions', async function () {expect(isStableVersionValid('3.4.0')).to.be.trueexpect(isStableVersionValid('0.4.0')).to.be.truediff --git a/server/core/helpers/custom-validators/activitypub/actor.ts b/server/core/helpers/custom-validators/activitypub/actor.tsindex 3b60ddd1ce..24a0d403ec 100644--- a/server/core/helpers/custom-validators/activitypub/actor.ts+++ b/server/core/helpers/custom-validators/activitypub/actor.ts@@ -17,6 +17,8 @@ export function isActorEndpointsObjectValid (endpointObject: any) {}export function isActorPublicKeyObjectValid (publicKeyObject: any) {+ if (!publicKeyObject) return false+return isActivityPubUrlValid(publicKeyObject.id) &&isActivityPubUrlValid(publicKeyObject.owner) &&isActorPublicKeyValid(publicKeyObject.publicKeyPem)