Skip to content

Deprecation warning for String based operators #8417

Closed

Description

@krishangupta

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?


const sequelize = new Sequelize(
  config.RDS_DB_NAME,
  config.RDS_USERNAME, 
  config.RDS_PASSWORD,
  {
    host: config.RDS_HOSTNAME,
    dialect: 'mysql',
    logging: false,
    freezeTableName: true,
    operatorsAliases: false
  }
)

Activity

  1. rojerv commented on Oct 4, 2017

    @rojerv

    The same error

  2. 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
  3. sushantdhiman commented on Oct 4, 2017

    @sushantdhiman
    Contributor

    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

    db.Token.findOne({
          where: {
            token: req.query.token
          }
    );

    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

    1. 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

    2. 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

    You can pass an operators map to operatorsAliases as explained in http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliases

    So 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

  4. krishangupta commented on Oct 4, 2017

    @krishangupta
    Author

    @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.

    1. 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)..

    2. 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!

  5. alanpurple commented on Oct 6, 2017

    @alanpurple

    I have no "$" things anywhere in my start code, but still has that deprecation warning

  6. krishangupta commented on Oct 6, 2017

    @krishangupta
    Author

    I also get it when doing a migration fyi.

  7. punmechanic commented on Oct 7, 2017

    @punmechanic

    This also occurs in findById - there's no way of passing operators here.

  8. ekamgit commented on Oct 7, 2017

    @ekamgit

    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.

    const Sequelize = require('sequelize');
    
    const sequelize = new Sequelize('database', 'username', 'password', {
      host: 'localhost',
      dialect: 'mysql',
    
      pool: {
        max: 5,
        min: 0,
        idle: 10000
      }
    });
    
  9. alanpurple commented on Oct 7, 2017

    @alanpurple

    So this warning sure is a bug, as mentioned by many people

  10. ftuckey commented on Oct 7, 2017

    @ftuckey

    same thing for me

  11. siguago commented on Oct 8, 2017

    @siguago

    Just add this to options.

    operatorsAliases: false

  12. reservce commented on Oct 9, 2017

    @reservce

    I tried to use

    const Op = Sequelize.Op;
    const operatorsAliases = {...}
    

    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:

    let options = {where: {}, raw: true};
    ...
    options.where.name = {$ilike: `%${filters.name}%`};
    options.where.duration = filters.duration;
    ...
    Banners.findAndCountAll(options);
    

    Before update operatorsAliases, everything works fine.
    How can I fix this?

  13. 95 remaining items

  14. dehypnosis commented on Jan 10, 2020

    @dehypnosis

    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.

    // tslint:disable-next-line:no-var-requires
    require("sequelize/lib/utils/deprecations").noStringOperators = () => {};
  15. francodoshii commented on Feb 19, 2020

    @francodoshii

    I tried to use

    const Op = Sequelize.Op;
    const operatorsAliases = {...}
    

    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:

    let options = {where: {}, raw: true};
    ...
    options.where.name = {$ilike: `%${filters.name}%`};
    options.where.duration = filters.duration;
    ...
    Banners.findAndCountAll(options);
    

    Before update operatorsAliases, everything works fine.
    How can I fix this?

    Experiencing the same issue, were you able to solve this?

  16. francodoshii commented on Feb 26, 2020

    @francodoshii

    experiencing this issue at 5.18.4

  17. francodoshii commented on Feb 26, 2020

    @francodoshii

    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.

    setOperatorsAliases(aliases) { if (!aliases || _.isEmpty(aliases)) { this.OperatorsAliasMap = false; } else { this.OperatorsAliasMap = Object.assign({}, aliases); } }

  18. francodoshii commented on Feb 26, 2020

    @francodoshii

    As far as I can tell, all this information is incorrect now?

    1. 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.
    
    1. Settings operatorsAliases to the recommended for aliasing will still produce a warning (as shown in documentation)
    const Op = Sequelize.Op;
    const operatorsAliases = {
      $eq: Op.eq,
      $ne: Op.ne,
      $gte: Op.gte,
      $gt: Op.gt,
      $lte: Op.lte,
      $lt: Op.lt,
      $not: Op.not,
      $in: Op.in,
      $notIn: Op.notIn,
      $is: Op.is,
      $like: Op.like,
      $notLike: Op.notLike,
      $iLike: Op.iLike,
      $notILike: Op.notILike,
      $regexp: Op.regexp,
      $notRegexp: Op.notRegexp,
      $iRegexp: Op.iRegexp,
      $notIRegexp: Op.notIRegexp,
      $between: Op.between,
      $notBetween: Op.notBetween,
      $overlap: Op.overlap,
      $contains: Op.contains,
      $contained: Op.contained,
      $adjacent: Op.adjacent,
      $strictLeft: Op.strictLeft,
      $strictRight: Op.strictRight,
      $noExtendRight: Op.noExtendRight,
      $noExtendLeft: Op.noExtendLeft,
      $and: Op.and,
      $or: Op.or,
      $any: Op.any,
      $all: Op.all,
      $values: Op.values,
      $col: Op.col
    };
    
    const connection = new Sequelize(db, user, pass, { operatorsAliases });

    Will produce the warning

    (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.

  19. atmanandsah commented on May 13, 2020

    @atmanandsah

    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?

    
    const sequelize = new Sequelize(
      config.RDS_DB_NAME,
      config.RDS_USERNAME, 
      config.RDS_PASSWORD,
      {
        host: config.RDS_HOSTNAME,
        dialect: 'mysql',
        logging: false,
        freezeTableName: true,
        operatorsAliases: false
      }
    )
    

    but can you explain why we are using operatorsAliases: false

  20. emarcelino3 commented on May 13, 2020

    @emarcelino3

    I'm in Sequelize 5.21.8 version. Same issue here.

    With operatorsAliases like:

    const operatorsAliases = { 
      $eq: Op.eq,
      $ne: Op.ne,
      ...
    

    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?

  21. ninsun commented on Dec 4, 2020

    @ninsun

    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"}}} ?

  22. added a commit that references this issue on Jan 31, 2023
  23. added a commit that references this issue on Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions