Skip to content

Restrict configuration sources to ENV and YAML#72

Open
palkan wants to merge 2 commits into
aderyabin:masterfrom
palkan:master
Open

Restrict configuration sources to ENV and YAML#72
palkan wants to merge 2 commits into
aderyabin:masterfrom
palkan:master

Conversation

@palkan
Copy link
Copy Markdown
Contributor

@palkan palkan commented Jun 24, 2025

Context

Recently, we found an issue with the combination of Sniffer, Anyway Config, and Doppler: a max call stack error occurs when we have an HTTP-backed configuration source available for Anyway Config.

Sniffer tries to load the configuration, and while it's still being loaded, we perform an HTTP request, which in its turn again tries to initializes the configuration—and the loop continues 'till it hits the max stack error.

Solution

We can limit the configuration sources for Sniffer to ENV and YAML. Those are safe to use (well, unless someone adds an HTTP call to YAML via ERB 😁).

Since we never mentioned that Sniffer can be configured in any way, keeping just ENV and YAML should be a good compromise.

Alternative solutions

I also considered making the config initialization two-phased: first, allocation and saving the @config variable, then doing the actual load (once). It's a bit more tricky because it would require to deal with the Anyway internals (we invoke #load right in the #initialize—not good) and handle the in-the-middle-of-loading state. Still worth exploring though.

Misc changes

Fixed some RuboCop issues.

Backporting

For those hitting the issue and waiting for a new release, the following snippet should help (make sure you use anyway_config >= 2.8.0):

require "sniffer/config"

Sniffer::Config.configuration_sources = [:env, :yml]

palkan added 2 commits June 24, 2025 15:29
Specify possible configuration sources explicitly to avoid triggering HTTP-backed Anyway loaders (e.g., Doppler or custom) that could cause recursion due to HTTP patches and, thus, crash due to the stack limit
Comment thread lib/sniffer/config.rb

# Only load configuration from static sources; prevent from trying to load
# from network sources, such as Doppler, to avoid recursion errors
self.configuration_sources = %i[env yml] if respond_to?(:configuration_sources)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use this configuration if supported; so, no requirement on upgrading the anyway_config gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants