urBackend icon indicating copy to clipboard operation
urBackend copied to clipboard

[Bug] public-api: bulk insert endpoint silently injects isDeleted/deletedAt fields into validated data after stripping them

Open Kirtan-pc opened this issue 5 months ago • 5 comments

Description

In data.controller.js, the bulkInsertData handler first correctly does delete cleanData.isDeleted and delete cleanData.deletedAt to prevent injection, but then immediately spreads isDeleted: false, deletedAt: null back into the sanitized object (sanitize({ ...cleanData, isDeleted: false, deletedAt: null })). This means every bulk-inserted document gets isDeleted: false and deletedAt: null added explicitly, which is redundant (Mongoose schema already defaults them) and inconsistent with the single-insert path in insertData (lines 53-56), which only deletes but does not re-add these fields. This creates a schema-consistency divergence and could confuse RLS filters or analytics that inspect these fields.

Steps to Reproduce

Call POST /api/data/{collection}/bulk with a valid array. Inspect the inserted documents in MongoDB. Every bulk-inserted document has isDeleted: false and deletedAt: null as explicit stored fields. A single-insert via POST /api/data/{collection} does NOT explicitly store these fields (relies on schema defaults).

Expected Behaviour

Both insertData and bulkInsertData should behave consistently: either both rely on Mongoose schema defaults, or both explicitly set the soft-delete fields. The current mixed behaviour is a latent bug.

Actual Behaviour

bulkInsertData explicitly writes isDeleted: false, deletedAt: null into every inserted document, while insertData does not. Documents from the two paths are structurally different in MongoDB.

Kirtan-pc avatar Jun 07 '26 09:06 Kirtan-pc

Hi @yash-pouranik ,

I would like to work on this issue under GSSoC 2026.

Could you please assign this issue to me?

Thank you!

Kirtan-pc avatar Jun 07 '26 09:06 Kirtan-pc

Hi! @yash-pouranik I'd like to work on this issue #287. I have reviewed the bug description and would appreciate it if this issue could be assigned to me.

goelakshita708 avatar Jun 09 '26 06:06 goelakshita708

@Kirtan-pc @goelakshita708 As of I know, Mongoose doesnt implicitely add deletedAt and isDeleted fields to any document please reverify

yash-pouranik avatar Jun 09 '26 08:06 yash-pouranik

Hey @yash-pouranik,

Thanks for the clarification. I agree that Mongoose doesn’t automatically inject deletedAt / isDeleted fields.

My report is specifically about the bulk handler’s implementation: after removing those properties for safety (delete cleanData.isDeleted / delete cleanData.deletedAt), the code immediately reintroduces them when sanitizing:

sanitize({ ...cleanData, isDeleted: false, deletedAt: null })

So those fields are not coming from any Mongoose “implicit defaults”; they’re being explicitly persisted by the bulk insert path itself. That’s why bulk-inserted docs end up containing isDeleted: false and deletedAt: null as stored fields, while the single-insert path doesn’t set them and relies on schema behavior.

So we can either bulk should stop explicitly writing isDeleted/deletedAt (match insertData), or single insert should also explicitly set them, so both paths write the same shape.

Kirtan-pc avatar Jun 09 '26 11:06 Kirtan-pc

Hi! This issue appears to be unassigned. Would it be possible to assign it to me for GSSoC '26? I'm interested in working on this and would be happy to submit a PR once assigned.

Thank you!

anshul23102 avatar Jun 28 '26 17:06 anshul23102