aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/activitypub/account.ts92
-rw-r--r--server/helpers/custom-validators/activitypub/activity.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/actor.ts91
-rw-r--r--server/helpers/custom-validators/activitypub/index.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/undo.ts2
5 files changed, 94 insertions, 95 deletions
diff --git a/server/helpers/custom-validators/activitypub/account.ts b/server/helpers/custom-validators/activitypub/account.ts
deleted file mode 100644
index 10bf81e8a..000000000
--- a/server/helpers/custom-validators/activitypub/account.ts
+++ /dev/null
@@ -1,92 +0,0 @@
1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { isAccountNameValid } from '../accounts'
4import { exists, isUUIDValid } from '../misc'
5import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
6
7function isAccountEndpointsObjectValid (endpointObject: any) {
8 return isActivityPubUrlValid(endpointObject.sharedInbox)
9}
10
11function isAccountPublicKeyObjectValid (publicKeyObject: any) {
12 return isActivityPubUrlValid(publicKeyObject.id) &&
13 isActivityPubUrlValid(publicKeyObject.owner) &&
14 isAccountPublicKeyValid(publicKeyObject.publicKeyPem)
15}
16
17function isAccountTypeValid (type: string) {
18 return type === 'Person' || type === 'Application'
19}
20
21function isAccountPublicKeyValid (publicKey: string) {
22 return exists(publicKey) &&
23 typeof publicKey === 'string' &&
24 publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
25 publicKey.endsWith('-----END PUBLIC KEY-----') &&
26 validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY)
27}
28
29function isAccountPreferredUsernameValid (preferredUsername: string) {
30 return isAccountNameValid(preferredUsername)
31}
32
33function isAccountPrivateKeyValid (privateKey: string) {
34 return exists(privateKey) &&
35 typeof privateKey === 'string' &&
36 privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
37 privateKey.endsWith('-----END RSA PRIVATE KEY-----') &&
38 validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY)
39}
40
41function isRemoteAccountValid (remoteAccount: any) {
42 return isActivityPubUrlValid(remoteAccount.id) &&
43 isUUIDValid(remoteAccount.uuid) &&
44 isAccountTypeValid(remoteAccount.type) &&
45 isActivityPubUrlValid(remoteAccount.following) &&
46 isActivityPubUrlValid(remoteAccount.followers) &&
47 isActivityPubUrlValid(remoteAccount.inbox) &&
48 isActivityPubUrlValid(remoteAccount.outbox) &&
49 isAccountPreferredUsernameValid(remoteAccount.preferredUsername) &&
50 isActivityPubUrlValid(remoteAccount.url) &&
51 isAccountPublicKeyObjectValid(remoteAccount.publicKey) &&
52 isAccountEndpointsObjectValid(remoteAccount.endpoints)
53}
54
55function isAccountFollowingCountValid (value: string) {
56 return exists(value) && validator.isInt('' + value, { min: 0 })
57}
58
59function isAccountFollowersCountValid (value: string) {
60 return exists(value) && validator.isInt('' + value, { min: 0 })
61}
62
63function isAccountDeleteActivityValid (activity: any) {
64 return isBaseActivityValid(activity, 'Delete')
65}
66
67function isAccountFollowActivityValid (activity: any) {
68 return isBaseActivityValid(activity, 'Follow') &&
69 isActivityPubUrlValid(activity.object)
70}
71
72function isAccountAcceptActivityValid (activity: any) {
73 return isBaseActivityValid(activity, 'Accept')
74}
75
76// ---------------------------------------------------------------------------
77
78export {
79 isAccountEndpointsObjectValid,
80 isAccountPublicKeyObjectValid,
81 isAccountTypeValid,
82 isAccountPublicKeyValid,
83 isAccountPreferredUsernameValid,
84 isAccountPrivateKeyValid,
85 isRemoteAccountValid,
86 isAccountFollowingCountValid,
87 isAccountFollowersCountValid,
88 isAccountNameValid,
89 isAccountFollowActivityValid,
90 isAccountAcceptActivityValid,
91 isAccountDeleteActivityValid
92}
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts
index 043e3c55e..ae7732194 100644
--- a/server/helpers/custom-validators/activitypub/activity.ts
+++ b/server/helpers/custom-validators/activitypub/activity.ts
@@ -1,6 +1,6 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { Activity, ActivityType } from '../../../../shared/models/activitypub' 2import { Activity, ActivityType } from '../../../../shared/models/activitypub'
3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' 3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './actor'
4import { isAnnounceActivityValid } from './announce' 4import { isAnnounceActivityValid } from './announce'
5import { isActivityPubUrlValid } from './misc' 5import { isActivityPubUrlValid } from './misc'
6import { isDislikeActivityValid, isLikeActivityValid } from './rate' 6import { isDislikeActivityValid, isLikeActivityValid } from './rate'
diff --git a/server/helpers/custom-validators/activitypub/actor.ts b/server/helpers/custom-validators/activitypub/actor.ts
new file mode 100644
index 000000000..28551c96c
--- /dev/null
+++ b/server/helpers/custom-validators/activitypub/actor.ts
@@ -0,0 +1,91 @@
1import * as validator from 'validator'
2import { CONSTRAINTS_FIELDS } from '../../../initializers'
3import { isAccountNameValid } from '../accounts'
4import { exists, isUUIDValid } from '../misc'
5import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
6
7function isActorEndpointsObjectValid (endpointObject: any) {
8 return isActivityPubUrlValid(endpointObject.sharedInbox)
9}
10
11function isActorPublicKeyObjectValid (publicKeyObject: any) {
12 return isActivityPubUrlValid(publicKeyObject.id) &&
13 isActivityPubUrlValid(publicKeyObject.owner) &&
14 isActorPublicKeyValid(publicKeyObject.publicKeyPem)
15}
16
17function isActorTypeValid (type: string) {
18 return type === 'Person' || type === 'Application' || type === 'Group'
19}
20
21function isActorPublicKeyValid (publicKey: string) {
22 return exists(publicKey) &&
23 typeof publicKey === 'string' &&
24 publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
25 publicKey.endsWith('-----END PUBLIC KEY-----') &&
26 validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTOR.PUBLIC_KEY)
27}
28
29function isActorPreferredUsernameValid (preferredUsername: string) {
30 return isAccountNameValid(preferredUsername)
31}
32
33function isActorPrivateKeyValid (privateKey: string) {
34 return exists(privateKey) &&
35 typeof privateKey === 'string' &&
36 privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
37 privateKey.endsWith('-----END RSA PRIVATE KEY-----') &&
38 validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTOR.PRIVATE_KEY)
39}
40
41function isRemoteActorValid (remoteActor: any) {
42 return isActivityPubUrlValid(remoteActor.id) &&
43 isUUIDValid(remoteActor.uuid) &&
44 isActorTypeValid(remoteActor.type) &&
45 isActivityPubUrlValid(remoteActor.following) &&
46 isActivityPubUrlValid(remoteActor.followers) &&
47 isActivityPubUrlValid(remoteActor.inbox) &&
48 isActivityPubUrlValid(remoteActor.outbox) &&
49 isActorPreferredUsernameValid(remoteActor.preferredUsername) &&
50 isActivityPubUrlValid(remoteActor.url) &&
51 isActorPublicKeyObjectValid(remoteActor.publicKey) &&
52 isActorEndpointsObjectValid(remoteActor.endpoints)
53}
54
55function isActorFollowingCountValid (value: string) {
56 return exists(value) && validator.isInt('' + value, { min: 0 })
57}
58
59function isActorFollowersCountValid (value: string) {
60 return exists(value) && validator.isInt('' + value, { min: 0 })
61}
62
63function isActorDeleteActivityValid (activity: any) {
64 return isBaseActivityValid(activity, 'Delete')
65}
66
67function isActorFollowActivityValid (activity: any) {
68 return isBaseActivityValid(activity, 'Follow') &&
69 isActivityPubUrlValid(activity.object)
70}
71
72function isActorAcceptActivityValid (activity: any) {
73 return isBaseActivityValid(activity, 'Accept')
74}
75
76// ---------------------------------------------------------------------------
77
78export {
79 isActorEndpointsObjectValid,
80 isActorPublicKeyObjectValid,
81 isActorTypeValid,
82 isActorPublicKeyValid,
83 isActorPreferredUsernameValid,
84 isActorPrivateKeyValid,
85 isRemoteActorValid,
86 isActorFollowingCountValid,
87 isActorFollowersCountValid,
88 isActorFollowActivityValid,
89 isActorAcceptActivityValid,
90 isActorDeleteActivityValid
91}
diff --git a/server/helpers/custom-validators/activitypub/index.ts b/server/helpers/custom-validators/activitypub/index.ts
index f8dfae4ff..ba411f1c6 100644
--- a/server/helpers/custom-validators/activitypub/index.ts
+++ b/server/helpers/custom-validators/activitypub/index.ts
@@ -1,4 +1,4 @@
1export * from './account' 1export * from './actor'
2export * from './activity' 2export * from './activity'
3export * from './misc' 3export * from './misc'
4export * from './signature' 4export * from './signature'
diff --git a/server/helpers/custom-validators/activitypub/undo.ts b/server/helpers/custom-validators/activitypub/undo.ts
index 58043f8a1..d07bbf6b7 100644
--- a/server/helpers/custom-validators/activitypub/undo.ts
+++ b/server/helpers/custom-validators/activitypub/undo.ts
@@ -1,4 +1,4 @@
1import { isAccountFollowActivityValid } from './account' 1import { isAccountFollowActivityValid } from './actor'
2import { isBaseActivityValid } from './misc' 2import { isBaseActivityValid } from './misc'
3import { isDislikeActivityValid, isLikeActivityValid } from './rate' 3import { isDislikeActivityValid, isLikeActivityValid } from './rate'
4 4