Skip to content
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

add escape html to htmlContent on conversation list #589

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/anchore-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Build the Container image
run: |
docker build --build-arg APP_ENV=production \
--build-arg RUBY_VERSION=2.7.2 \
--build-arg RUBY_VERSION=2.7.5 \
--build-arg PG_MAJOR=11 \
--build-arg NODE_MAJOR=12 \
--build-arg YARN_VERSION=1.13.0 \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
build-args: |
"APP_ENV=production"
"NODE_ENV=production"
"RUBY_VERSION=2.7.2"
"RUBY_VERSION=2.7.5"
"PG_MAJOR=11"
"NODE_MAJOR=12"
"YARN_VERSION=1.13.0"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Build the Docker image
run: |
docker build --build-arg APP_ENV=production \
--build-arg RUBY_VERSION=2.7.2 \
--build-arg RUBY_VERSION=2.7.5 \
--build-arg PG_MAJOR=11 \
--build-arg NODE_MAJOR=12 \
--build-arg YARN_VERSION=1.13.0 \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rubocop-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.2
ruby-version: 2.7.5

# This step is not necessary if you add the gem to your Gemfile
# - name: Install Code Scanning integration
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.2
2.7.5
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "2.7.2"
ruby "2.7.5"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "pg"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ DEPENDENCIES
webpacker (~> 5.4.0)

RUBY VERSION
ruby 2.7.2p137
ruby 2.7.5p203

BUNDLED WITH
2.1.4
7 changes: 7 additions & 0 deletions app/javascript/packages/components/src/utils/htmlSanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ export default function extractContent(html) {
return new DOMParser().parseFromString(html, 'text/html').documentElement
.textContent;
}

export function escapeHTML(unsafe) {
return unsafe.replace(
/[\u0000-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00FF]/g,
(c) => '&#' + ('000' + c.charCodeAt(0)).substr(-4, 4) + ';'
);
}
6 changes: 4 additions & 2 deletions app/javascript/src/pages/conversations/ItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import { Link } from 'react-router-dom';
import Moment from 'react-moment';
import { readableColor } from 'polished';
import sanitizeHtml from '@chaskiq/components/src/utils/htmlSanitize';
import sanitizeHtml, {
escapeHTML,
} from '@chaskiq/components/src/utils/htmlSanitize';
import { LabelIcon } from '@chaskiq/components/src/components/icons';
import Avatar from '@chaskiq/components/src/components/Avatar';

Expand All @@ -16,7 +18,7 @@ export default function ConversationItemList({ app, conversation }) {
const renderConversationContent = (o) => {
const message = o.lastMessage.message;
if (message.htmlContent) {
return sanitizeHtml(message.htmlContent).substring(0, 250);
return sanitizeHtml(escapeHTML(message.htmlContent)).substring(0, 250);
}
};

Expand Down
23 changes: 13 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
version: '2.4'

x-app: &app
x-app:
&app
build:
context: .
dockerfile: ./Dockerfile.development
args:
RUBY_VERSION: '2.7.2'
RUBY_VERSION: '2.7.5'
PG_MAJOR: '11'
NODE_MAJOR: '12'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
environment: &env
environment:
&env
NODE_ENV: development
RAILS_ENV: ${RAILS_ENV:-development}
ANYCABLE_DEBUG: ${DEBUG:-0}
Expand All @@ -19,7 +21,8 @@ x-app: &app
tmpfs:
- /tmp

x-backend: &backend
x-backend:
&backend
<<: *app
stdin_open: true
tty: true
Expand Down Expand Up @@ -126,9 +129,9 @@ services:
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0

volumes:
postgres:
redis:
bundle:
node_modules:
rails_cache:
packs:
postgres: null
redis: null
bundle: null
node_modules: null
rails_cache: null
packs: null
2 changes: 1 addition & 1 deletion hooks/build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env sh

docker build --build-arg APP_ENV=production \
--build-arg RUBY_VERSION=2.7.2 \
--build-arg RUBY_VERSION=2.7.5 \
--build-arg PG_MAJOR=11 \
--build-arg NODE_MAJOR=12 \
--build-arg YARN_VERSION=1.13.0 \
Expand Down