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
{{ message }}
Repository navigation
Deprecation warning for String based operators #8417
Since I upgraded to 4.13.2 I get a deprecation warning
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:236:13
I do not use any string based operators, however, or any operators of any kind. I didn't even know what an operator was actually, which is why I was confused.
I can fix this by adding operatorsAliases: false when instantiating the Sequellize object as below. Should this not be the default though? Or can we have the warning and documentation more clearly state that operatorsAliases: false must be set in order to avoid the warning?
Reacted by Stratos Theodorou, Yousef Shanawany, kramer65, Baptiste Manson, dkravcovs, Juan Diego Silva, Chris Papidas, Aymeric Beaumet, Abhijeet Ashok Muneshwar, Chris and 80 more
Reacted by 4bx, William McMurray, curt, Brett Beutell, unscored, GastonMrPhan, Captyou and Nate
changed the title [-]sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:236:13[/-][+]Deprecation warning for String based operators[/+]on Oct 4, 2017
Let me distill this regardless, Most web frameworks in Node.js allow parsing a object like string to actual JS object. This becomes a major issue when developers are passing user input without sanitizing them to Sequelize methods.
Now a bad actor could pass token='{"$gt": 1}' which will make above query to become something like this
db.Token.findOne({where: {token: {$gt: 1}});
This is because $gt is a string based operator which can be injected as string. To mitigate this we introduced secure operators #8240
Secure operators are Symbols which can't be duplicated by such object conversion. If we were using above code with secure operators we get this state
db.Token.findOne({where: {token: {$gt: 1// invalid, as Op.gt is an operator but $gt is not. This will throw an error}});
We cant make these symbol operators default for everyone as this would be a breaking change.
So what should you as a developer do now
If you follow good development practices and sanitize your user inputs properly, Go ahead and ignore this warning. We encourage you to switch your code base to use Op based operators as in v5 String based operators $gte, $lte .... will be disabled by default
If you think your inputs are not properly sanitized, please change your codebase to use Op (Symbol based operators).
You still want to use a few or all string operators, but dont want this warning
@sushantdhiman Thanks for the quick response. I would normally expect deprecation warnings when I had actually used the thing that was being deprecated. I was really hunting my code for any operators before I figured out what was going on.
You have this section of the docs.
You can limit alias your application will need by setting operatorsAliases option, remember to sanitize user input especially when you are directly passing them to Sequelize methods.
To me it wasn't clear where to set operatorsAliases, or what to set it to.
A couple suggestions if it's not just me who's confused.
In the security section mentioned above, tell people When instantiating Sequelize, you are required to specify Operator Aliases or specifically set this value to false (set operatorAliases: false)..
Set operatorAliases: false by default on the Sequelize constructor so that others dont get the depreciation warning. Not sure of the implications here.
Thanks for all the hard work on this project!
Reacted by Zack Moore, Bree Jackson, David Beitey, Tobias Kremer, Kumaran, Dan M., Vennamaneni Sai Krishna, Stratos Theodorou, takotuesday, Md Abdulla Al Sun and 119 more
I have no "$" things anywhere in my start code, but still has that deprecation warning
Reacted by Eyal Wiener, Selva Valluvan, Amanda Pouget, Constantin Guidon, Nicolas Coutin, Dmitriy Pushkov, Jonatan Lundqvist, Jake Zatecky, Wilhelm Klopp, Marcel Menzel and 69 more
Reacted by Karl Adler, aryeharmon, Soufiane Fadil, Max Jacobson, Deividas Valaitis, curt, Guillermo Grau Panea, Carol Chung, Son Goku, Rishabh Rawat and 18 more
This occurs using the basic 'Getting started' example from the main page. I do not even have a single query. I literally have the following code in index.js and get the warning.
Reacted by Rojer V, Hamidreza Mahdavipanah, yorbb, Daniel Baird, Kumaran, user3587412, Robert Churchill, Ryan Olds, Marcus Pohorely, Elias Toivanen and 191 more
Reacted by sansx, Havit Rovik, Valerii Kuzivanov, Nick Steele, Kirill Belorunov, Thomas Lynch, cyecho, hungv76, Vlad Povalii, Evan Baker and 7 more
Reacted by Indospace.io, Mathieu St-Vincent, TaylorPzreal, Thomas HAMOU, yueshuiniao, Jose Quintana, Stefan Aichholzer, Serg Kunin, Edgar Huamaní, Arthur Garreau and 109 more
Reacted by Nicolas Coutin, Michael, Nam Nguyen, dkravcovs, Jay Soeur, Eric Alter, Shane McDermed, curt, km, Nick Steele and 15 more
Reacted by Sanjay Achar, Jane Jeon, Timothy Zorn, Nick Steele, rf-sys, Seanghay Yath, Aimarekin, RN4N, unscored and Felipe Acosta
Reacted by TaylorPzreal, Rojer V, blueberry6401, Stefan Aichholzer, Mitch Horne, Chunlin Li, Dave T. Johnson, Ezequiel Falduto, Petr Volf, Made Baruna and 22 more
Reacted by HiiTea, Boris Berman, Amanda Pouget, Lautaro Mosse, Gady, Michael Yoffe, Bartosz Łaniewski, Vinicius Tavares, Jesal Gadhia, Grigorii K. Shartsev and 15 more
Reacted by wasddd, Sanjay Achar, Andrii Diachuk, Hugo Abonizio, Shehan Ekanayake, Timothy Zorn, Moisă Anca-Elena, Nick Steele, Shusse Kaido, Tomas Aprile and 8 more
For my system, query payloads with complex operators are transferred from my internal services which means payloads are serialized as text based packet and then unserialized again to JSON which will be parsed as sequelize find options / where attribute.
So I really need this string based operator aliases feature. And hope this feature shall not be deprecated.. ever. I really don't wanna dig into complex payload and map string aliases to symbol operators.
Also I cannot turn this deprecation warning off.
For now.. for someone like me.
Assigned operatorsAliases with an empty array [] to not trigger the warning. We are not using operatorsAliases, will this cause an issue?
The above assignment will result to this.OperatorsAliasMap = false.
As far as I can tell, all this information is incorrect now?
Settings operatorsAliases to false produces an error that it is a no-op
(node:23934) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
Settings operatorsAliases to the recommended for aliasing will still produce a warning (as shown in documentation)
(node:23711) [SEQUELIZE0003] DeprecationWarning: String based operators are deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/querying.html#operators
even though the linked docs clearly indicate:
Sequelize will warn you if you're using the default aliases and not limiting them if you want to keep using all default aliases (excluding legacy ones) without the warning you can pass the following operatorsAliases option -
A bit of a mess here, understandable its a bit of a confusing transition but sucks there seems to be no way to transition smoothly without those warnings showing up everywhere and worrying various engineers when they run into it.
In our case, we have a lib that handles Sequelize versions 3-5 as we transition libraries to use the latest. It appears impossible at this point to not get warnings on all our applications.
This may be due to v5 being used in this test scenario, but the documentation for v5 should then reflect that this option is no longer allowed in any way and the warning will always show if that option is ever defined at all.
Check out my reply above. I hope it helps. If you find my workaround to be incorrect, enlighten me, thank you.
Since I upgraded to 4.13.2 I get a deprecation warning
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:236:13
I do not use any string based operators, however, or any operators of any kind. I didn't even know what an operator was actually, which is why I was confused.
I can fix this by adding operatorsAliases: false when instantiating the Sequellize object as below. Should this not be the default though? Or can we have the warning and documentation more clearly state that operatorsAliases: false must be set in order to avoid the warning?
What should I do if I did not use operatorsAliases and want to filter the result using where but only can done by JSON? Like in a restful api? I parse the JSON to object by my self?
I mean, how can I use Op.gt when I can only use json, something like {"where": {"start_datetime": {"$gt": "2020-11-25"}}} ?
Activity
rojerv commentedon Oct 4, 2017
The same error
[-]sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:236:13[/-][+]Deprecation warning for String based operators[/+]sushantdhiman commentedon Oct 4, 2017
This is a deprecation warning, reason behind which is clearly stated in http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-security , I am sure you must have read it.
Let me distill this regardless, Most web frameworks in Node.js allow parsing a object like string to actual JS object. This becomes a major issue when developers are passing user input without sanitizing them to Sequelize methods.
For example, consider this sample of code
Now a bad actor could pass
token='{"$gt": 1}'which will make above query to become something like thisThis is because
$gtis a string based operator which can be injected as string. To mitigate this we introduced secure operators #8240Secure operators are Symbols which can't be duplicated by such object conversion. If we were using above code with secure operators we get this state
We cant make these symbol operators default for everyone as this would be a breaking change.
So what should you as a developer do now
If you follow good development practices and sanitize your user inputs properly, Go ahead and ignore this warning. We encourage you to switch your code base to use
Opbased operators as in v5 String based operators$gte, $lte ....will be disabled by defaultIf you think your inputs are not properly sanitized, please change your codebase to use
Op(Symbol based operators).You still want to use a few or all string operators, but dont want this warning
You can pass an operators map to
operatorsAliasesas explained in http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliasesSo in theory you can pass all current operators and disable this warning but be aware of this issue and dont forget to sanitize your user inputs.
More discussion and implementation details here
krishangupta commentedon Oct 4, 2017
@sushantdhiman Thanks for the quick response. I would normally expect deprecation warnings when I had actually used the thing that was being deprecated. I was really hunting my code for any operators before I figured out what was going on.
You have this section of the docs.
To me it wasn't clear where to set operatorsAliases, or what to set it to.
A couple suggestions if it's not just me who's confused.
In the security section mentioned above, tell people
When instantiating Sequelize, you are required to specify Operator Aliases or specifically set this value to false (set operatorAliases: false)..Set
operatorAliases: falseby default on the Sequelize constructor so that others dont get the depreciation warning. Not sure of the implications here.Thanks for all the hard work on this project!
alanpurple commentedon Oct 6, 2017
I have no "$" things anywhere in my start code, but still has that deprecation warning
krishangupta commentedon Oct 6, 2017
I also get it when doing a migration fyi.
punmechanic commentedon Oct 7, 2017
This also occurs in
findById- there's no way of passing operators here.ekamgit commentedon Oct 7, 2017
This occurs using the basic 'Getting started' example from the main page. I do not even have a single query. I literally have the following code in index.js and get the warning.
alanpurple commentedon Oct 7, 2017
So this warning sure is a bug, as mentioned by many people
ftuckey commentedon Oct 7, 2017
same thing for me
siguago commentedon Oct 8, 2017
Just add this to options.
operatorsAliases: falsereservce commentedon Oct 9, 2017
I tried to use
following this http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliases
However I got error:
Invalid value [object Object]when this code below run:
Before update operatorsAliases, everything works fine.
How can I fix this?
95 remaining items
dehypnosis commentedon Jan 10, 2020
For my system, query payloads with complex operators are transferred from my internal services which means payloads are serialized as text based packet and then unserialized again to JSON which will be parsed as sequelize find options / where attribute.
So I really need this string based operator aliases feature. And hope this feature shall not be deprecated.. ever. I really don't wanna dig into complex payload and map string aliases to symbol operators.
Also I cannot turn this deprecation warning off.
For now.. for someone like me.
Enhance resolvers and organize all graphql apis given (#27)
francodoshii commentedon Feb 19, 2020
Experiencing the same issue, were you able to solve this?
[feature/redux] Merge master in feature/redux (#1877)
francodoshii commentedon Feb 26, 2020
experiencing this issue at 5.18.4
francodoshii commentedon Feb 26, 2020
Assigned
operatorsAliaseswith an empty array[]to not trigger the warning. We are not using operatorsAliases, will this cause an issue?The above assignment will result to
this.OperatorsAliasMap = false.setOperatorsAliases(aliases) { if (!aliases || _.isEmpty(aliases)) { this.OperatorsAliasMap = false; } else { this.OperatorsAliasMap = Object.assign({}, aliases); } }francodoshii commentedon Feb 26, 2020
Check out my reply above. I hope it helps. If you find my workaround to be incorrect, enlighten me, thank you.
atmanandsah commentedon May 13, 2020
but can you explain why we are using operatorsAliases: false
emarcelino3 commentedon May 13, 2020
I'm in Sequelize 5.21.8 version. Same issue here.
With operatorsAliases like:
It's working fine : where: {id_ativo: { [Op.notIn] : arr }
ok
It's working fine : where: {id_ativo: { $notIn : arr } (
But warning: [SEQUELIZE0003] DeprecationWarning:
Without operatorsAliases :
Anything works using operators
What am I doing wrong?
ninsun commentedon Dec 4, 2020
What should I do if I did not use operatorsAliases and want to filter the result using where but only can done by JSON? Like in a restful api? I parse the JSON to object by my self?
I mean, how can I use Op.gt when I can only use json, something like {"where": {"start_datetime": {"$gt": "2020-11-25"}}} ?
Removed 'operatorsAliases: false' in models/index.js.
Update packages (#1595)
Update packages (#1595)
[feature/redux] Merge master in feature/redux (#1877)