pg.ddx.io GitHub: postgresql-interfaces/psqlodbc (issues + PRs as email threads)
help / color / mirror / Atom feed[postgresql-interfaces/psqlodbc] PR #232: Add build image and threat model for the OSS Scanner
3+ messages / 1 participants
[nested] [flat]
* [postgresql-interfaces/psqlodbc] PR #232: Add build image and threat model for the OSS Scanner
@ 2026-11-03 15:14 "davecramer (@davecramer)" <noreply+davecramer@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: davecramer (@davecramer) @ 2026-11-03 15:14 UTC (permalink / raw)
To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>
Adds the two files that [OSS Scanner](https://github.com/anthropics/oss-scanner) enrolment reads from the project's repository. Their README prefers keeping them here, so the build can change without a pull request to them.
- `.oss-scanner/Dockerfile` builds both drivers on Debian bookworm with `-g -fno-omit-frame-pointer`. It installs PostgreSQL and runs the regression suite once during the build, because the scan runs without network access. A failing test does not fail the build. It uses the same `odbc_config` stand-in as `.github/workflows/linux.yml`.
- `.oss-scanner/threat_model.md` tells the scanner where untrusted input enters, which files matter, how to start the server and run the tests offline, and how we rate severity. The input sources are the server, other database users, application arguments, connection strings, and the local filesystem. The severity levels follow how the 18.00.0006 advisories were scored.
After this merges, the enrolment PR to anthropics/oss-scanner adds `projects/psqlodbc/project.yaml` with `repo`, `primary_contact`, and `dockerfile: .oss-scanner/Dockerfile` and `threat_model: .oss-scanner/threat_model.md`.
## Testing
I built the image from a clean export of this branch (`git archive`), for both `linux/arm64` and `linux/amd64`. In both builds the regression suite passed (68 of 68).
I then ran the image with `--network none`. The commands in the threat model start the server and run tests, and both `psqlodbcw.so` and `psqlodbca.so` are in `/src/.libs`.
inline patch 1: .oss-scanner/Dockerfile, .oss-scanner/threat_model.md (+111/-0 lines) download inline-1.patch
diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile
new file mode 100644
index 00000000..ccc8b518
--- /dev/null
+++ b/.oss-scanner/Dockerfile
@@ -0,0 +1,43 @@
+# Build image for the Anthropic OSS Scanner (https://github.com/anthropics/oss-scanner).
+# The scanner builds this with the repository as the build context and removes network access afterwards,
+# so everything the build and the regression tests need is installed here.
+FROM debian:bookworm
+ENV DEBIAN_FRONTEND=noninteractive
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ ca-certificates build-essential autoconf automake libtool pkg-config git python3 \
+ libpq-dev unixodbc unixodbc-dev \
+ postgresql postgresql-client \
+ && rm -rf /var/lib/apt/lists/*
+
+# configure runs odbc_config, which Debian's unixodbc-dev does not ship. The same stand-in is used by
+# .github/workflows/linux.yml.
+RUN if ! command -v odbc_config >/dev/null 2>&1; then \
+ printf '%s\n' '#!/bin/sh' \
+ 'case $1 in' \
+ ' --include-prefix) echo /usr/include ;;' \
+ ' --lib-prefix) echo /usr/lib ;;' \
+ ' --libs) echo -lodbc ;;' \
+ ' *) echo "$0: unknown argument $1"; exit 1 ;;' \
+ 'esac' > /usr/local/bin/odbc_config \
+ && chmod +x /usr/local/bin/odbc_config; \
+ fi
+
+# scanner contract: the checkout lives inside the image, at /src
+COPY . /src
+WORKDIR /src
+
+# Build both drivers (psqlodbcw.so and psqlodbca.so in .libs/) with debug info and frame pointers.
+RUN autoreconf -fi \
+ && ./configure CFLAGS="-g -O2 -fno-omit-frame-pointer" \
+ && make -j"$(nproc)"
+
+# The regression tests need a running server. Create a superuser for root and the contrib_regression
+# database, build the test programs, and run the suite once. A failing test does not fail the build.
+# The server does not survive into the image; start it again with
+# pg_ctlcluster "$(pg_lsclusters -h | awk 'NR==1{print $1}')" main start
+RUN cluster="$(pg_lsclusters -h | awk 'NR==1{print $1, $2}')" \
+ && pg_ctlcluster $cluster start \
+ && su postgres -c 'createuser -s root' \
+ && createdb contrib_regression \
+ && (cd test && make installcheck || echo "WARNING: regression tests reported failures") \
+ && pg_ctlcluster $cluster stop
diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md
new file mode 100644
index 00000000..e0b7e2e5
--- /dev/null
+++ b/.oss-scanner/threat_model.md
@@ -0,0 +1,68 @@
+# Threat model
+
+## What this project does and where untrusted input enters
+
+psqlODBC is the ODBC driver for PostgreSQL. Applications load it as a shared library (`psqlodbcw.so`, `psqlodbca.so`, or the Windows DLLs) through an ODBC driver manager, and it talks to the server through libpq. A bug in the driver runs in the application's process, with the application's privileges.
+
+Untrusted input enters from these sources, all in scope:
+
+- **The server.** Result sets, column names and types, row and column counts, error and notice fields, and large-object replies. Treat every byte the server sends as hostile: the server may be malicious or compromised, and the default `sslmode` is `disable`, so anyone on the network path can rewrite the traffic unless the connection uses `sslmode=verify-full`.
+- **Other database users.** Anyone who can create a table, view, column, function, or schema can choose names and values that the driver later reads back, for example a view with its own column named `ctid`, or a column name containing `"` or `%`.
+- **The application's arguments.** SQL text, including ODBC escape sequences (`{fn ...}`, `{d ...}`, `{ts ...}`, `{escape ...}`), table and schema names passed to the catalog functions (`SQLTables`, `SQLColumns`, `SQLSpecialColumns`, `SQLStatistics`, and the rest), column numbers, row numbers, descriptor fields, and buffer lengths. Many applications pass end-user input straight through, so the driver must not turn a bad argument into memory corruption or SQL injection.
+- **Connection strings and DSN settings.** Applications often build connection strings from user input. Escaping rules are in `docs/config.html`.
+- **The local filesystem.** The driver writes log files (`Debug`, `CommLog`) and reads `odbc.ini` and `odbcinst.ini`. Other local users are untrusted.
+
+## Components that matter most / least
+
+Most important:
+
+- Result handling: `qresult.c`, `results.c`, `connection.c` (`CC_send_query_append`, `CC_send_function`), `columninfo.c`.
+- Data conversion: `convert.c` (application SQL rewriting, escape sequences, parameter binding, type conversion) and `bind.c`.
+- Catalog functions: `info.c`.
+- Updatable cursors and keysets: `parse.c`, `results.c` (`SQLSetPos`, `SQLBulkOperations`, positioned updates and deletes).
+- Descriptors and statement attributes: `descriptor.c`, `pgapi30.c`, `options.c`.
+- Unicode entry points: `odbcapi*w.c`, `win_unicode.c`.
+- Logging: `mylog.c`.
+
+Lower priority:
+
+- Windows-only code that this image cannot build: the setup dialogs (`dlg_wingui.c`, `setup.c`), MSDTC support (`msdtc_enlist.cpp`, `pgxalib.cpp`), and the installer (`installer/`, `winbuild/`). Source review of these is still welcome.
+
+Out of scope:
+
+- `test/` is test code, and `docs/` is documentation.
+- Bugs in libpq, unixODBC, or the PostgreSQL server belong to those projects.
+
+## How to exercise it
+
+The image builds both drivers into `/src/.libs/` and the regression tests into `/src/test/exe/`. The tests need a running server:
+
+```sh
+pg_ctlcluster "$(pg_lsclusters -h | awk 'NR==1{print $1}')" main start
+cd /src/test
+make installcheck # full suite
+./runsuite keyset-overflow # one test; programs are in exe/, expected output in expected/
+```
+
+`make installcheck` creates `test/odbc.ini` and `test/odbcinst.ini`, which point at the drivers in `../.libs`. The test DSN is `psqlodbc_test_dsn` (Unicode driver) and `psqlodbc_test_dsn_ansi` (ANSI driver), connecting as `root` over the Unix socket to the `contrib_regression` database. `COMMON_CONNECTION_STRING_FOR_REGRESSION_TEST` adds settings to every test connection, for example `UseDeclareFetch=1;Fetch=1` or `UseServerSidePrepare=0`.
+
+To act as a hostile server, use a small relay in front of the local server that rewrites its replies, or reach the code path from SQL. For example, `CREATE VIEW v AS SELECT 1 AS id, repeat('x', 200) AS ctid` makes the driver's appended `ctid` column return an oversized value.
+
+A reproducer is most useful as a new program in `test/src/` with its expected output in `test/expected/`, added to `test/tests`, in the style of the existing tests.
+
+## How you rate severity
+
+We score with CVSS 3.1 and use these levels:
+
+- **High:** memory corruption (out-of-bounds write, use after free, double free, format string) reachable from the server, from another database user, or from application arguments that applications commonly take from users. SQL injection through driver-built queries is also High. An overflow without a demonstrated path to code execution is capped at High.
+- **Critical:** only with a demonstrated, reliable path to code execution from a position that needs no access.
+- **Medium:** crashes and out-of-bounds reads that only cause denial of service, and disclosure of query text or data through log files.
+- **Low:** defects that only an application can reach by calling a driver export in a way no driver manager does, or that need a misconfiguration.
+
+Being reachable only from a hostile server, or from a man-in-the-middle when `sslmode` is not `verify-full`, does not lower a finding below these levels. It sets attack complexity to high.
+
+## Anything to leave alone
+
+- An application misusing the ODBC API in ways the specification leaves undefined, when the result only affects that application and no untrusted input is involved. A buffer length the application states wrongly is an example.
+- Behaviour that needs control of the application's own process or of the driver's installation directory.
+- Findings in third-party code that the driver links against (libpq, unixODBC, OpenSSL).
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [postgresql-interfaces/psqlodbc] PR #232: Add build image and threat model for the OSS Scanner
@ 2026-11-03 15:17 "davecramer (@davecramer)" <noreply+davecramer@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: davecramer (@davecramer) @ 2026-11-03 15:17 UTC (permalink / raw)
To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>
@davecramer closed this.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [postgresql-interfaces/psqlodbc] PR #232: Add build image and threat model for the OSS Scanner
@ 2026-11-03 15:17 "davecramer (@davecramer)" <noreply+davecramer@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: davecramer (@davecramer) @ 2026-11-03 15:17 UTC (permalink / raw)
To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>
@davecramer merged this (commit 4dd02aa0e8ae).
^ permalink raw [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-11-03 15:17 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 15:14 [postgresql-interfaces/psqlodbc] PR #232: Add build image and threat model for the OSS Scanner "davecramer (@davecramer)" <noreply+davecramer@github.com>
2026-11-03 15:17 ` "davecramer (@davecramer)" <noreply+davecramer@github.com>
2026-11-03 15:17 ` "davecramer (@davecramer)" <noreply+davecramer@github.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox