{"record":{"id":"73299af115d95d4a","repo":"shadow1ng/fscan","slug":"auth-function-is-nil","errorCode":null,"errorMessage":"auth function is nil","messagePattern":"auth function is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/services/credential_tester.go","lineNumber":86,"sourceCode":"func authCleanupWait() time.Duration {\n\treturn time.Duration(atomic.LoadInt64(&authCleanupWaitNanos))\n}\n\n// =============================================================================\n// 单凭据测试（解决 goroutine 泄漏）\n// =============================================================================\n\n// TestSingleCredential 安全地测试单个凭据\n// 正确处理 context 取消时的资源清理\nfunc TestSingleCredential(ctx context.Context, cred Credential, authFn AuthFunc) *AuthResult {\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\tif authFn == nil {\n\t\treturn &AuthResult{\n\t\t\tSuccess:   false,\n\t\t\tErrorType: ErrorTypeUnknown,\n\t\t\tError:     fmt.Errorf(\"auth function is nil\"),\n\t\t}\n\t}\n\tif err := ctx.Err(); err != nil {\n\t\treturn &AuthResult{\n\t\t\tSuccess:   false,\n\t\t\tErrorType: ErrorTypeNetwork,\n\t\t\tError:     err,\n\t\t}\n\t}\n\n\tresultChan := make(chan *AuthResult, 1)\n\n\tgo func() {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tresultChan <- &AuthResult{\n\t\t\t\t\tSuccess:   false,\n\t\t\t\t\tErrorType: ErrorTypeUnknown,","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/plugins/services/credential_tester.go#L68-L104","documentation":"TestSingleCredential was invoked with a nil authFn — the function responsible for performing an auth attempt against a target. Since no test can run, it returns an AuthResult with Success:false, ErrorTypeUnknown, and the 'auth function is nil' error. This is a programming/configuration bug, not a network outcome.","triggerScenarios":"testCredentialWithRetry (or tests) calls TestSingleCredential without supplying an authFn, e.g. a plugin forgot to build its auth function via createAuthFunc or passed an uninitialized function variable.","commonSituations":"Plugin registration code that constructs the tester before wiring authFn; refactor left authFn unassigned; a nil return from createAuthFunc on a misconfigured plugin passed straight through.","solutions":["Fix the caller to construct and pass a non-nil authFn (e.g. p.createAuthFunc(info, config, state)) before invoking TestSingleCredential.","Add an early check in the calling plugin so nil authFn is caught and reported with plugin context.","In tests, this is expected behavior — assert on ErrorTypeUnknown and the message rather than treating it as a scan failure."],"exampleFix":"// before\nresult := TestSingleCredential(ctx, target, cred, nil, state)\n// after\nauthFn := p.createAuthFunc(info, config, state)\nresult := TestSingleCredential(ctx, target, cred, authFn, state)","handlingStrategy":"validation","validationCode":"if authFn == nil {\n    return fmt.Errorf(\"plugin %s produced nil auth function; check createAuthFunc wiring\", pluginName)\n}\nresult := TestSingleCredential(ctx, target, cred, authFn, state)","typeGuard":null,"tryCatchPattern":"res := TestSingleCredential(ctx, target, cred, authFn, state)\nif !res.Success && res.ErrorType == ErrorTypeUnknown && res.Error.Error() == \"auth function is nil\" {\n    log.Printf(\"tester misconfigured: authFn missing for %s\", target)\n}","preventionTips":["Always build authFn via the plugin's createAuthFunc before constructing the tester.","Assert non-nil authFn in plugin initialization tests.","Watch for nil returns from factory functions and fail fast at startup rather than mid-scan."],"tags":["credentials","nil-check","configuration","go"],"backgroundTag":"null-argument","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}