summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-05-18 16:36:06 +0100
committerdakkar <dakkar@thenautilus.net>2024-05-18 16:48:10 +0100
commitc05cc63e24c654e5e5d2d098e00a2aa669b61adf (patch)
treee56d3eda18886e93a54e93aec12e8076944ecc2e /packages/backend/src
parentmerge: allow overriding all string config values via env - fixes #465 (!476) (diff)
downloadsharkey-c05cc63e24c654e5e5d2d098e00a2aa669b61adf.tar.gz
sharkey-c05cc63e24c654e5e5d2d098e00a2aa669b61adf.tar.bz2
sharkey-c05cc63e24c654e5e5d2d098e00a2aa669b61adf.zip
look inside `url` when checking activity origin - #512
The previous assertion that: > if it's a complicated thing and the `activity.id` doesn't match, I > think we're fine rejecting the activity was wrong: at least peertube sends activities that have `url` as an array of objects. Notice that this does *not*, in fact, fix #512: the peertube activity does not contain its short URL (`https://example.com/w/someid`), so there's no way to confirm that it is the activity we requested.
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/activitypub/misc/check-against-url.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/packages/backend/src/core/activitypub/misc/check-against-url.ts b/packages/backend/src/core/activitypub/misc/check-against-url.ts
index 78ba891a2e..34e4907267 100644
--- a/packages/backend/src/core/activitypub/misc/check-against-url.ts
+++ b/packages/backend/src/core/activitypub/misc/check-against-url.ts
@@ -4,16 +4,24 @@
*/
import type { IObject } from '../type.js';
+function getHrefFrom(one: IObject|string): string | undefined {
+ if (typeof(one) === 'string') return one;
+ return one.href;
+}
+
export function assertActivityMatchesUrls(activity: IObject, urls: string[]) {
const idOk = activity.id !== undefined && urls.includes(activity.id);
+ if (idOk) return;
- // technically `activity.url` could be an `ApObject = IObject |
- // string | (IObject | string)[]`, but if it's a complicated thing
- // and the `activity.id` doesn't match, I think we're fine
- // rejecting the activity
- const urlOk = typeof(activity.url) === 'string' && urls.includes(activity.url);
+ const url = activity.url;
+ if (url) {
+ // `activity.url` can be an `ApObject = IObject | string | (IObject
+ // | string)[]`, we have to look inside it
+ const activityUrls = Array.isArray(url) ? url.map(getHrefFrom) : [getHrefFrom(url)];
+ const goodUrl = activityUrls.find(u => u && urls.includes(u));
- if (!idOk && !urlOk) {
- throw new Error(`bad Activity: neither id(${activity?.id}) nor url(${activity?.url}) match location(${urls})`);
+ if (goodUrl) return;
}
+
+ throw new Error(`bad Activity: neither id(${activity?.id}) nor url(${JSON.stringify(activity?.url)}) match location(${urls})`);
}