Comments (10)
Ok, it might be an effect of the Plug macros.
Anyway, I can see what's happening here. The fix would be to make the other endpoints safe the same way that GET is.
from fun_with_flags_ui.
Hey there, thank you for using the package and for reporting this.
How many BEAM notes are you running? I wonder to what extent this could be caused by the GET request landing on a cold node that has never loaded the flag in memory before (that's what creates the flag-name atom for the first time).
from fun_with_flags_ui.
Hello @tompave! Thanks for the answer. It happened while having 3 nodes.
from fun_with_flags_ui.
I see. Then that happens because your GET /flags/:flag_name
request lands on a BEAM node that hasn't loaded that flag in memory yet. The earliest that can happen is by visiting GET /flags
, as all flags are loaded in memory from the DB, and the atoms for the names are created.
The reason I'm hesitant to replace String.to_existing_atom/1
with String.to_atom/1
is that in the case of GET /flags/:flag_name
we're dealing with user input. Since atoms are not garbage collected, creating atoms for user input would be an attack vector that could make the BEAM node go out-of-memory. This is a bit safer when loading flags from the DB, where String.to_atom/1
is used.
from fun_with_flags_ui.
Oh, I got it. I'll try to provide force early visiting of /flags
, to load flags in memory 👍
So I think we can close this ticket. Thanks @tompave!
from fun_with_flags_ui.
It's still not a great solution though. Even if just a few nodes, refreshing GET /flags
won't guarantee that you hit all nodes. And as the number of nodes increases, the solution becomes less and less practical.
This is not normally a problem when the flag is actually checked by the application at runtime (outside FunWithFlags.UI
), as that would cause the flag name atom to be encountered first and loaded in memory, because you have to reference it as an atom literal in your code, in order to check a flag. So, in that case, if the flag is checked in a frequently executed code path, chances are that all your BEAM nodes will have already loaded it by the time you try to access it at GET /flags/:flag_name
. Even in this case, though, the situation is not perfect.
Perhaps the right solution is to wrap that String.to_existing_atom/1
with a try...rescue
, and if it fails with the atom error, check if the flag actually exists. We could also check it immediately before trying to load the flag.
from fun_with_flags_ui.
Ok, I've just realized that I had already solved this problem ages ago. That flag lookup is wrapped with if safe_flag_exists?(name)
:
fun_with_flags_ui/lib/fun_with_flags/ui/utils.ex
Lines 75 to 77 in caca4f7
Which basically does what I described above:
fun_with_flags_ui/lib/fun_with_flags/ui/utils.ex
Lines 151 to 158 in caca4f7
I'm not sure why you're getting that error then.
Perhaps you're running on a DB cluster, and there is some replica lag?
from fun_with_flags_ui.
Your stacktrace:
lib/fun_with_flags/ui/router.ex in anonymous fn/3 in FunWithFlags.UI.Router.do_match/4 at line 99
lib/plug/router.ex in anonymous fn/4 in FunWithFlags.UI.Router.dispatch/2 at line 246
Ok, so that's happening on different endpoints, not on GET /flags/:flag_name
. That makes sense then. The fix it to make those safe as well.
The line numbers don't perfectly align. What version of FWF.UI are you using?
from fun_with_flags_ui.
Hmm, as I see in my mix.lock: 0.8.1
from fun_with_flags_ui.
We encountered this issue when trying to clean up after a feature flag that we removed from our code, so its atom name was no longer referenced/created anywhere.
from fun_with_flags_ui.
Related Issues (14)
- Provide bootstrap.min.css.gz unzipped HOT 4
- Use conn.script_name instead of namespace to construct paths HOT 3
- Stable ordering of gates in index page HOT 2
- Percentage gates display as scientific notation HOT 5
- (UndefinedFunctionError) function FunWithFlags.Store.Persistent.Redis.all_flags/0 is undefined (module FunWithFlags.Store.Persistent.Redis is not available) HOT 4
- Persistent XSS Vulnerability HOT 1
- Add support to protect from forgery HOT 3
- How to select DB to read flags HOT 2
- Can't use this library if using `fun_with_flags` with `runtime: false` HOT 5
- CSRF Protection Error when loading script HOT 5
- Customize UI HOT 3
- Problem to load gzipped bootstrap in production HOT 6
- Flags with question marks are routed incorrectly HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fun_with_flags_ui.