Use unicode:characters_to_binary for os:getenv values so Cyrillic placeholder passwords fail with weak_secret instead of badarg crash. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -51,7 +51,7 @@ require_admin_seed_email(EnvKey) ->
|
||||
case os:getenv(EnvKey) of
|
||||
false -> {error, {missing_secret, list_to_atom(EnvKey)}};
|
||||
"" -> {error, {missing_secret, list_to_atom(EnvKey)}};
|
||||
Email -> {ok, list_to_binary(Email)}
|
||||
Email -> {ok, env_to_binary(Email)}
|
||||
end.
|
||||
|
||||
-spec require_admin_seed_password(string()) ->
|
||||
@@ -61,7 +61,7 @@ require_admin_seed_password(EnvKey) ->
|
||||
false -> {error, {missing_secret, list_to_atom(EnvKey)}};
|
||||
"" -> {error, {missing_secret, list_to_atom(EnvKey)}};
|
||||
Pass ->
|
||||
Bin = list_to_binary(Pass),
|
||||
Bin = env_to_binary(Pass),
|
||||
case is_strong_secret(Bin) of
|
||||
true -> {ok, Bin};
|
||||
false -> {error, {weak_secret, list_to_atom(EnvKey)}}
|
||||
@@ -124,9 +124,13 @@ os_getenv_binary(Key) ->
|
||||
case os:getenv(Key) of
|
||||
false -> undefined;
|
||||
"" -> undefined;
|
||||
Val -> list_to_binary(Val)
|
||||
Val -> env_to_binary(Val)
|
||||
end.
|
||||
|
||||
%% os:getenv/1 returns Unicode charlists; list_to_binary/1 only accepts byte iolists.
|
||||
env_to_binary(Val) when is_binary(Val) -> Val;
|
||||
env_to_binary(Val) when is_list(Val) -> unicode:characters_to_binary(Val).
|
||||
|
||||
dev_warn_if_weak(_Name, undefined) -> ok;
|
||||
dev_warn_if_weak(Name, Secret) ->
|
||||
case is_strong_secret(Secret) of
|
||||
|
||||
Reference in New Issue
Block a user