return invalid url if feed url is different from user provided url

This commit is contained in:
Hongbo Wu 2023-12-22 09:05:43 +08:00
parent 696de8ea50
commit f6e04daf60
4 changed files with 15 additions and 2 deletions

View file

@ -2790,6 +2790,7 @@ export enum SubscribeErrorCode {
AlreadySubscribed = 'ALREADY_SUBSCRIBED',
BadRequest = 'BAD_REQUEST',
ExceededMaxSubscriptions = 'EXCEEDED_MAX_SUBSCRIPTIONS',
InvalidUrl = 'INVALID_URL',
NotFound = 'NOT_FOUND',
Unauthorized = 'UNAUTHORIZED'
}

View file

@ -2190,6 +2190,7 @@ enum SubscribeErrorCode {
ALREADY_SUBSCRIBED
BAD_REQUEST
EXCEEDED_MAX_SUBSCRIPTIONS
INVALID_URL
NOT_FOUND
UNAUTHORIZED
}

View file

@ -1,6 +1,6 @@
import axios from 'axios'
import { parseHTML } from 'linkedom'
import { Brackets } from 'typeorm'
import { Brackets, In } from 'typeorm'
import {
DEFAULT_SUBSCRIPTION_FOLDER,
Subscription,
@ -204,7 +204,7 @@ export const subscribeResolver = authorized<
// find existing subscription
const existingSubscription = await getRepository(Subscription).findOneBy({
url: feedUrl,
url: In([feedUrl, input.url]), // check both user provided url and parsed url
user: { id: uid },
type: SubscriptionType.Rss,
})
@ -241,6 +241,16 @@ export const subscribeResolver = authorized<
}
}
if (feedUrl !== input.url) {
log.info('feed url is different from user provided url', {
feedUrl,
inputUrl: input.url,
})
return {
errorCodes: [SubscribeErrorCode.InvalidUrl],
}
}
// create new rss subscription
const MAX_RSS_SUBSCRIPTIONS = env.subscription.feed.max

View file

@ -1737,6 +1737,7 @@ const schema = gql`
NOT_FOUND
ALREADY_SUBSCRIBED
EXCEEDED_MAX_SUBSCRIPTIONS
INVALID_URL
}
union AddPopularReadResult = AddPopularReadSuccess | AddPopularReadError