Skip to content

pkp/pkp-lib#1660 Customizable Reviewer Recommendations #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 29, 2025

Conversation

touhidurabir
Copy link
Member

@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 73e1b28 to 664f865 Compare November 19, 2024 07:46
@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 6ffce94 to 843402d Compare December 6, 2024 11:34
@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 6a02187 to 3a9b03d Compare January 10, 2025 12:05
@touhidurabir touhidurabir requested a review from asmecher January 24, 2025 17:43
@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 406d064 to 253ac65 Compare February 11, 2025 09:08
@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 70c9f3f to b8beae3 Compare February 23, 2025 17:03
@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 3fc09e1 to a3dc39d Compare February 27, 2025 19:13
@touhidurabir touhidurabir marked this pull request as ready for review February 27, 2025 20:06
this.openDialog({
name: 'delete',
title: this.deleteRecommendationLabel,
message: this.replaceLocaleParams(this.confirmDeleteMessage, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an XSS flaw -- any HTML entered in the recommendation.title will be passed through to the browser. (Also the other keys that mix user-supplied data in here.)

Copy link
Member Author

@touhidurabir touhidurabir Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmecher good spot . I had this left out as v-strip-unsafe-html was not yet available for main as we introduced in 3.4.0 . But then forgot to update these as v-strip-unsafe-html was added just about a week ago in main branch .

One question , rather than applying this for replaceLocaleParams every time like

message: this.replaceLocaleParams(this.confirmDeleteMessage, {
    title: sanitizeHtml(this.localize(recommendation.title)),
})

should we add this sanitizeHtml into the implementation of replaceLocaleParams so that we don't need to make sure to add this every time ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XSS is by default prevented by vue.js, and in cases where we use (and sometime overuse) v-html, its now replaced with v-strip-unsafe-html. Therefore this will go through that. Every component is responsible to do the XSS protection.

Therefore Dialog handles that when rendering message.

<div v-strip-unsafe-html="message" />

No point to sanitize twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jardakotesovec, I used a <i> tag to confirm that entered HTML was passed through, and I didn't check whether more malicious tags were filtered -- so it's possible that <i> gets through because it's "safe", but worse HTML would be filtered. However, it's still incorrectly escaping the content. The reviewer recommendation title is plaintext, not a rich text field, so any entered content should be fully escaped before getting glued into the locale string.

Copy link
Contributor

@jardakotesovec jardakotesovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @touhidurabir. This is very nicely integrated with new code base. I am not sure whether this is aimed for 3.5, so I would understand if some of the 'composition api' updates would be left out for timeline purposes.

But if you decide to do the upgrade and struggle with something feel free to message me directly on mattermost. I should be able to point you to some good example or something.

@asmecher
Copy link
Member

I am not sure whether this is aimed for 3.5

It's scheduled for 3.6, and I was considering pulling it forward to 3.5 -- but I'd rather spend a bit more time to get a clean implementation than rush it in. So let's leave it on the 3.6 milestone.

@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from d224862 to 61d5f40 Compare March 20, 2025 19:38
? props.confirmDeactivateMessage
: props.confirmActivateMessage,
{
title: escapeHtml(localize(item.title)),
Copy link
Contributor

@jardakotesovec jardakotesovec Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that the reviewer recommendations are not supporting any html tags, right? So we basically just want to make sure that if it has any html tags it would not be interpreted?

We have couple places like tooltip or dialogs, where we introduced v-html because we had some message in translations which required that. To reduce attack surface area we introduced v-strip-unsafe-html, which at least ensures safe html.

I would like to improve the situation in 3.6 further.

I think for general components that because of some use case started offering v-html - we should have separate props for that. For Example having openDialog with options: message and messageHtml. So its decided when the dialog is created whether html is needed and whether its safe based on what I am passing there. For this improvement I will create separate ticket and introduce the html variants when necessary.

But your use case is bit more nuanced, because you have translation Are you sure you want to deactivate the recommendation <b>{$title}</b>. Therefore you want to render it as html, but escape the argument, which you are doing, but would be nice to also make the translation toolkit safe by default.

I will leave up to you whether you would add this improvement here, since you already touched on the escaping functions or whether you prefer me to add it in separate ticket, but I think having option in our t function will be best..

By default t should escape all the arguments being passed. But need to introduce option to allow html if needed.

So in your case it should look like (now putting aside that I will move the message to messageHtml in separate ticket):

message: item.status ? t('manager.reviewerRecommendations.confirmDeactivate', {title: localize(item.title)}) : ...

But there still would be option, to skip the escaping for specific fields:

t('manager.reviewerRecommendations.confirmDeactivate', {title: localize(item.title)}, {allowHtml: ['title']}) 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will and want to work on this but I think it will be better to handle this as a separate issue . Reason is, this would be a global impact level change and a very important one . Better to keep track of this as it's own issue so that we can in future get clear idea what plan and strategy we adapted for this one and what was the implementation. This issue is already got bit too big so better to separate this implementation from this issue .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.. make sense to introduce these changes separately.

In that case I would suggest not to introduce the escapeHtml at this point. Because that will be default behaviour for the message of dialog. So if you remove it - it will be safe enough for now and after we work on the updates that I mentioned, it will also prevent sneaking in any html to affect rendering.

@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 24e353d to 003b6aa Compare April 15, 2025 12:59
@touhidurabir
Copy link
Member Author

Hi @jardakotesovec can you please take another look .

Copy link
Contributor

@jardakotesovec jardakotesovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding useForm, sorry I need to document this better. I did some testing and it seems to be working fine. Feel free to cherry-pick this commit - jardakotesovec@6e4ec1a

I also sneaked in spinner to the table to indicate when the data are being refetched for small connections.

So my suggestion would be to add this commit (seemed working fine from my testing, if you see issue ping me on mattermost).

Resolve other suggestions.

And ping me and I will do the last quick check.

Thank you!

@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 81712d6 to 081001c Compare April 21, 2025 05:24
@touhidurabir
Copy link
Member Author

@jardakotesovec hopefully ready for the final look , please check .

Copy link
Contributor

@jardakotesovec jardakotesovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just couple small clean up items. Thanks!

<SideModalLayoutBasic>
<PkpForm
ref="editRecommendation"
class="recommendations__recommendationForm"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class needed?

<template #default="{closeModal}">
<SideModalLayoutBasic>
<PkpForm
ref="editRecommendation"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No big deal, but I think you don't think you need this ref?

const {t, localize} = useLocalize();

const items = computed({
get: () => recommendations.value?.items || [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So could this be just

computed(() => recommendations.value?.items || [])

});

await fetch();
return isSuccess.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but isSuccess is not really needed.

const newStatus = !item.status;

openDialog({
name: 'edit',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, name is not used anymore

: t('manager.reviewerRecommendations.deactivate.title'),
message: t(
item.status
? 'manager.reviewerRecommendations.confirmDeactivate'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.. :-).. this is tricky..

Automatic detection of the locale keys is happening in build time and therefore I have to rely on regex.

So it needs to find t('key') or tk('key') to pick it up.

With having condition like this inside, I don't think it would work.

}

// Initial data fetch
fetchRecommendations();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very subjective suggestion about how to organise with composition API. Especially for more complex components trying to group things by feature. So since the beginning is focused on the fetching the recommendations I would do the initial trigger there.

		const {
			data: recommendations,
			fetch: fetchRecommendations,
			isLoading: isRecommendationsLoading,
		} = useFetch(apiUrl);
		// Initial data fetch
		fetchRecommendations();

@touhidurabir touhidurabir force-pushed the i1660_main branch 2 times, most recently from 8781121 to 1f8f1ae Compare April 25, 2025 14:06
touhidurabir and others added 6 commits April 28, 2025 19:50
pkp/pkp-lib#1660 remove static recommendations and added dymanic recommendations pulling

pkp/pkp-lib#1660 updated activate/deactivate process

pkp/pkp-lib#1660 behaviour update of checkbox to activate/deactivate

pkp/pkp-lib#1660 table view implementation

pkp/pkp-lib#1660 set used recommendation uneditable

pkp/pkp-lib#1660 updated dropdown action component

pkp/pkp-lib#1660 removed unused imports

pkp/pkp-lib#1660 make recommendations optional for reviewer manager component to support OMP/OPS

pkp/pkp-lib#1660 added js side html sanitizer to handle XXS issue

pkp/pkp-lib#1660 removed value attributes form recommendation
pkp/pkp-lib#1660 fixing storybook

pkp/pkp-lib#1660 issue when recommendation not available

pkp/pkp-lib#1660 tag remove for put text presentation

pkp/pkp-lib#1660 Better escaping added
@touhidurabir touhidurabir merged commit a1302a9 into pkp:main Apr 29, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants