Skip to content

Commit

Permalink
Sanitize more strings (#42)
Browse files Browse the repository at this point in the history
Add string escaping to prevent XSS in several places.
  • Loading branch information
jakozaur authored May 6, 2024
1 parent fc42b89 commit 9c79ce4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions quesma/quesma/ui/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (qmc *QuesmaManagementConsole) generateDashboardPanel() []byte {

buffer.Html(`<div id="dashboard-kibana" class="component">`)
if qmc.config.Elasticsearch.AdminUrl != nil {
buffer.Html(fmt.Sprintf(`<a href="%s">`, qmc.config.Elasticsearch.AdminUrl.String()))
buffer.Html(fmt.Sprintf(`<a href="%s">`, url.PathEscape(qmc.config.Elasticsearch.AdminUrl.String())))
}
buffer.Html(dashboardName)
if qmc.config.Elasticsearch.AdminUrl != nil {
Expand All @@ -161,7 +161,7 @@ func (qmc *QuesmaManagementConsole) generateDashboardPanel() []byte {

buffer.Html(`<div id="dashboard-clickhouse" class="component">`)
if qmc.config.ClickHouse.AdminUrl != nil {
buffer.Html(fmt.Sprintf(`<a href="%s">`, qmc.config.ClickHouse.AdminUrl.String()))
buffer.Html(fmt.Sprintf(`<a href="%s">`, url.PathEscape(qmc.config.ClickHouse.AdminUrl.String())))
}
buffer.Html(clickhouseName)
if qmc.config.ClickHouse.AdminUrl != nil {
Expand All @@ -184,7 +184,7 @@ func (qmc *QuesmaManagementConsole) generateDashboardPanel() []byte {
cpuStr = fmt.Sprintf("Host CPU: N/A (error: %s)", err0.Error())
}

buffer.Html(fmt.Sprintf(`<div class="status">%s</div>`, cpuStr))
buffer.Html(`<div class="status">`).Text(cpuStr).Html(`</div>`)

var m runtime.MemStats
runtime.ReadMemStats(&m)
Expand All @@ -193,7 +193,7 @@ func (qmc *QuesmaManagementConsole) generateDashboardPanel() []byte {
total := float64(v.Total) / 1024.0 / 1024.0 / 1024.0
memStr += fmt.Sprintf(", avail: %.1f GB", total)
}
buffer.Html(fmt.Sprintf(`<div class="status">%s</div>`, memStr))
buffer.Html(`<div class="status">`).Text(memStr).Html(`</div>`)

duration := uint64(time.Since(qmc.startedAt).Seconds())

Expand Down
11 changes: 5 additions & 6 deletions quesma/quesma/ui/data_sources.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ui

import (
"fmt"
"mitmproxy/quesma/quesma/ui/internal/builder"
"slices"
"strings"
Expand Down Expand Up @@ -44,11 +43,11 @@ func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
tables := qmc.logManager.GetTableDefinitions()
slices.Sort(tableNames)
for _, tableName := range tableNames {
buffer.Html(`<li>`).Text(tableName)
if _, exist := tables.Load(tableName); exist {
buffer.Html(fmt.Sprintf(`<li>%s (table exists)</li>`, tableName))
} else {
buffer.Html(fmt.Sprintf(`<li>%s</li>`, tableName))
buffer.Html(` (table exists)`)
}
buffer.Html(`</li>`)
}
buffer.Html(`</ul>`)

Expand All @@ -70,14 +69,14 @@ func (qmc *QuesmaManagementConsole) generateDatasources() []byte {
slices.Sort(indexNames)
slices.Sort(internalIndexNames)
for _, indexName := range indexNames {
buffer.Html(fmt.Sprintf(`<li>%s</li>`, indexName))
buffer.Html(`<li>`).Text(indexName).Html(`</li>`)
}

if len(internalIndexNames) > 0 {
buffer.Html(`<ul>`)

for _, indexName := range internalIndexNames {
buffer.Html(fmt.Sprintf(`<li><small>%s</small></li>`, indexName))
buffer.Html(`<li><small>`).Text(indexName).Html(`</small></li>`)
}
buffer.Html(`</ul>`)
}
Expand Down
3 changes: 2 additions & 1 deletion quesma/quesma/ui/unsupported_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"mitmproxy/quesma/model"
"mitmproxy/quesma/quesma/ui/internal/builder"
"mitmproxy/quesma/tracing"
"net/url"
"regexp"
"sort"
)
Expand Down Expand Up @@ -74,7 +75,7 @@ func (qmc *QuesmaManagementConsole) generateReportForUnsupportedRequests() []byt
buffer.Html(`<h3>Unsupported queries by type</h3>`)
buffer.Html(`<ul id="unsupported-queries-stats">`)
for _, t := range slice {
buffer.Html(fmt.Sprintf(`<li><a class="debug-warn-log" href="/unsupported-requests/%s">`, t.name))
buffer.Html(fmt.Sprintf(`<li><a class="debug-warn-log" href="/unsupported-requests/%s">`, url.PathEscape(t.name)))
buffer.Text(fmt.Sprintf(`%s: %d`, t.name, t.count))
buffer.Html("</a></li>\n")
}
Expand Down

0 comments on commit 9c79ce4

Please sign in to comment.