mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-15 16:50:16 +01:00
hints: prevent malicious timestamp hints to bork calculations.
This commit is contained in:
@@ -27,6 +27,10 @@ func NewHintDB() *HintDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *HintDB) Save(pubkey string, relay string, key hints.HintKey, ts nostr.Timestamp) {
|
func (db *HintDB) Save(pubkey string, relay string, key hints.HintKey, ts nostr.Timestamp) {
|
||||||
|
if now := nostr.Now(); ts > now {
|
||||||
|
ts = now
|
||||||
|
}
|
||||||
|
|
||||||
relayIndex := slices.Index(db.RelayBySerial, relay)
|
relayIndex := slices.Index(db.RelayBySerial, relay)
|
||||||
if relayIndex == -1 {
|
if relayIndex == -1 {
|
||||||
relayIndex = len(db.RelayBySerial)
|
relayIndex = len(db.RelayBySerial)
|
||||||
|
|||||||
@@ -87,11 +87,15 @@ func (sh SQLiteHints) TopN(pubkey string, n int) []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh SQLiteHints) Save(pubkey string, relay string, key hints.HintKey, score nostr.Timestamp) {
|
func (sh SQLiteHints) Save(pubkey string, relay string, key hints.HintKey, ts nostr.Timestamp) {
|
||||||
_, err := sh.saves[key].Exec(pubkey, relay, score, score)
|
if now := nostr.Now(); ts > now {
|
||||||
|
ts = now
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := sh.saves[key].Exec(pubkey, relay, ts, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nostr.InfoLogger.Printf("[sdk/hints/sqlite] unexpected error on insert for %s, %s, %d: %s\n",
|
nostr.InfoLogger.Printf("[sdk/hints/sqlite] unexpected error on insert for %s, %s, %d: %s\n",
|
||||||
pubkey, relay, score, err)
|
pubkey, relay, ts, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user