Skip to content

Commit 43fc74c

Browse files
committed
HTML escape certificate fields
WE2-926 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 1e6e8cc commit 43fc74c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/controller/command-handlers/certificatereader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const CardInfo::ptr& c
7878
CertificateReader::CertificateReader(const CommandWithArguments& cmd) : CommandHandler(cmd)
7979
{
8080
validateAndStoreOrigin(cmd.second);
81-
if (Application* app = qobject_cast<Application*>(qApp)) {
81+
if (auto* app = qobject_cast<Application*>(qApp)) {
8282
app->loadTranslations(cmd.second.value(QStringLiteral("lang")).toString());
8383
}
8484
}
@@ -142,7 +142,7 @@ void CertificateReader::validateAndStoreOrigin(const QVariantMap& arguments)
142142
|| origin.hasFragment()) {
143143
THROW(CommandHandlerInputDataError, "origin is not in <scheme>://<host>[:<port>] format");
144144
}
145-
if (origin.scheme() != QStringLiteral("https") && origin.scheme() != QStringLiteral("wss")) {
145+
if (origin.scheme() != QLatin1String("https") && origin.scheme() != QLatin1String("wss")) {
146146
THROW(CommandHandlerInputDataError, "origin scheme has to be https or wss");
147147
}
148148
}

src/ui/certificatewidget.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ CardCertificateAndPinInfo CertificateWidgetInfo::certificateInfo() const
7878

7979
std::tuple<QString, QString, QString> CertificateWidgetInfo::certData() const
8080
{
81-
return {certAndPinInfo.certificate.issuerInfo(QSslCertificate::CommonName).join(' '),
81+
return {certAndPinInfo.certificate.issuerInfo(QSslCertificate::CommonName)
82+
.join(' ')
83+
.toHtmlEscaped(),
8284
certAndPinInfo.certificate.effectiveDate().date().toString(Qt::ISODate),
8385
certAndPinInfo.certificate.expiryDate().date().toString(Qt::ISODate)};
8486
}
@@ -110,8 +112,9 @@ void CertificateWidgetInfo::setCertificateInfo(const CardCertificateAndPinInfo&
110112
expiryDate = displayInRed(expiryDate);
111113
warning = displayInRed(CertificateWidget::tr(" (Expired)"));
112114
}
113-
info->setText(CertificateWidget::tr("<b>%1</b><br />Issuer: %2<br />Valid: %3 to %4%5")
114-
.arg(certInfo.subject, issuer, effectiveDate, expiryDate, warning));
115+
info->setText(
116+
CertificateWidget::tr("<b>%1</b><br />Issuer: %2<br />Valid: %3 to %4%5")
117+
.arg(certInfo.subject.toHtmlEscaped(), issuer, effectiveDate, expiryDate, warning));
115118
info->parentWidget()->setDisabled(certInfo.notEffective || certInfo.isExpired
116119
|| cardCertPinInfo.pinInfo.pinIsBlocked);
117120
if (warning.isEmpty() && cardCertPinInfo.pinInfo.pinIsBlocked) {
@@ -174,7 +177,7 @@ void CertificateButton::setCertificateInfo(const CardCertificateAndPinInfo& card
174177
const auto& certInfo = cardCertPinInfo.certInfo;
175178
auto [issuer, effectiveDate, expiryDate] = certData();
176179
setText(tr("%1 Issuer: %2 Valid: %3 to %4")
177-
.arg(certInfo.subject, issuer, effectiveDate, expiryDate));
180+
.arg(certInfo.subject.toHtmlEscaped(), issuer, effectiveDate, expiryDate));
178181
}
179182

180183
void CertificateButton::paintEvent(QPaintEvent* /*event*/)

0 commit comments

Comments
 (0)