Files
projectdiscovery-nuclei/pkg/authprovider
Hussain Alsaibai 9caa62ebd5 fix: resolve auth secret file race condition using sync.Once (#6976)
This commit fixes a race condition where templates start executing before
the secret file's login flow completes when using -secret-file flag.

Changes:
- pkg/authprovider/authx/dynamic.go: Replace atomic.Bool-based synchronization
  with sync.Once to ensure fetch callback runs exactly once and all concurrent
  callers block until completion. This prevents the race where multiple goroutines
  would see fetching=true and return early with nil error before secrets were ready.

- internal/runner/runner.go: Always prefetch secrets when AuthProvider exists,
  removing the PreFetchSecrets flag check. This ensures authentication completes
  before scanning starts regardless of flag settings.

- lib/sdk_private.go: Same change as runner.go for SDK mode consistency.

- pkg/authprovider/file_test.go: Add test for concurrent dynamic secret access
  to verify fetch happens exactly once and all workers get authenticated.

- pkg/authprovider/authx/dynamic_test.go: Add concurrent fetch tests to verify
  proper synchronization behavior.

Fixes #6592

Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2026-03-20 01:16:28 +01:00
..
2025-08-25 13:36:58 +05:30
2025-02-20 06:01:24 +05:30