mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-16 08:52:42 +00:00
Forex/camp review hardening: bound CoinGecko body, escape URL params, fail-open camp on DB error
- forex_crypto.go: cap the CoinGecko response with io.LimitReader(64KiB); build the simple/price query via url.Values instead of bare Sprintf. - dnd_expedition_camp.go: a combat-session lookup error now fails open (allow camp) + logs a warning, instead of blocking standard camp with a misleading empty 'not cleared' rejection.
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -82,8 +84,11 @@ func (p *ForexPlugin) cgSpotUSD(sym string) (float64, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
||||
defer cancel()
|
||||
|
||||
url := fmt.Sprintf("%s/simple/price?ids=%s&vs_currencies=usd", coinGeckoBaseURL, info.CoinGeckoID)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
q := url.Values{}
|
||||
q.Set("ids", info.CoinGeckoID)
|
||||
q.Set("vs_currencies", "usd")
|
||||
reqURL := coinGeckoBaseURL + "/simple/price?" + q.Encode()
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -99,7 +104,7 @@ func (p *ForexPlugin) cgSpotUSD(sym string) (float64, error) {
|
||||
}
|
||||
|
||||
var data map[string]map[string]float64
|
||||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
if err := json.NewDecoder(io.LimitReader(resp.Body, 64<<10)).Decode(&data); err != nil {
|
||||
return 0, fmt.Errorf("coingecko decode error: %w", err)
|
||||
}
|
||||
entry, ok := data[info.CoinGeckoID]
|
||||
|
||||
Reference in New Issue
Block a user