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

Sweep: Cross-site scripting in username edit field (βœ“ Sandbox Passed) #315

Closed
5 changes: 3 additions & 2 deletions src/components/common/EditableSpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './css/editableSpan.css';
import React, {PureComponent} from 'react';
import _ from 'lodash';
import Caret from '../../lib/caret';
import { sanitizeInput } from '../../utils/sanitizeInput';

export default class EditableSpan extends PureComponent {
constructor() {
Expand Down Expand Up @@ -48,7 +49,7 @@ export default class EditableSpan extends PureComponent {
let result = value;
const nbsp = String.fromCharCode('160');
while (result.indexOf(' ') !== -1) {
result = result.replace(' ', nbsp);
result = result.replaceAll(' ', nbsp);
}
return result;
}
Expand All @@ -69,7 +70,7 @@ export default class EditableSpan extends PureComponent {
if (this.props.hidden) return;
if (this.text === val) return;
// set text while retaining cursor position
this.span.current.innerHTML = val;
this.span.current.innerHTML = sanitizeInput(val);
}

handleFocus = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/sanitizeInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sanitizeInput(input) {
return input.replace(/<\/?[^>]+(>|$)/g, "");
}