fix for possible xss exploits

This commit is contained in:
or-else
2019-08-17 16:56:15 +03:00
parent be528ff282
commit c14fb857bc
7 changed files with 86 additions and 19 deletions
+3 -3
View File
@@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import FileProgress from './file-progress.jsx';
import { bytesToHumanSize } from '../lib/strformat.js';
import { isUrlRelative, sanitizeUrl } from '../lib/utils.js';
export default class Attachment extends React.Component {
constructor(props) {
@@ -53,8 +54,7 @@ export default class Attachment extends React.Component {
// If the URL is relative use LargeFileHelper to attach authentication
// credentials to the request.
let url, helperFunc;
if (!this.props.uploader && !this.state.downloader &&
!(/^(?:(?:[a-z]+:)?\/\/)/i.test(this.props.downloadUrl))) {
if (!this.props.uploader && !this.state.downloader && isUrlRelative(this.props.downloadUrl)) {
// Relative URL. Use download helper.
url = '#';
helperFunc = (e) => {
@@ -62,7 +62,7 @@ export default class Attachment extends React.Component {
this.downloadFile(this.props.downloadUrl, this.props.filename, this.props.mimetype);
};
} else {
url = this.props.downloadUrl;
url = sanitizeUrl(this.props.downloadUrl) || 'about:blank';
helperFunc = null;
}
return (
+3 -1
View File
@@ -6,6 +6,7 @@ import { Drafty } from 'tinode-sdk'
import Attachment from './attachment.jsx';
import LetterTile from './letter-tile.jsx';
import ReceivedMarker from './received-marker.jsx'
import { sanitizeUrl } from '../lib/utils.js';
export default class ChatMessage extends React.Component {
constructor(props) {
@@ -48,7 +49,7 @@ export default class ChatMessage extends React.Component {
e.target.dataset.val === undefined ? 1 : '' + e.target.dataset.val;
}
if (e.target.dataset.act == 'url') {
data.ref = '' + e.target.dataset.ref;
data.ref = sanitizeUrl(e.target.dataset.ref) || 'about:blank';
}
const text = e.target.dataset.title || 'unknown';
this.props.onFormResponse(e.target.dataset.act, text, data);
@@ -163,6 +164,7 @@ function draftyFormatter(style, data, values, key) {
Math.min(this.props.viewportWidth - REM_SIZE * 4, REM_SIZE * 36), REM_SIZE * 24, false);
dim = dim || {dstWidth: BROKEN_IMAGE_SIZE, dstHeight: BROKEN_IMAGE_SIZE};
attr.style = { width: dim.dstWidth + 'px', height: dim.dstHeight + 'px' };
attr.src = sanitizeUrl(attr.src);
if (attr.src) {
attr.onClick = this.handlePreviewImage;
attr.className += ' image-clickable';