Repository navigation
fix: harden payload validation, PostgreSQL entry points and network handling - #96
Merged
Merged
Conversation
…, SQL injection) - cloudsync_changes_insert_trigger refuses a table that lacks the cloudsync_changes layout (attaching it to another table crashed the backend) - a name value is no longer treated as a varlena (out-of-bounds read) - cloudsync_update and database_value_dup copy every pass-by-reference datum - payload and update aggregates refuse a window context - database_column_blob only reads bytea columns - single quotes in table/column names are escaped in generated SQL, trigger bodies use a dedicated dollar-quote tag, and the update trigger quotes the table literal correctly (tables with a ' in the name can now be initialized) - add test 68_hardening; bump version to 1.2.1 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- sqlite: validate argument counts/types in cloudsync_insert/delete/update instead of reading out of bounds - core: reject pk blobs whose component count differs from the table's pks (merge_insert, merge_insert_col, merge_sentinel_only_insert) - postgres: check NULL tbl in the cloudsync_changes insert trigger - postgres: schema-qualify extension functions in generated triggers to defeat search_path hijacking - network: make cloudsync_network_* DIRECTONLY (no longer INNOCUOUS) - network: drop token/apikey/org when init_custom switches origin; require https (http only for loopback); validate database id and credentials Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- network: cap responses at 1e9 bytes and always NUL-terminate the buffer (HTTP error bodies on binary downloads were read past their end) - payload: reassemble v3 fragments only if staged bytes match total_size; cap total_size and LZ4 expanded_size at 1e9 - sqlite: cloudsync_payload_save/load are SQLITE_DIRECTONLY - postgres: look up trigger names on the table being initialised - postgres: use *_cloudsync tables only when they have the metadata shape, a same-owner base table and are readable by the caller - postgres: bump_app_schema_version is SECURITY DEFINER with a pinned search_path; init is idempotent for roles that do not own the event trigger Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ew did not cover - core: 16-byte site ids, block column names and position ids validated as well-formed order keys, clock values bounded, nine columns for every payload version, pk_decode no longer negates out-of-range magnitudes - network: only 2xx is a success, ticket accepted from API endpoints only, balanced curl_global_cleanup, strict JSON, network.m refuses redirects and survives a missing endpoint - sqlite: payload_chunks resume offset checked, zero-argument payload decode/apply, quoted blocks tables, escaped metadata suffix match with a shape filter, atomic set_filter/clear_filter, rowid left to SQLite - postgres: text with NUL refused, payload_chunks NULL and resume checks, hashed trigger names beyond 63 bytes, quote-heavy column names, database_value_text rethrows non-data errors - fractional-indexing allocator set once per process (data race) - tests: apply fuzzer (ASan/UBSan, TSan, MSan), RLS isolation, low-finding regressions Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The NULL col_value fix itself is already in the security fixes; keep the regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…k case pk_decode now refuses a magnitude past INT64_MAX, so the old 2^63+1 case no longer applies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A hashed aggregate that is rescanned without being rebuilt finalizes the same group state again. The final function encoded and released the state's buffer, so a second call worked on freed memory. The state now caches the encoded result and every later call returns a copy of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_changes view The trigger function is PUBLIC-callable. Attached at statement level it has no tuple to read; attached to another relation with the same columns it is not an insert into the changes view. It now requires a row-level INSTEAD OF INSERT trigger on the cloudsync_changes view of the extension's schema. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The encoder always writes zero as a positive integer, so a negative zero only comes from a forged blob and would alias the key 0. The noncanonical pk test now uses a wider-than-needed zero instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing the payload Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alls to SECURITY DEFINER Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at a NUL Document that PostgreSQL text is stored up to the first NUL character and that binary or encrypted data belongs in BLOB/BYTEA columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…locator Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Hardening across the SQLite and PostgreSQL extensions and the network layer, plus fixes found while reviewing it.
cloudsync_changestrigger;cloudsync_set_filter()keeps the previous filter when a new one doesn't compile.<table>_cloudsynctables of registered tables are counted, so lookalike tables are ignored. On SQLite the name match is case-insensitive. A dropped table never lowerscloudsync_db_version().cloudsync_network_init_custom()changes address.Behaviour changes
cloudsync_network_*,cloudsync_payload_save()andcloudsync_payload_load()can only be called directly, not from views, triggers or CHECK constraints. Direct queries, including recursive CTE loops, still work.https://(http://only for localhost).cloudsync_network_init_custom()with a different address clears the previous token, API key and organization.Notes
SECURITY DEFINERschema-version function on context load, when the session owns it. This step runs DDL inside the caller's transaction, so a rollback defers it to the next load. Sync roles never own the function, so it never runs on the apply path.docs/postgresql/README.mdlists the NUL limitation and recommendsBLOB/BYTEAfor binary or encrypted data.Tests
68–74,test/review_regressions.c, and an apply fuzzer intest/fuzz.make unittest: all OK, 0 failed.make network-unittest: all passed.🤖 Generated with Claude Code