Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14739

Escape control characters in log messages

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.3, 2.7.4
    • Component/s: Logging
    • ALL
    • Hide

      map reduce example

      db.things.insert( { _id : 1, tags : ['dog', 'cat'] } );
      db.things.insert( { _id : 2, tags : ['cat'] } );
      db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } );
      db.things.insert( { _id : 4, tags : []  } );
      
      var map = function() {
        var things = this;
        things.tags.forEach( function(elem) {
            emit( elem , { count : 1 } );
          }
        );
      };
      
      var reduce = function( key , values ) {
        var total = 0;
        for ( var i=0; i<values.length; i++ ) {
          total += values[i].count;
        }
        return { count : total };
      };
      var res = db.things.mapReduce(map, reduce, { out : "myoutput" } );
      

      insert example

      db.things.insert( { a : 'asdf\n  asdf' } );
      
      master (f7df4c7)
      $ mongod --v
      2014-07-31T10:56:53.753+0100 I COMMANDS [conn1] command test.$cmd command: mapReduce { mapreduce: "things", map: function () {
        var things = this;
        things.tags.forEach( function(ele..., reduce: function ( key , values ) {
        var total = 0;
        for ( var i=0; i<values..., out: "myoutput" } planSummary: COLLSCAN keyUpdates:0 numYields:0 locks(micros) r:2756 w:1818 reslen:205 24ms
      
      2014-07-31T10:57:30.833+0100 I COMMANDS [conn1] insert test.things query: { _id: ObjectId('53da130a998eaf05e7f22c7c'), a: "asdf
        asdf" } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:81 0ms
      
      2.6.3
      $ mongod --v
      
      2014-07-31T10:39:52.109+0100 [conn1] command test.$cmd command: mapReduce { mapreduce: "things", map: function () {
        var things = this;
        things.tags.forEach( function(ele..., reduce: function ( key , values ) {
        var total = 0;
        for ( var i=0; i<values..., out: "myoutput" } planSummary: COLLSCAN keyUpdates:0 numYields:0 locks(micros) r:6729 w:5992 reslen:175 71ms
      
      2014-07-31T10:40:00.955+0100 [conn1] insert test.things query: { _id: ObjectId('53da0ef0998eaf05e7f22c7a'), a: "asdf
        asdf" } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:83 0ms
      
      Show
      map reduce example db.things.insert( { _id : 1, tags : [ 'dog' , 'cat' ] } ); db.things.insert( { _id : 2, tags : [ 'cat' ] } ); db.things.insert( { _id : 3, tags : [ 'mouse' , 'cat' , 'dog' ] } ); db.things.insert( { _id : 4, tags : [] } ); var map = function () { var things = this ; things.tags.forEach( function (elem) { emit( elem , { count : 1 } ); } ); }; var reduce = function ( key , values ) { var total = 0; for ( var i=0; i<values.length; i++ ) { total += values[i].count; } return { count : total }; }; var res = db.things.mapReduce(map, reduce, { out : "myoutput" } ); insert example db.things.insert( { a : 'asdf\n asdf' } ); master (f7df4c7) $ mongod --v 2014-07-31T10:56:53.753+0100 I COMMANDS [conn1] command test.$cmd command: mapReduce { mapreduce: "things", map: function () { var things = this; things.tags.forEach( function(ele..., reduce: function ( key , values ) { var total = 0; for ( var i=0; i<values..., out: "myoutput" } planSummary: COLLSCAN keyUpdates:0 numYields:0 locks(micros) r:2756 w:1818 reslen:205 24ms 2014-07-31T10:57:30.833+0100 I COMMANDS [conn1] insert test.things query: { _id: ObjectId('53da130a998eaf05e7f22c7c'), a: "asdf asdf" } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:81 0ms 2.6.3 $ mongod --v 2014-07-31T10:39:52.109+0100 [conn1] command test.$cmd command: mapReduce { mapreduce: "things", map: function () { var things = this; things.tags.forEach( function(ele..., reduce: function ( key , values ) { var total = 0; for ( var i=0; i<values..., out: "myoutput" } planSummary: COLLSCAN keyUpdates:0 numYields:0 locks(micros) r:6729 w:5992 reslen:175 71ms 2014-07-31T10:40:00.955+0100 [conn1] insert test.things query: { _id: ObjectId('53da0ef0998eaf05e7f22c7a'), a: "asdf asdf" } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:83 0ms
    • Security 2020-09-07

      We should consider escaping control characters in user-supplied data when it is printed in the server log.

            Assignee:
            spencer.jackson@mongodb.com Spencer Jackson
            Reporter:
            gianfranco Gianfranco Palumbo
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: