Skip to content

Commit

Permalink
[FIX] fixes HTML sanitizing error. (#25410)
Browse files Browse the repository at this point in the history
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
  [NEW] For new features
  [IMPROVE] For an improvement (performance or little improvements) in existing features
  [FIX] For bug fixes that affect the end-user
  [BREAK] For pull requests including breaking changes
  Chore: For small tasks
  Doc: For documentation
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code. 
  - I have read the Contributing Guide - https://github.com/RocketChat/Rocket.Chat/blob/develop/.github/CONTRIBUTING.md#contributing-to-rocketchat doc
  - I have signed the CLA - https://cla-assistant.io/RocketChat/Rocket.Chat
  - Lint and unit tests pass locally with my changes
  - I have added tests that prove my fix is effective or that my feature works (if applicable)
  - I have added necessary documentation (if applicable)
  - Any dependent changes have been merged and published in downstream modules
-->

## Proposed changes (including videos or screenshots)
<!-- CHANGELOG -->
<!--
  Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
  If it fixes a bug or resolves a feature request, be sure to link to that issue below.
  This description will appear in the release notes if we accept the contribution.
-->
If the user sent a HTML message over our product to a livechat user the HTML would get rendered on the message box, this prevents it from happening.

<!-- END CHANGELOG -->

## Issue(s)
<!-- Link the issues being closed by or related to this PR. For example, you can use #594 if this PR closes issue number 594 -->

## Steps to test or reproduce
<!-- Mention how you would reproduce the bug if not mentioned on the issue page already. Also mention which screens are going to have the changes if applicable -->
try to send some html tags in livechat

## Further comments
<!-- If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -->

**Will be ready to review as soon as #25312 is merged**

Co-authored-by: Cauê Felchar <11652381+cauefcr@users.noreply.github.com>
  • Loading branch information
MartinSchoeler and cauefcr committed Jun 13, 2022
1 parent 949fcae commit f8065bf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions packages/livechat/src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { route } from 'preact-router';

import { Livechat } from '../api';
import { CallStatus, isCallOngoing } from '../components/Calls/CallStatus';
import { setCookies, upsert, canRenderMessage, parse } from '../components/helpers';
import { setCookies, upsert, canRenderMessage } from '../components/helpers';
import { store, initialState } from '../store';
import { normalizeAgent } from './api';
import Commands from './commands';
Expand Down Expand Up @@ -175,8 +175,6 @@ Livechat.onMessage(async (message) => {

message = transformAgentInformationOnMessage(message);

message.msg = parse(message.msg);

await store.setState({
messages: upsert(store.state.messages, message, ({ _id }) => _id === message._id, ({ ts }) => ts),
});
Expand Down
4 changes: 3 additions & 1 deletion packages/livechat/src/lib/threads.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Livechat } from '../api';
import { upsert } from '../components/helpers';
import { parse, upsert } from '../components/helpers';
import { store } from '../store';
import { createToken } from './random';

Expand Down Expand Up @@ -60,6 +60,8 @@ export const normalizeMessage = async (message) => {
return null;
}

message.msg = parse(message.msg);

if (message && message.tmid && !message.threadMsg) {
return normalizeThreadMessage(message);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/livechat/src/routes/Chat/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { withTranslation } from 'react-i18next';

import { Livechat } from '../../api';
import { ModalManager } from '../../components/Modal';
import { debounce, getAvatarUrl, canRenderMessage, throttle, upsert, parse } from '../../components/helpers';
import { debounce, getAvatarUrl, canRenderMessage, throttle, upsert } from '../../components/helpers';
import { normalizeQueueAlert } from '../../lib/api';
import constants from '../../lib/constants';
import { loadConfig } from '../../lib/main';
Expand Down Expand Up @@ -117,8 +117,6 @@ class ChatContainer extends Component {
return;
}

msg = parse(msg);

await this.grantUser();
const { _id: rid } = await this.getRoom();
const { alerts, dispatch, token, user } = this.props;
Expand Down

0 comments on commit f8065bf

Please sign in to comment.