Repository navigation
Commit 0639b37
pgconn: add ParseConfigOptions.ConnStringAllowedKeys
If any portion of the DSN is attacker-influenced (an app builds
postgres://host/db?<user_supplied_options>, or a tenant supplies a
connection URL), the attacker can set servicefile=, sslkey=, sslcert=,
sslrootcert=, or passfile= to read arbitrary local files or, via
servicefile, redirect the connection to a host they choose. libpq
deliberately does not accept servicefile from the connection string for
this reason; pgx's divergence has been documented but remains a
footgun.
Add ParseConfigOptions.ConnStringAllowedKeys, a caller-supplied
allow-list of parameter keys permitted in connString. Any key outside
the list causes ParseConfigWithOptions to fail before any filesystem or
network access. Environment variables and defaults are unaffected. The
default (nil) preserves existing behaviour. Fails closed: future libpq
keywords that pgconn learns to parse are rejected unless the caller
allow-lists them.
Also consolidate the three duplicated {"dbname": "database"} alias
maps in config.go into a package-level connStringKeyAliases map plus a
canonicalConnStringKey() helper used by all parsers and by the new
check.
Reported by CrowdStrike (F08/F09).1 parent b28e65b commit 0639b37
2 files changed
Lines changed: 131 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
115 | 130 | | |
116 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
117 | 151 | | |
118 | 152 | | |
119 | 153 | | |
| |||
298 | 332 | | |
299 | 333 | | |
300 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
301 | 347 | | |
302 | 348 | | |
303 | 349 | | |
| |||
615 | 661 | | |
616 | 662 | | |
617 | 663 | | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | 664 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
| 665 | + | |
628 | 666 | | |
629 | 667 | | |
630 | 668 | | |
| |||
639 | 677 | | |
640 | 678 | | |
641 | 679 | | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | 680 | | |
647 | 681 | | |
648 | 682 | | |
| |||
693 | 727 | | |
694 | 728 | | |
695 | 729 | | |
696 | | - | |
697 | | - | |
698 | | - | |
| 730 | + | |
699 | 731 | | |
700 | 732 | | |
701 | 733 | | |
| |||
721 | 753 | | |
722 | 754 | | |
723 | 755 | | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | 756 | | |
729 | 757 | | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
| 758 | + | |
734 | 759 | | |
735 | 760 | | |
736 | 761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
0 commit comments