You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@yhbsh agree. I found this package envied it uses the build_runner to take the .env contents and bake them into a generated file.
I added the .env and .g.dart files to .gitignore. And the package has a obfuscation feature. The secrets are still in the binary, and you could reverse engineer it, but more hidden... still looking for a better solution, if there is any...
looking for a solution with --dart-define.
UPDATE:
Never mind, after more research --dart-define also bakes the the secrets into the binary (makes sense since it is a compile flag... 🤣 ), there's no way around it and it seems that the only mitigation for it is code obfuscation.
@yhbsh agree. I found this package envied it uses the build_runner to take the .env contents and bake them into a generated file.
I added the .env and .g.dart files to .gitignore. And the package has a obfuscation feature. The secrets are still in the binary, and you could reverse engineer it, but more hidden... still looking for a better solution, if there is any...
looking for a solution with --dart-define.
UPDATE:
Never mind, after more research --dart-define also bakes the the secrets into the binary (makes sense since it is a compile flag... 🤣 ), there's no way around it and it seems that the only mitigation for it is code obfuscation.
Were you able to extract the secrets from the binary? Using --dart-define
The main advantage of using --dart-define is that we're no longer hardcoding sensitive keys in the source code.
But when we compile our app, the keys are still going to be baked in in the release binary:
API keys and source code are combined to produce the release binary
This makes total sense that the keys are ending up in the final binary, in fact that is always the case with compiled binaries, unless you are downloading them from a remote source at runtime.
The main advantage of using --dart-define is that we're no longer hardcoding sensitive keys in the source code.
But when we compile our app, the keys are still going to be baked in in the release binary:
API keys and source code are combined to produce the release binary
This makes total sense that the keys are ending up in the final binary, in fact that is always the case with compiled binaries, unless you are downloading them from a remote source at runtime.
True, but I am not sure we can extract them easily from the release binary, please try and see where it goes, if that's true then obfuscating is a must
Why not simply use --dart-define-from-file=.env? I don't quite understand the point of third-party packages here.
You can never completely prevent users from being able to read the secrets. Client secrets should only be an additional security hurdle.
I use flutter_dotenv or envied now, cause it gives you insight on your env at build time, and you have a Typed env to use, that i find really handy.
With --dart-define you will know about a missing env var at Runtime, with String.fromEnvironment.
Why should env variables be missing at runtime? They are defined in advance at compile time, so I don't see the point of defining them again at runtime.
That's wrong. You can build you app without --dart-define flags and it will produce a valid build, with empty strings.
Of course they are only defined at compile time if you use const variables for this (that's what the const keyword is for in the first place). And if the variable doesn't exist, an empty String is set, but I don't see how that contradicts my statement. It just sets an empty String because that is the default value in the method definition: external const factory String.fromEnvironment(String name, {String defaultValue = ""});
"This constructor is only guaranteed to work when invoked as const. It may work as a non-constant invocation on some platforms which have access to compiler options at run-time, but most ahead-of-time compiled platforms will not have this information."
this comment
With --dart-define you will know about a missing env var at Runtime, with String.fromEnvironment.
@maeddin again, with --dart-define you will know about a missing env only during runtime, when the String.fromEnvironment is executed.
envied uses build_runner and parses the variables before you run the app, while generating files. your app will not compile if the env is wrong. I find this really helpful, and that's why i use it.
this comment
With --dart-define you will know about a missing env var at Runtime, with String.fromEnvironment.
@maeddin again, with --dart-define you will know about a missing env only during runtime, when the String.fromEnvironment is executed.
envied uses build_runner and parses the variables before you run the app, while generating files. your app will not compile if the env is wrong. I find this really helpful, and that's why i use it.
Okay, now I understand what you mean. I thought you were referring to flutter_dotenv. My mistake.
I personally also find envied more useful.
It's worth mentioning we could add obfuscation to this package to achieve making it harder to extract keys but it would come at a concern of giving the package consumers a false sense of security.
I am going to close the issues for now but if someone would like to discuss if there is value in obfuscation or has another better idea please feel free to open or re open!
Activity
ccosnean commentedon Jun 4, 2024
@yhbsh yes, hence the "add the .env" into your
pubspec.ymlstep. This approach is flawed in its core, sadly.yhbsh commentedon Jun 4, 2024
That's kinda sad
ccosnean commentedon Jun 4, 2024
@yhbsh agree. I found this package envied it uses the
build_runnerto take the.envcontents and bake them into a generated file.I added the
.envand.g.dartfiles to .gitignore. And the package has a obfuscation feature. The secrets are still in the binary, and you could reverse engineer it, but more hidden... still looking for a better solution, if there is any...looking for a solution with
--dart-define.UPDATE:
Never mind, after more research
--dart-definealso bakes the the secrets into the binary (makes sense since it is a compile flag... 🤣 ), there's no way around it and it seems that the only mitigation for it is code obfuscation.yhbsh commentedon Jun 4, 2024
Were you able to extract the secrets from the binary? Using --dart-define
ccosnean commentedon Jun 4, 2024
@yhbsh I haven't tried, i read it in this article
This makes total sense that the keys are ending up in the final binary, in fact that is always the case with compiled binaries, unless you are downloading them from a remote source at runtime.
yhbsh commentedon Jun 4, 2024
True, but I am not sure we can extract them easily from the release binary, please try and see where it goes, if that's true then obfuscating is a must
ccosnean commentedon Jun 4, 2024
@yhbsh it is not easy, with obfuscation it is even harder. But still theoretically possible.
maeddin commentedon Jun 13, 2024
Why not simply use
--dart-define-from-file=.env? I don't quite understand the point of third-party packages here.You can never completely prevent users from being able to read the secrets. Client secrets should only be an additional security hurdle.
ccosnean commentedon Jun 13, 2024
@maeddin you can use what's best for you.
I use
flutter_dotenvor envied now, cause it gives you insight on your env at build time, and you have a Typed env to use, that i find really handy.With
--dart-defineyou will know about a missing env var at Runtime, withString.fromEnvironment.maeddin commentedon Jun 13, 2024
Why should env variables be missing at runtime? They are defined in advance at compile time, so I don't see the point of defining them again at runtime.
ccosnean commentedon Jun 13, 2024
That's wrong. You can build you app without
--dart-defineflags and it will produce a valid build, with empty strings.maeddin commentedon Jun 13, 2024
Of course they are only defined at compile time if you use
constvariables for this (that's what theconstkeyword is for in the first place). And if the variable doesn't exist, an emptyStringis set, but I don't see how that contradicts my statement. It just sets an emptyStringbecause that is the default value in the method definition:external const factory String.fromEnvironment(String name, {String defaultValue = ""});"This constructor is only guaranteed to work when invoked as const. It may work as a non-constant invocation on some platforms which have access to compiler options at run-time, but most ahead-of-time compiled platforms will not have this information."
https://api.flutter.dev/flutter/dart-core/String/String.fromEnvironment.html
maeddin commentedon Jun 13, 2024
You can also use typed values with
int.fromEnvironmentandbool.fromEnvironmentwithout parsing it yourself.Or am I getting this wrong?
ccosnean commentedon Jun 13, 2024
@maeddin again, with
--dart-defineyou will know about a missing env only during runtime, when theString.fromEnvironmentis executed.enviedusesbuild_runnerand parses the variables before you run the app, while generating files. your app will not compile if the env is wrong. I find this really helpful, and that's why i use it.maeddin commentedon Jun 13, 2024
Okay, now I understand what you mean. I thought you were referring to
flutter_dotenv. My mistake.I personally also find
enviedmore useful.java-james commentedon Oct 18, 2024
Hey everyone. Some good discussion on this thread.
I've appended a section to the readme to be more explicit about the concern. See https://github.com/java-james/flutter_dotenv/blob/master/README.md#security-considerations
It's worth mentioning we could add obfuscation to this package to achieve making it harder to extract keys but it would come at a concern of giving the package consumers a false sense of security.
Related issues raised are
#74
#73
#111
I am going to close the issues for now but if someone would like to discuss if there is value in obfuscation or has another better idea please feel free to open or re open!