Skip to content

Commit

Permalink
Fix code security issue: CWE-79, CWE-116, CWE-190 and CWE-681
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jul 24, 2021
1 parent e27df2a commit a935e08
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion cookies.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTube.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTubeJobs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTubeJobsActionsRow.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTubeJobsShowcase.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTubeJobsSummaryTable.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion currentTubeSearchResults.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
19 changes: 10 additions & 9 deletions handlers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand All @@ -12,6 +12,7 @@
package main

import (
"html"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -53,15 +54,15 @@ func handlerServer(w http.ResponseWriter, r *http.Request) {
action := r.URL.Query().Get("action")
switch action {
case "reloader":
_, _ = io.WriteString(w, getServerTubes(server))
_, _ = io.WriteString(w, html.EscapeString(getServerTubes(server)))
return
case "clearTubes":
_ = r.ParseForm()
clearTubes(server, r.Form)
_, _ = io.WriteString(w, `{"result":true}`)
return
}
_, _ = io.WriteString(w, tplServer(getServerTubes(server), server))
_, _ = io.WriteString(w, html.EscapeString(tplServer(getServerTubes(server), server)))
}

// handlerTube handle request on router: /tube
Expand All @@ -79,7 +80,7 @@ func handlerTube(w http.ResponseWriter, r *http.Request) {
return
case "search":
content := searchTube(server, tube, r.URL.Query().Get("limit"), r.URL.Query().Get("searchStr"))
_, _ = io.WriteString(w, tplTube(content, server, tube))
_, _ = io.WriteString(w, html.EscapeString(tplTube(content, server, tube)))
return
case "addSample":
_ = r.ParseForm()
Expand Down Expand Up @@ -137,7 +138,7 @@ func handleRedirect(w http.ResponseWriter, r *http.Request, server string, tube
w.Header().Set("Location", link.String())
w.WriteHeader(307)
}
_, _ = io.WriteString(w, tplTube(currentTube(server, tube), server, tube))
_, _ = io.WriteString(w, html.EscapeString(tplTube(currentTube(server, tube), server, tube)))
}

// handlerSample handle request on router: /sample
Expand All @@ -148,13 +149,13 @@ func handlerSample(w http.ResponseWriter, r *http.Request) {
server := r.URL.Query().Get("server")
switch action {
case "manageSamples":
_, _ = io.WriteString(w, tplSampleJobsManage(getSampleJobList(), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(getSampleJobList(), server)))
return
case "newSample":
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", ""), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", ""), server)))
return
case "editSample":
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit(r.URL.Query().Get("key"), ""), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit(r.URL.Query().Get("key"), ""), server)))
return
case "actionNewSample":
_ = r.ParseForm()
Expand Down Expand Up @@ -191,5 +192,5 @@ func handlerStatistics(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, statisticWaitress(server, tube))
return
}
_, _ = io.WriteString(w, tplStatistic(server, tube))
_, _ = io.WriteString(w, html.EscapeString(tplStatistic(server, tube)))
}
16 changes: 10 additions & 6 deletions lib.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand All @@ -12,6 +12,7 @@
package main

import (
"math"
"net/url"
"strconv"
"strings"
Expand All @@ -22,11 +23,14 @@ import (

// addJob puts a job into tube by given config.
func addJob(server string, tube string, data string, priority string, delay string, TTR string) {
var err error
var tubePriority, tubeDelay, tubeTTR int
var bstkConn *beanstalk.Conn
tubePriority, err = strconv.Atoi(priority)
if err != nil {
var (
err error
tubeDelay, tubeTTR int
tubePriority uint64
bstkConn *beanstalk.Conn
)
tubePriority, err = strconv.ParseUint(priority, 10, 32)
if err != nil || tubePriority > math.MaxUint32 {
tubePriority = DefaultPriority
}
tubeDelay, err = strconv.Atoi(delay)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:generate statik -src=./public

// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion modalAddJob.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion modalAddSample.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion modalClearTubes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
12 changes: 6 additions & 6 deletions sampleJobUtils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down Expand Up @@ -261,7 +261,7 @@ func newSample(server string, f url.Values, w http.ResponseWriter, r *http.Reque
alert := `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> Required fields are not set</span></div>`
err = readConf()
if err != nil {
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> Read config error</span></div>`), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> Read config error</span></div>`), server)))
return
}
for k, v := range f {
Expand All @@ -281,16 +281,16 @@ func newSample(server string, f url.Values, w http.ResponseWriter, r *http.Reque
}
}
if len(tubes) == 0 || name == "" || body == "" || ttr == "" {
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", alert), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", alert), server)))
return
}
if checkSampleJobs(name) {
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> You already have a job with this name</span></div>`), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> You already have a job with this name</span></div>`), server)))
return
}
sampleTTR, err = strconv.Atoi(ttr)
if err != nil {
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> You should give a correct TTR with this sample</span></div>`), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> You should give a correct TTR with this sample</span></div>`), server)))
return
}
sampleJobs.Jobs = append(sampleJobs.Jobs, SampleJob{
Expand All @@ -302,7 +302,7 @@ func newSample(server string, f url.Values, w http.ResponseWriter, r *http.Reque
})
err = saveSample()
if err != nil {
_, _ = io.WriteString(w, tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> Save sample job error</span></div>`), server))
_, _ = io.WriteString(w, html.EscapeString(tplSampleJobsManage(tplSampleJobEdit("", `<div class="alert alert-danger" id="sjsa"><button type="button" class="close" onclick="$('#sjsa').fadeOut('fast');">×</button><span> Save sample job error</span></div>`), server)))
return
}
w.Header().Set("Location", "./sample?action=manageSamples")
Expand Down
2 changes: 1 addition & 1 deletion statisticsUtils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion structs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplFilter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplMain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplNav.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplSampleJobEdit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplSampleJobsManage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplSearchTube.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplServer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplStatistic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplStatisticEdit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplStatisticSetting.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion tplTube.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
Expand Down

0 comments on commit a935e08

Please sign in to comment.