{"record":{"id":"a5d1b4cc092c5c5f","repo":"crowdsecurity/crowdsec","slug":"too-many-levels-of-symbolic-links","errorCode":null,"errorMessage":"too many levels of symbolic links","messagePattern":"too many levels of symbolic links","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/path.go","lineNumber":42,"sourceCode":"\n\t\tif fi.Mode()&os.ModeSymlink == 0 {\n\t\t\t// found the target\n\t\t\treturn cur, nil\n\t\t}\n\n\t\ttarget, err := os.Readlink(cur)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\t// relative to the link's directory?\n\t\tif !filepath.IsAbs(target) {\n\t\t\ttarget = filepath.Join(filepath.Dir(cur), target)\n\t\t}\n\t\tcur = target\n\t}\n\n\treturn \"\", errors.New(\"too many levels of symbolic links\")\n}\n\n// isPathInside checks if a path is inside the given directory\nfunc isPathInside(path, dir string) (bool, error) {\n\tabsFile, err := filepath.Abs(path)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\tabsDir, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn false, err\n\t}\n\n\trel, err := filepath.Rel(absDir, absFile)\n\tif err != nil {\n\t\treturn false, err\n\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/path.go#L24-L60","documentation":"resolveSymlink walks a path resolving symlinks with an iteration cap; if it exceeds the maximum number of link levels without reaching a real file it returns 'too many levels of symbolic links'. This guards against symlink loops during plugin/hub item installation.","triggerScenarios":"newItemSpec resolving an item path whose symlink chain loops (A -> B -> A) or is longer than the iteration limit; called during item loading and exercised by TestResolveSymlink_Relative.","commonSituations":"Hand-made symlink cycles in the hub directory; a user symlinked a data dir onto itself via bind mounts or misconfigured dotfiles; restoring a backup that recreated circular links.","solutions":["Find and remove the symlink cycle: 'find /path/to/hub -type l -exec ls -l {} \\;' and delete the looping link","Replace the circular symlink with the real file or a direct path","Reinstall the affected hub item ('cscli hub item reinstall <item>')"],"exampleFix":"// before\nln -s /etc/crowdsec/hub/parsers/syslog /etc/crowdsec/hub/parsers/syslog\n// after\nln -s /etc/crowdsec/hub/parsers/syslog/remote_syslog.yaml /etc/crowdsec/hub/parsers/syslog-current","handlingStrategy":"validation","validationCode":"// detect symlink loops before installing items\nresolved, err := filepath.EvalSymlinks(targetPath)\nif err != nil { return fmt.Errorf(\"bad symlink at %s: %w\", targetPath, err) }","typeGuard":"func isSymlinkLoop(p string) bool { _, err := filepath.EvalSymlinks(p); return err != nil }","tryCatchPattern":"spec, err := cwhub newItemSpec(...)\nif err != nil && strings.Contains(err.Error(), \"too many levels of symbolic links\") {\n    return fmt.Errorf(\"symlink loop in hub item path %s\", path)\n}","preventionTips":["Never create symlinks pointing at their own parent directory inside hub dirs","Audit hub directories for circular links after restores or manual edits","Reinstall items via cscli rather than hand-symlinking"],"tags":["filesystem","symlink","hub","loop"],"backgroundTag":"symlink-loop-detected","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}