Skip to content

Commit

Permalink
(BIDS-2417) Changed wrong user input to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisei24 committed Sep 6, 2023
1 parent d7d21fd commit f5193f4
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 207 deletions.
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ func saveBlocks(blocks map[uint64]map[string]*types.Block, tx *sqlx.Tx, forceSlo
b.Signature,
b.RandaoReveal,
b.Graffiti,
utils.GraffitiToSring(b.Graffiti),
utils.GraffitiToString(b.Graffiti),
b.Eth1Data.DepositRoot,
b.Eth1Data.DepositCount,
b.Eth1Data.BlockHash,
Expand Down
4 changes: 2 additions & 2 deletions handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ func SetDataTableStateChanges(w http.ResponseWriter, r *http.Request) {
settings := types.DataTableSaveState{}
err = json.NewDecoder(r.Body).Decode(&settings)
if err != nil {
utils.LogError(err, errMsgPrefix+", could not parse body", 0, errFields)
w.WriteHeader(http.StatusInternalServerError)
logger.Warnf(errMsgPrefix+", could not parse body for tableKey %v: %v", tableKey, err)
w.WriteHeader(http.StatusBadRequest)
return
}

Expand Down
8 changes: 4 additions & 4 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,14 @@ func DashboardDataWithdrawals(w http.ResponseWriter, r *http.Request) {

draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
utils.LogError(err, fmt.Errorf("error converting datatables data parameter from string to int: %v", err), 0)
http.Error(w, "Internal server error", http.StatusInternalServerError)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
utils.LogError(err, fmt.Errorf("error converting datatables data parameter from string to int: %v", err), 0)
http.Error(w, "Internal server error", http.StatusInternalServerError)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}

Expand Down
12 changes: 6 additions & 6 deletions handlers/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ func EpochsData(w http.ResponseWriter, r *http.Request) {

draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
12 changes: 6 additions & 6 deletions handlers/eth1Blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ func Eth1BlocksData(w http.ResponseWriter, r *http.Request) {
}
draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int for route %v: %v", r.URL.String(), err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
24 changes: 12 additions & 12 deletions handlers/eth1Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ func Eth1DepositsData(w http.ResponseWriter, r *http.Request) {

draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down Expand Up @@ -171,20 +171,20 @@ func Eth1DepositsLeaderboardData(w http.ResponseWriter, r *http.Request) {

draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
2 changes: 1 addition & 1 deletion handlers/eth1tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Eth1TransactionTx(w http.ResponseWriter, r *http.Request) {

txHash, err := hex.DecodeString(strings.ReplaceAll(txHashString, "0x", ""))
if err != nil {
logger.Errorf("error parsing tx hash %v: %v", txHashString, err)
logger.Warnf("error parsing tx hash %v: %v", txHashString, err)
data = InitPageData(w, r, "blockchain", path, title, txNotFoundTemplateFiles)
txTemplate = txNotFoundTemplate
} else {
Expand Down
12 changes: 6 additions & 6 deletions handlers/eth2Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func Eth2DepositsData(w http.ResponseWriter, r *http.Request) {

draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand Down
3 changes: 2 additions & 1 deletion handlers/graffitiwall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"eth2-exporter/db"
"eth2-exporter/templates"
"eth2-exporter/types"
"eth2-exporter/utils"
"net/http"
)

Expand All @@ -21,7 +22,7 @@ func Graffitiwall(w http.ResponseWriter, r *http.Request) {
err = db.ReaderDb.Select(&graffitiwallData, "SELECT DISTINCT ON (x, y) x, y, color, slot, validator from graffitiwall ORDER BY x, y, slot DESC")

if err != nil {
logger.Errorf("error retrieving block tree data: %v", err)
utils.LogError(err, "error retrieving graffitiwall data", 0)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
}
Expand Down
76 changes: 52 additions & 24 deletions handlers/pools_rocketpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ func PoolsRocketpoolDataMinipools(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand All @@ -56,6 +56,13 @@ func PoolsRocketpoolDataMinipools(w http.ResponseWriter, r *http.Request) {
search = search[:128]
}

// Search for invalid postgres strings
if utils.HasProblematicUtfCharacters(search) || strings.HasSuffix(search, "\\") {
logger.Warnf("error converting search %v to valid UTF-8): %v", search, err)
http.Error(w, "Error: Invalid parameter search.", http.StatusBadRequest)
return
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "address",
Expand Down Expand Up @@ -188,20 +195,20 @@ func PoolsRocketpoolDataNodes(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand All @@ -212,6 +219,13 @@ func PoolsRocketpoolDataNodes(w http.ResponseWriter, r *http.Request) {
search = search[:128]
}

// Search for invalid postgres strings
if utils.HasProblematicUtfCharacters(search) || strings.HasSuffix(search, "\\") {
logger.Warnf("error converting search %v to valid UTF-8): %v", search, err)
http.Error(w, "Error: Invalid parameter search.", http.StatusBadRequest)
return
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "address",
Expand Down Expand Up @@ -332,20 +346,20 @@ func PoolsRocketpoolDataDAOProposals(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand All @@ -356,6 +370,13 @@ func PoolsRocketpoolDataDAOProposals(w http.ResponseWriter, r *http.Request) {
search = search[:128]
}

// Search for invalid postgres strings
if utils.HasProblematicUtfCharacters(search) || strings.HasSuffix(search, "\\") {
logger.Warnf("error converting search %v to valid UTF-8): %v", search, err)
http.Error(w, "Error: Invalid parameter search.", http.StatusBadRequest)
return
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "id",
Expand Down Expand Up @@ -545,20 +566,20 @@ func PoolsRocketpoolDataDAOMembers(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
draw, err := strconv.ParseUint(q.Get("draw"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables data parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables draw parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter draw", http.StatusBadRequest)
return
}
start, err := strconv.ParseUint(q.Get("start"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables start parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter start", http.StatusBadRequest)
return
}
length, err := strconv.ParseUint(q.Get("length"), 10, 64)
if err != nil {
logger.Errorf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
logger.Warnf("error converting datatables length parameter from string to int: %v", err)
http.Error(w, "Error: Missing or invalid parameter length", http.StatusBadRequest)
return
}
if length > 100 {
Expand All @@ -569,6 +590,13 @@ func PoolsRocketpoolDataDAOMembers(w http.ResponseWriter, r *http.Request) {
search = search[:128]
}

// Search for invalid postgres strings
if utils.HasProblematicUtfCharacters(search) || strings.HasSuffix(search, "\\") {
logger.Warnf("error converting search %v to valid UTF-8): %v", search, err)
http.Error(w, "Error: Invalid parameter search.", http.StatusBadRequest)
return
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "address",
Expand Down
Loading

0 comments on commit f5193f4

Please sign in to comment.