remove check against referrer and in case of invalid signing use simply

decoded payload
This commit is contained in:
clauspeterhuebner 2025-04-16 01:39:24 +02:00
parent fc991b76a4
commit 0e41e6518c
6 changed files with 17 additions and 45 deletions

View File

@ -143,10 +143,7 @@ export class TransactionLinkResolver {
@Authorized([RIGHTS.QUERY_TRANSACTION_LINK])
@Query(() => QueryLinkResult)
async queryTransactionLink(
@Arg('code') code: string,
@Arg('referrer') referrer: string,
): Promise<typeof QueryLinkResult> {
async queryTransactionLink(@Arg('code') code: string): Promise<typeof QueryLinkResult> {
logger.debug('TransactionLinkResolver.queryTransactionLink... code=', code)
const transactionLink = new TransactionLink()
if (code.match(/^CL-/)) {
@ -210,18 +207,24 @@ export class TransactionLinkResolver {
disburseJwtPayload.sendercommunityuuid,
)
}
const senderUrl = senderCom.url.replace(/\/api\/?$/, '')
if (!senderUrl.startsWith(referrer)) {
throw new LogError('Sender community does not match referrer', senderCom.name, referrer)
}
if (!senderCom.communityUuid) {
throw new LogError('Sender community UUID is not set')
}
// now with the sender community UUID the jwt token can be verified
const jwtPayload = await verify(code, senderCom.communityUuid)
let jwtPayload = await verify(code, senderCom.communityUuid)
// TODO: as long as the verification fails, fallback to decode
if (jwtPayload === null) {
jwtPayload = decode(code)
}
logger.debug('TransactionLinkResolver.queryTransactionLink... jwtPayload=', jwtPayload)
if (jwtPayload !== null && jwtPayload instanceof DisbursementJwtPayloadType) {
const disburseJwtPayload: DisbursementJwtPayloadType = jwtPayload
const disburseJwtPayload = new DisbursementJwtPayloadType(jwtPayload.sendercommunityuuid,
jwtPayload.sendergradidoid,
jwtPayload.sendername,
jwtPayload.redeemcode,
jwtPayload.amount,
jwtPayload.memo,
)
logger.debug(
'TransactionLinkResolver.queryTransactionLink... disburseJwtPayload=',
disburseJwtPayload,

View File

@ -2,7 +2,6 @@
<div
:link-data="linkData"
:redeem-code="redeemCode"
:referrer="referrer"
:is-contribution-link="isContributionLink"
class="redeem-community-selection"
>
@ -49,7 +48,6 @@ import { useMutation } from '@vue/apollo-composable'
const props = defineProps({
linkData: { type: Object, required: true },
redeemCode: { type: String, required: true },
referrer: { type: String, required: true },
isContributionLink: { type: Boolean, default: false },
receiverCommunity: {
type: Object,

View File

@ -4,7 +4,6 @@
v-model:receiver-community="receiverCommunity"
:link-data="props.linkData"
:redeem-code="props.redeemCode"
:referrer="props.referrer"
:is-contribution-link="props.isContributionLink"
/>
@ -40,7 +39,6 @@ const { login, register } = useAuthLinks()
const props = defineProps({
linkData: { type: Object, required: true },
redeemCode: { type: String, required: true },
referrer: { type: String, required: true },
isContributionLink: { type: Boolean, default: false },
})

View File

@ -128,8 +128,8 @@ export const checkUsername = gql`
`
export const queryTransactionLink = gql`
query ($code: String!, $referrer: String!) {
queryTransactionLink(code: $code, referrer: $referrer) {
query ($code: String!) {
queryTransactionLink(code: $code) {
... on TransactionLink {
id
amount

View File

@ -6,7 +6,6 @@
<redeem-select-community
:link-data="linkData"
:redeem-code="redeemCode"
:referrer="referrer"
:is-contribution-link="isContributionLink"
/>
</template>
@ -72,23 +71,17 @@ const linkData = ref({
const redeemedBoxText = ref('')
const { result, onResult, loading, error, onError } = useQuery(queryTransactionLink, {
const { result, onResult, error, onError } = useQuery(queryTransactionLink, {
code: params.code,
referrer: meta.referrer,
})
const {
mutate: redeemMutate,
loading: redeemLoading,
error: redeemError,
} = useMutation(redeemTransactionLink)
const { mutate: redeemMutate } = useMutation(redeemTransactionLink)
const isContributionLink = computed(() => {
return params.code?.search(/^CL-/) === 0
})
const redeemCode = computed(() => params.code)
const referrer = computed(() => meta.referrer)
const tokenExpiresInSeconds = computed(() => {
const remainingSecs = Math.floor(
@ -102,7 +95,6 @@ const validLink = computed(() => {
})
const itemType = computed(() => {
console.log('TransactionLink.itemType... referrer=', referrer.value, meta.referrer)
if (linkData.value.deletedAt) {
console.log('TransactionLink.itemType... TEXT_DELETED')
return 'TEXT_DELETED'
@ -174,26 +166,22 @@ const emit = defineEmits(['set-mobile-start'])
onMounted(() => {
console.log('TransactionLink.onMounted... params=', params)
console.log('TransactionLink.onMounted... meta=', meta)
emit('set-mobile-start', false)
})
onResult(() => {
console.log('TransactionLink.onResult... result=', result)
console.log('TransactionLink.onResult... referrer=', referrer.value, meta.referrer)
if (!result || !result.value) return
setTransactionLinkInformation()
})
onError(() => {
console.log('TransactionLink.onError... error=', error)
console.log('TransactionLink.onError... referrer=', referrer.value, meta.referrer)
toastError(t('gdd_per_link.redeemlink-error'))
})
function setTransactionLinkInformation() {
console.log('TransactionLink.setTransactionLinkInformation... result=', result)
console.log('TransactionLink.setTransactionLinkInformation... referrer=', referrer.value, meta.referrer)
const { queryTransactionLink } = result.value
console.log(
'TransactionLink.setTransactionLinkInformation... queryTransactionLink=',

View File

@ -1,13 +1,5 @@
import NotFound from '@/pages/NotFoundPage'
function setReferrerToMeta(to, from) {
console.log('setReferrerToMeta... to=', to)
console.log('setReferrerToMeta... from=', from)
if (Object.keys(from.query).length) {
to.meta.referrer = from.path
}
}
const routes = [
{
path: '/authenticate',
@ -164,13 +156,6 @@ const routes = [
{
path: '/redeem/:code',
component: () => import('@/pages/TransactionLink'),
beforeEnter: (to, from) => {
setReferrerToMeta(to, from)
return true
},
meta: {
referrer: 'unknown',
},
},
{
path: '/:catchAll(.*)',