feat(langgraph-checkpoint-postgres): optional schema creation - #2561
Open
Alex Golubtsov (alex-golubtsov) wants to merge 15 commits into
Open
Alex Golubtsov (alex-golubtsov) wants to merge 15 commits into
Alex Golubtsov (alex-golubtsov) wants to merge 15 commits into
Conversation
…nd store idempotency
🦋 Changeset detectedLatest commit: cc570c7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Security Issues
- SQL Injection
The newly addedschemaExistsSQL()helper directly interpolates the configurableschemavalue into a SQL string. If an attacker can influence this option in a deployment or tenant-provisioning flow, they can break out of the string literal and execute arbitrary SQL duringsetup()whencreateSchema: falseis used.
Recommendations
- Use parameterized queries for schema existence checks, e.g.
WHERE schema_name = $1with[schema]passed separately toclient.query(). - Avoid returning SQL strings that already contain user/config-controlled values embedded via template literals.
@langchain/langgraph-checkpoint
@langchain/langgraph-checkpoint-mongodb
@langchain/langgraph-checkpoint-postgres
@langchain/langgraph-checkpoint-redis
@langchain/langgraph-checkpoint-sqlite
@langchain/langgraph-checkpoint-validation
create-langgraph
@langchain/langgraph-api
@langchain/langgraph-cli
@langchain/langgraph
@langchain/langgraph-cua
@langchain/langgraph-supervisor
@langchain/langgraph-swarm
@langchain/langgraph-ui
@langchain/langgraph-sdk
@langchain/angular
@langchain/react
@langchain/svelte
@langchain/vue
commit: |
This reverts commit c047686.
Author
|
Christian Bromann (@christian-bromann), when you have a moment, could you take a look at this PR? I’d really appreciate it |
Christian Bromann (christian-bromann)
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR, here is some feedback:
- One consistency note: PostgresStore now has both ensureTables and createSchema, but PostgresSaver has neither ensureTables nor lazy auto-setup, so createSchema is the saver's first option of this kind. Can we stay consistent and keep the saver and store option surfaces aligned (e.g. eventually adding ensureTables to the saver too).
- Small naming thought: ensureTables: false means "skip setup entirely," whereas createSchema: false means "still run setup/migrations, but verify the schema and throw if missing." A reader might expect createSchema: false to simply skip creation rather than assert. The throw-on-missing behavior is the right call, something like verifySchema/requireSchema would telegraph intent more clearly.
- Two minor things: (a)
PostgresStoreConfig.createSchemais optional butPostgresSaverOptions.createSchemais required-in-interface, both work given the different patterns, just noting the asymmetry. (b) Since this is a minor release, could you confirm whether Python langgraph's PostgresSaver/PostgresStore has an equivalent option, and match the name if so? Keeping the JS/Python APIs aligned would be ideal.
Author
Pushed the changes. Speaking of the Python implementation, I don’t think it has a similar option. I also don’t feel confident enough to contribute it myself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-out
createSchemaoption to the Postgres checkpointer and store. By default behavior is unchanged (setup()runsCREATE SCHEMA IF NOT EXISTS). When set tofalse,setup()instead verifies thetarget schema already exists and throws a clear error if it doesn't — supporting least-privilege database roles that aren't permitted to create schemas. Table migrations run either way.
Motivation
In many production environments, the connecting role cannot create schemas; the schema is provisioned out-of-band by a DBA. The previous hardcoded
CREATE SCHEMA IF NOT EXISTSeither failed or required grantingelevated privileges.
createSchema: falselets these deployments runsetup()/migrations against a pre-existing schema.Behavior
createSchemasetup()behaviortrue(default)CREATE SCHEMA IF NOT EXISTS— unchangedfalseError message when missing guides the user to either provision the schema out-of-band or set
createSchema: true.Usage