[SERVER-61846] Prevent redact from throwing BSONObjectTooLarge Created: 02/Dec/21  Updated: 29/Oct/23  Resolved: 13/Dec/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.3.0, 5.2.0, 5.0.6, 4.4.11

Type: Bug Priority: Major - P3
Reporter: Haley Connelly Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
depends on SERVER-57289 redact should not convert BSONArray i... Closed
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.2, v5.0, v4.4
Steps To Reproduce:

The described behavior is demonstrated by adding the following to redaction_test.cpp

TEST(RedactBSONTest, RedactCausesBSONTooLarge) {
    logv2::setShouldRedactLogs(true);
    BSONObjBuilder bob;
    for (int i = 0; i < 1024 * 1024; i++) {
        auto fieldName = "abcdefg";
        // The value of each field is smaller than the size of the kRedactionDefaultMask.
        bob.append(fieldName, 1);
    }
    const auto obj = bob.obj();
    // Demonstrates it is possible to grow a BSON too large by redacting fields.
    ASSERT_THROWS_CODE(redact(obj), DBException, ErrorCodes::BSONObjectTooLarge);
}

Sprint: Execution Team 2021-12-13
Participants:
Case:

 Description   

redact replaces BSONObj field values with the kRedactionDefaultMask string "###".

A redacted BSONObj can throw BSONObjectTooLarge if a valid BSONObj has many fields with values smaller than the kRedactionDefaultMask string size.

ex) 
BSON("foodIsGood" << 1) is smaller than
redact(BSON("foodIsGood" << 1)) which yields BSON("foodIsGood": "###")

This can cause real problems on startup if, say, we try to apply a large oplog entry close to the limit full of arrays of ints that get expanded to "###" and cause the startup to fail with a DBException



 Comments   
Comment by Githook User [ 16/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 redact document using null instead of default mask to stay under BSON limit

(cherry picked from commit 886e09ce457d5cdbef16710678c386ec6765db3c)
Branch: v5.0
https://github.com/mongodb/mongo/commit/3285f14892712d7fef470bb4aa745e8dd0f76803

Comment by Githook User [ 16/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 add redaction test for small fields

(cherry picked from commit c8de2a7f419f2486780fed5ae06ade4e78aa2a5d)
Branch: v5.0
https://github.com/mongodb/mongo/commit/e166033f62f8efdc0499ce534235c0209c217405

Comment by Githook User [ 16/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 redact document using null instead of default mask to stay under BSON limit

(cherry picked from commit 886e09ce457d5cdbef16710678c386ec6765db3c)
Branch: v4.4
https://github.com/mongodb/mongo/commit/80d2987ad08a9f6a187b0df19b1ca1d7462a9e02

Comment by Githook User [ 16/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 add redaction test for small fields

(cherry picked from commit c8de2a7f419f2486780fed5ae06ade4e78aa2a5d)
Branch: v4.4
https://github.com/mongodb/mongo/commit/817e61d303996e944c4c14e8df14b73f1eb15381

Comment by Githook User [ 15/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 redact document using null instead of default mask to stay under BSON limit
Branch: v5.2
https://github.com/mongodb/mongo/commit/1f7a0a72cc04e6787246aee421572040ffdc0a9f

Comment by Githook User [ 15/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 add redaction test for small fields
Branch: v5.2
https://github.com/mongodb/mongo/commit/615eb7a80e605f5a51e923a36e1075feea8b7edb

Comment by Benety Goh [ 15/Dec/21 ]

This redaction changes in this ticket builds on the BSONArray work done in SERVER-57289, which is currently present in 5.1 but not in any server version prior to 5.1.

Comment by Githook User [ 13/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 redact document using null instead of default mask to stay under BSON limit
Branch: master
https://github.com/mongodb/mongo/commit/886e09ce457d5cdbef16710678c386ec6765db3c

Comment by Githook User [ 13/Dec/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-61846 add redaction test for small fields
Branch: master
https://github.com/mongodb/mongo/commit/c8de2a7f419f2486780fed5ae06ade4e78aa2a5d

Generated at Thu Feb 08 05:53:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.