{"record":{"id":"d4275b785da90a3f","repo":"anomalyco/sst","slug":"panic-err-d4275b","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/id/id.go","lineNumber":33,"sourceCode":"func Descending() string {\n\treturn generateID(true)\n}\n\nfunc generateID(descending bool) string {\n\tnow := time.Now().UnixMilli()\n\tif descending {\n\t\tnow = ^now\n\t}\n\n\ttimeBytes := make([]byte, 6)\n\tfor i := 0; i < 6; i++ {\n\t\ttimeBytes[i] = byte(now >> (40 - 8*i))\n\t}\n\n\trandomBytes := make([]byte, (LENGTH-12)/2)\n\t_, err := rand.Read(randomBytes)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tresult := make([]byte, LENGTH)\n\thex.Encode(result[:12], timeBytes)\n\thex.Encode(result[12:], randomBytes)\n\n\treturn string(result)\n}\n","sourceCodeStart":15,"sourceCodeEnd":42,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/id/id.go#L15-L42","documentation":"pkg/id generates 24-character time-sortable IDs, combining the current timestamp with bytes read from crypto/rand. crypto/rand.Read fails only when the operating system's cryptographic entropy source is unavailable; the library treats this as unrecoverable (IDs must be unpredictable) and panics. Ascending() and Descending() both funnel through generateID, so any caller panics.","triggerScenarios":"Any call to id.Ascending() or id.Descending() when crypto/rand.Read errors — practically only when the OS CSPRNG is unavailable: a sealed /dev/urandom-less container, getrandom(2) returning ENOSYS/EAGAIN repeatedly, or an extremely restricted seccomp/AppArmor profile blocking getrandom.","commonSituations":"Minimal Docker containers with restricted syscalls (seccomp profiles blocking getrandom on old Docker + new kernels); embedded/unusual Linux setups without a functional entropy pool; sandboxed CI environments.","solutions":["Restore access to the OS entropy source: allow the getrandom syscall in the container/seccomp profile or mount /dev/urandom","Upgrade the container runtime/seccomp profile (e.g. docker>=20.10 default profiles allow getrandom)","Rerun the process on a host with a working CSPRNG — verify with `head -c 16 /dev/urandom | xxd`","If you control the code, replace panic with error propagation, though SST treats RNG failure as fatal by design"],"exampleFix":"// before (seccomp profile json)\n\"syscalls\": [{ \"names\": [\"getrandom\"], \"action\": \"SCMP_ACT_ERRNO\" }]\n// after\nremove the getrandom deny rule, or run with: docker run --security-opt seccomp=default.json ...","handlingStrategy":"try-catch","validationCode":"// verify the CSPRNG is reachable before invoking sst code paths that generate IDs\nf, err := os.Open(\"/dev/urandom\")\nif err != nil {\n    return fmt.Errorf(\"entropy source unavailable: %w\", err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"// cannot recover from the panic itself (library-level); guard the calling operation and surface a clear message:\nfunc safeAscending() (id string, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"id generation failed (check CSPRNG/seccomp getrandom): %v\", r)\n        }\n    }()\n    return id.Ascending(), nil\n}","preventionTips":["Allow the getrandom syscall in container seccomp/AppArmor profiles","Keep /dev/urandom mounted in minimal containers","Test ID-generation-dependent code paths in the same sandbox used in production","Pin a modern container runtime whose default seccomp profile permits getrandom"],"tags":["go","panic","crypto","entropy","randomness"],"backgroundTag":"entropy-source-unavailable","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}