Prevent leakage of sensitive credentials
defmodule MyApp.Config do
@api_key "hard-coded-api-key"
def get_api_key do
@api_key
end
end
The code hard-codes a sensitive API key, which exposes the key if the code is leaked. An attacker obtaining this key can misuse it to impersonate the application.
defmodule MyApp.Config do
def get_api_key do
System.get_env("API_KEY")
end
end
The code retrieves the API key from an environment variable instead of hard-coding it. Even if the code is leaked, the sensitive API key remains secure.