Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-islands-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': major
---

fix(integrations): Add validation for Incoming Webhook Avatar
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Changelog entry should reflect the primary fix (emoji validation) and mention both validations added.

The changeset message only mentions "Avatar" validation, but according to the PR objectives and the linked issue #37451, the primary fix is for emoji field validation. The AI summary context also indicates that both validateAvatarUrl and validateEmoji validators are being added. The changelog entry should be more accurate and complete.

Consider updating the changelog message to clarify the primary objective and mention both validations:

- fix(integrations): Add validation for Incoming Webhook Avatar
+ fix(integrations): Add validation for Incoming Webhook Emoji and Avatar URL

Alternatively, if emoji validation is the primary fix:

- fix(integrations): Add validation for Incoming Webhook Avatar
+ fix(integrations): Add validation for Incoming Webhook Emoji field format
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fix(integrations): Add validation for Incoming Webhook Avatar
fix(integrations): Add validation for Incoming Webhook Emoji and Avatar URL
🤖 Prompt for AI Agents
In .changeset/funny-islands-run.md around line 5, the changelog line only
mentions "Avatar" validation but the PR primarily fixes emoji field validation
and adds both validateAvatarUrl and validateEmoji; update the changelog entry to
clearly state the primary fix (emoji validation) and also mention that avatar
URL validation was added so both validations are reflected in the message.

5 changes: 5 additions & 0 deletions .changeset/light-singers-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix(integrations): Add validation for Incoming Webhook Avatar
5 changes: 5 additions & 0 deletions .changeset/mighty-queens-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix(integrations): Add validation for Incoming Webhook Emoji field format
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { useSetModal, useTranslation, useRouter, useRouteParameter } from '@rock
import { useId, useCallback } from 'react';
import { FormProvider, useForm } from 'react-hook-form';




import IncomingWebhookForm from './IncomingWebhookForm';
import { Page, PageHeader, PageScrollableContentWithShadow, PageFooter } from '../../../../components/Page';
import { useCreateIntegration } from '../hooks/useCreateIntegration';
import { useDeleteIntegration } from '../hooks/useDeleteIntegration';
import { useUpdateIntegration } from '../hooks/useUpdateIntegration';



export type EditIncomingWebhookFormData = {
enabled: boolean;
channel: string;
Expand Down Expand Up @@ -51,6 +56,8 @@ const EditIncomingWebhook = ({ webhookData }: EditIncomingWebhookProps) => {
const setModal = useSetModal();
const tab = useRouteParameter('type');



const deleteIntegration = useDeleteIntegration(INCOMING_TYPE);
const updateIntegration = useUpdateIntegration(INCOMING_TYPE);
const createIntegration = useCreateIntegration(INCOMING_TYPE);
Expand All @@ -63,6 +70,9 @@ const EditIncomingWebhook = ({ webhookData }: EditIncomingWebhookProps) => {
formState: { isDirty },
} = methods;




const handleDeleteIntegration = useCallback(() => {
const onDelete = async () => {
if (!webhookData?._id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ const IncomingWebhookForm = ({ webhookData }: { webhookData?: Serialized<IIncomi
const { t } = useTranslation();
const absoluteUrl = useAbsoluteUrl();

const validateAvatarUrl = (value: string) => {
if (!value) return true;
try {
const url = new URL(value);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
return t('The_URL_is_invalid', { url: value });
}
return true;
} catch (error) {
return t('The_URL_is_invalid', { url: value });
}
};

const validateEmoji = (value: string) => {
if (!value) return true;

if (/^:.+:$/.test(value)) {
return true;
}

if ([...value.trim()].length === 1 && /\p{Extended_Pictographic}/u.test(value)) {
return true;
}

return t('Invalid_emoji_format_Must_be_in_colon_format', { example: ':ghost:' });
};

const {
control,
watch,
Expand Down Expand Up @@ -236,47 +263,67 @@ const IncomingWebhookForm = ({ webhookData }: { webhookData?: Serialized<IIncomi
</FieldRow>
<FieldHint id={`${aliasField}-hint`}>{t('Choose_the_alias_that_will_appear_before_the_username_in_messages')}</FieldHint>
</Field>

<Field>
<FieldLabel htmlFor={avatarField}>{t('Avatar_URL')}</FieldLabel>
<FieldRow>
<Controller
name='avatar'
control={control}
render={({ field }) => (
rules={{ validate: validateAvatarUrl }}
render={({ field, fieldState: { error } }) => (
<TextInput
id={avatarField}
{...field}
aria-describedby={`${avatarField}-hint-1 ${avatarField}-hint-2`}
aria-describedby={`${avatarField}-hint-1 ${avatarField}-hint-2 ${avatarField}-error`}
addon={<Icon name='user-rounded' size='x20' alignSelf='center' />}
aria-invalid={Boolean(error)}
/>
)}
/>
</FieldRow>
{errors?.avatar && (
<FieldError aria-live='assertive' id={`${avatarField}-error`}>
{errors.avatar.message}
</FieldError>
)}

<FieldHint id={`${avatarField}-hint-1`}>{t('You_can_change_a_different_avatar_too')}</FieldHint>
<FieldHint id={`${avatarField}-hint-2`}>{t('Should_be_a_URL_of_an_image')}</FieldHint>
</Field>

<Field>
<FieldLabel htmlFor={emojiField}>{t('Emoji')}</FieldLabel>
<FieldRow>
<Controller
name='emoji'
control={control}
render={({ field }) => (
rules={{ validate: validateEmoji }}
render={({ field, fieldState: { error } }) => (
<TextInput
id={emojiField}
{...field}
aria-describedby={`${emojiField}-hint-1 ${emojiField}-hint-2`}
aria-describedby={`${emojiField}-hint-1 ${emojiField}-hint-2 ${emojiField}-error`}
addon={<Icon name='emoji' size='x20' alignSelf='center' />}
aria-invalid={Boolean(error)}
/>
)}
/>
</FieldRow>

{errors?.emoji && (
<FieldError aria-live='assertive' id={`${emojiField}-error`}>
{errors.emoji.message}
</FieldError>
)}

<FieldHint id={`${emojiField}-hint-1`}>{t('You_can_use_an_emoji_as_avatar')}</FieldHint>
<FieldHint
id={`${emojiField}-hint-2`}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(t('Example_s', { postProcess: 'sprintf', sprintf: [':ghost:'] })) }}
/>
</Field>

<Field>
<FieldRow>
<FieldLabel htmlFor={overrideDestinationChannelEnabledField}>{t('Override_Destination_Channel')}</FieldLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { useCreateIntegration } from '../hooks/useCreateIntegration';
import { useDeleteIntegration } from '../hooks/useDeleteIntegration';
import { useUpdateIntegration } from '../hooks/useUpdateIntegration';

//


type EditOutgoingWebhookFormData = {
enabled: boolean;
impersonateUser: boolean;
Expand Down Expand Up @@ -68,6 +71,7 @@ type EditOutgoingWebhookProps = {

const EditOutgoingWebhook = ({ webhookData }: EditOutgoingWebhookProps) => {
const t = useTranslation();

const setModal = useSetModal();
const router = useRouter();

Expand All @@ -87,6 +91,8 @@ const EditOutgoingWebhook = ({ webhookData }: EditOutgoingWebhookProps) => {
const createIntegration = useCreateIntegration(OUTGOING_TYPE);
const updateIntegration = useUpdateIntegration(OUTGOING_TYPE);



const handleDeleteIntegration = useCallback(() => {
const onDelete = async () => {
deleteIntegration.mutate({ type: OUTGOING_TYPE, integrationId: webhookData?._id });
Expand Down Expand Up @@ -151,7 +157,7 @@ const EditOutgoingWebhook = ({ webhookData }: EditOutgoingWebhookProps) => {
)}
<PageScrollableContentWithShadow is='form' id={formId} onSubmit={handleSubmit(handleSave)}>
<FormProvider {...methods}>
<OutgoingWebhookForm />
<OutgoingWebhookForm />
</FormProvider>
</PageScrollableContentWithShadow>
<PageFooter isDirty={isDirty}>
Expand Down