Skip to content

Postgres#5365

Merged
boutell merged 62 commits intomainfrom
postgres
Apr 23, 2026
Merged

Postgres#5365
boutell merged 62 commits intomainfrom
postgres

Conversation

@boutell
Copy link
Copy Markdown
Member

@boutell boutell commented Mar 25, 2026

No description provided.

Comment thread packages/db-connect/adapters/postgres.js Fixed
Comment thread packages/db-connect/adapters/sqlite.js Fixed
}
current = current[parts[i]];
}
current[parts[parts.length - 1]] = value;

Check warning

Code scanning / CodeQL

Prototype-polluting function Medium

The property chain
here
is recursively assigned to
current
without guarding against prototype pollution.

Copilot Autofix

AI 9 days ago

The safest minimal fix is to harden setNestedField by rejecting any path segment that can participate in prototype-chain mutation: __proto__, constructor, and prototype (not just __proto__). This preserves existing functionality for legitimate field paths while blocking known prototype pollution vectors.

In packages/db-connect/lib/shared.js, update setNestedField:

  • Replace the current guard:
    • if (parts.includes('__proto__')) { return; }
  • With a stronger segment validation that rejects all dangerous keys:
    • if (parts.some(part => part === '__proto__' || part === 'constructor' || part === 'prototype')) { return; }

No new imports or external dependencies are required.

Suggested changeset 1
packages/db-connect/lib/shared.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/db-connect/lib/shared.js b/packages/db-connect/lib/shared.js
--- a/packages/db-connect/lib/shared.js
+++ b/packages/db-connect/lib/shared.js
@@ -103,7 +103,7 @@
 
 function setNestedField(obj, path, value) {
   const parts = path.split('.');
-  if (parts.includes('__proto__')) {
+  if (parts.some(part => part === '__proto__' || part === 'constructor' || part === 'prototype')) {
     return;
   }
   let current = obj;
EOF
@@ -103,7 +103,7 @@

function setNestedField(obj, path, value) {
const parts = path.split('.');
if (parts.includes('__proto__')) {
if (parts.some(part => part === '__proto__' || part === 'constructor' || part === 'prototype')) {
return;
}
let current = obj;
Copilot is powered by AI and may make mistakes. Always verify output.
boutell added 2 commits March 26, 2026 10:25
* "npm test" tests all three adapters
.*.sw*

# claude-tools log files
claude-tools/**/*.log
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-tools is meant to persist, but its logs are not

'test/apos-build',
'coverage'
'coverage',
'claude-tools'
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude code riffing scripts for its own test purposes, eslint not necessary

"main": "index.js",
"scripts": {
"pretest": "npm run lint",
"test": "npm run test:base && npm run test:missing && npm run test:assets && npm run test:esm",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asset tests are now a good citizen, don't need to be broken out separately anymore

boutell added 18 commits April 12, 2026 10:17
* optimize $match when it is the first step in aggregation, don't fetch the whole collection 😜
* multipostgres listDatabases() and .db() should return and expect "fully qualified virtual database names," e.g. physical_db_name-schemaname
documentation improvements
…w on unrecognized operators. It should, and it should support the same mongodb operators that the regular find()

  path does in postgres/sqlite (our official subset), unless there is an extraordinary reason not to.

  * Similarly, the main query implementation for normal queries should throw on unrecognized operators if it doesn't already.

  * The dump/restore programmatic APIs in db-connect concern me. These involve returning the entire database as a string, which could exhaust memory. This impacts both utilities and
  also copyDatabase(). Could these APIs return and expect async iterators instead of strings?

  * The test "anchored regex on an indexed field uses a btree index search" runs explain on a query that's hardcoded in the test. Instead these SQL based adapters should expose a means
  to get the SQL for a query, so it can be directly tested. Otherwise this test proves nothing as changes to the adapter accumulate in future.

  * Why is this test searching for "at least 1" and not exactly 1?

  it('should find documents with null value', async function() {
    const docs = await db.collection('test').find({ value: null }).toArray();
    // MongoDB matches both null and missing fields with { value: null }
    expect(docs.length).to.be.at.least(1);
  });

  * What is the maximum size of a db-connect document in the postgres and sqlite adapters?

  * Update the copyright year in db-connect/LICENSE.md to 2025.

  * The db-connect README mentions: sqlite://:memory: What happens if you try to use .db('some-name') with that? I think it would be best to just not support throwaway in-memory sqlite
  databases because I doubt anyone would intentionally store a website in one.
@boutell boutell requested review from BoDonkey and myovchev April 16, 2026 16:26
Comment thread package.json Outdated
"build": "pnpm --recursive run build",
"lint": "pnpm --recursive run lint",
"test": "pnpm --recursive run test",
"test": "APOS_TEST_DB_PROTOCOL=postgres npm run test:main && APOS_TEST_DB_PROTOCOL=mongodb npm run test:main && APOS_TEST_DB_PROTOCOL=sqlite npm run test:main && APOS_TEST_DB_PROTOCOL=multipostgres npm run test:main",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be probably pnpm instead npm.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed that.

@boutell boutell requested a review from myovchev April 20, 2026 14:12
@boutell boutell merged commit 0d85771 into main Apr 23, 2026
33 checks passed
@boutell boutell deleted the postgres branch April 23, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants