Skip to content
Closed
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
24 changes: 23 additions & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ CServer::CServer ( const int iNewMaxNumChan,
QThreadPool::globalInstance()->setMaxThreadCount ( QThread::idealThreadCount() * 4 );
}

// initialize chat html sanitization patterns:
static QList<QString> qlPermittedChatTagNames = {
"b",
"i",
"p",
"pre",
"u",
};
foreach ( auto tag, qlPermittedChatTagNames )
{
QRegExp pattern = QRegExp ( "&lt;(" + tag + ")&gt;([^<>]+)&lt;/" + tag + "&gt;" );
pattern.setMinimal ( true ); // non-greedy matching
Copy link
Copy Markdown
Member

@softins softins May 1, 2021

Choose a reason for hiding this comment

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

Suggest it might be a good idea also to add the following:

pattern.setCaseSensitivity(Qt::CaseInsensitive);  // allow upper or lower case tags

Just in case the user is pasting in HTML that happens to use upper-case tags.

qlPermittedChatTagPatterns << pattern;
}

// Connections -------------------------------------------------------------
// connect timer timeout signal
Expand Down Expand Up @@ -1475,11 +1489,19 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID
// use different colors
QString sCurColor = vstrChatColors[iCurChanID % vstrChatColors.Size()];

// escape all html tags, but selectively allow safe tags again:
QString strChatTextFiltered = strChatText.toHtmlEscaped();
foreach ( auto pattern, qlPermittedChatTagPatterns )
{
strChatTextFiltered = strChatTextFiltered.replace ( pattern, "<\\1>\\2</\\1>" );
}
strChatTextFiltered = strChatTextFiltered.replace ( "&lt;br&gt;", "<br>" );

const QString strActualMessageText =
"<font color=\"" + sCurColor + "\">(" +
QTime::currentTime().toString ( "hh:mm:ss AP" ) + ") <b>" +
ChanName.toHtmlEscaped() +
"</b></font> " + strChatText.toHtmlEscaped();
"</b></font> " + strChatTextFiltered;


// Send chat text to all connected clients ---------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class CServer :

CSignalHandler* pSignalHandler;

QList<QRegExp> qlPermittedChatTagPatterns;

signals:
void Started();
void Stopped();
Expand Down