{"record":{"id":"c71bc4d7cbfdccf0","repo":"kgretzky/evilginx2","slug":"session-id-not-found-d","errorCode":null,"errorMessage":"session ID not found: %d","messagePattern":"session ID not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/db_session.go","lineNumber":197,"sourceCode":"func (d *Database) sessionsDelete(id int) error {\n\terr := d.db.Update(func(tx *buntdb.Tx) error {\n\t\t_, err := tx.Delete(d.genIndex(SessionTable, id))\n\t\treturn err\n\t})\n\treturn err\n}\n\nfunc (d *Database) sessionsGetById(id int) (*Session, error) {\n\ts := &Session{}\n\terr := d.db.View(func(tx *buntdb.Tx) error {\n\t\tfound := false\n\t\terr := tx.AscendEqual(\"sessions_id\", d.getPivot(map[string]int{\"id\": id}), func(key, val string) bool {\n\t\t\tjson.Unmarshal([]byte(val), s)\n\t\t\tfound = true\n\t\t\treturn false\n\t\t})\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"session ID not found: %d\", id)\n\t\t}\n\t\treturn err\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn s, nil\n}\n\nfunc (d *Database) sessionsGetBySid(sid string) (*Session, error) {\n\ts := &Session{}\n\terr := d.db.View(func(tx *buntdb.Tx) error {\n\t\tfound := false\n\t\terr := tx.AscendEqual(\"sessions_sid\", d.getPivot(map[string]string{\"session_id\": sid}), func(key, val string) bool {\n\t\t\tjson.Unmarshal([]byte(val), s)\n\t\t\tfound = true\n\t\t\treturn false\n\t\t})","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/kgretzky/evilginx2/blob/4c0988a1d9db4d172a185e979a38bfd0efdb5830/database/db_session.go#L179-L215","documentation":"Returned by the by-ID session lookup (sessionsGetById path) when a buntdb transaction iterates the sessions_id index with AscendEqual for the given numeric id and no record matches. It means no Session with that integer Id exists in the database. The lookup found the index but zero entries equaled the pivot.","triggerScenarios":"Calling GetSessionById (or anything that resolves a session by numeric Id, e.g. sessionsUpdate with a stale Id) with an id that was never created or was already deleted via session deletion/cleanup of expired sessions.","commonSituations":"A caller caches a Session.Id from a previous run and the database file was reset or the session was purged; passing a user-supplied numeric id that doesn't exist; off-by-one/derived ids (e.g. id from getNextId) used before creation completed.","solutions":["Verify the id exists by listing sessions (sessionsList) before fetching by id","Prefer lookups by session_id string (GetSessionBySid) if that is the stable identifier in your flow","Re-fetch the id from the current CreateSession result instead of reusing a cached one","Handle the error as 'session expired/purged' and re-create or re-authenticate the session"],"exampleFix":"// before\ns, err := db.GetSessionById(cachedID)\nif err != nil { return err }\n// after\ns, err := db.GetSessionById(cachedID)\nif err != nil {\n    // session no longer exists; obtain a fresh one\n    return handleExpiredSession(cachedID)\n}","handlingStrategy":"try-catch","validationCode":"sessions, err := db.GetSessions()\nif err == nil {\n    known := false\n    for _, s := range sessions {\n        if s.Id == wantedID { known = true; break }\n    }\n    if !known { return fmt.Errorf(\"id %d not present\", wantedID) }\n}","typeGuard":"func sessionExists(db *database.Database, id int) bool {\n    _, err := db.GetSessionById(id)\n    return err == nil\n}","tryCatchPattern":"s, err := db.GetSessionById(id)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"session ID not found\") {\n        return nil, ErrSessionExpired\n    }\n    return nil, err\n}","preventionTips":["Treat Session.Id as ephemeral; never persist it across restarts","Resolve sessions by session_id string when possible","Re-check existence after any delete/purge operation before further use"],"tags":["go","database","buntdb","not-found","session-management"],"backgroundTag":"record-not-found","analyzedSha":"4c0988a1d9db4d172a185e979a38bfd0efdb5830","analyzedAt":"2026-09-05T19:23:07.238Z","contentChangedAt":"2026-09-05T19:23:07.238Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}