Branch data Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * be-fe-helpers.c
4 : : * Helper functions for using libpq in extensions
5 : : *
6 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : *-------------------------------------------------------------------------
10 : : */
11 : :
12 : : #include "postgres.h"
13 : :
14 : : /*
15 : : * XXX: This is duplicated from libpq-be-fe-helpers.h, because including that
16 : : * header in backend source files is prohibited. Be sure to update its copy if
17 : : * this signature changes.
18 : : */
19 : : extern bool libpqsrv_is_valid_proxy_option(const char *keyword);
20 : :
21 : : /*
22 : : * Is the named libpq connection option known to be safe for an otherwise-
23 : : * unprivileged user to set on an outgoing connection, whether in a server
24 : : * extension, FDW, subscription, or otherwise?
25 : : *
26 : : * The vast majority of libpq-be-fe-helpers.h is `static inline`, but the
27 : : * safelist is kept here so that we can update it without recompiling dependent
28 : : * extensions. Since we must maintain safety with future versions of libpq, new
29 : : * known-safe options must unfortunately be backpatched into prior branches as
30 : : * needed.
31 : : */
32 : : bool
33 : 3501 : libpqsrv_is_valid_proxy_option(const char *keyword)
34 : : {
35 : : /*-
36 : : * NB: When modifying this list, ask yourself:
37 : : * - Can this new option be used to write local files, disclose server
38 : : * secrets, or bypass proxy authentication requirements?
39 : : * - When will you backpatch this addition to supported branches?
40 : : */
41 [ + + + + : 3501 : switch (keyword[0])
- + - - -
+ + + + -
+ - ]
42 : : {
43 : 272 : case 'a':
44 [ + - ]: 272 : if (strcmp(keyword, "application_name") == 0)
45 : 272 : return true;
46 : 0 : break;
47 : :
48 : 91 : case 'c':
49 [ - + ]: 91 : if (strcmp(keyword, "channel_binding") == 0)
50 : 0 : return true;
51 [ + - ]: 91 : if (strcmp(keyword, "client_encoding") == 0)
52 : 91 : return true;
53 [ # # ]: 0 : if (strcmp(keyword, "connect_timeout") == 0)
54 : 0 : return true;
55 : 0 : break;
56 : :
57 : 1038 : case 'd':
58 [ + - ]: 1038 : if (strcmp(keyword, "dbname") == 0)
59 : 1038 : return true;
60 : 0 : break;
61 : :
62 : 91 : case 'f':
63 [ + - ]: 91 : if (strcmp(keyword, "fallback_application_name") == 0)
64 : 91 : return true;
65 : 0 : break;
66 : :
67 : 0 : case 'g':
68 [ # # ]: 0 : if (strcmp(keyword, "gssdelegation") == 0)
69 : 0 : return true;
70 [ # # ]: 0 : if (strcmp(keyword, "gssencmode") == 0)
71 : 0 : return true;
72 [ # # ]: 0 : if (strcmp(keyword, "gsslib") == 0)
73 : 0 : return true;
74 : 0 : break;
75 : :
76 : 875 : case 'h':
77 [ + - ]: 875 : if (strcmp(keyword, "host") == 0)
78 : 875 : return true;
79 [ # # ]: 0 : if (strcmp(keyword, "hostaddr") == 0)
80 : 0 : return true;
81 : 0 : break;
82 : :
83 : 0 : case 'k':
84 [ # # ]: 0 : if (strcmp(keyword, "keepalives") == 0)
85 : 0 : return true;
86 [ # # ]: 0 : if (strcmp(keyword, "keepalives_count") == 0)
87 : 0 : return true;
88 [ # # ]: 0 : if (strcmp(keyword, "keepalives_idle") == 0)
89 : 0 : return true;
90 [ # # ]: 0 : if (strcmp(keyword, "keepalives_interval") == 0)
91 : 0 : return true;
92 [ # # ]: 0 : if (strcmp(keyword, "krbsrvname") == 0)
93 : 0 : return true;
94 : 0 : break;
95 : :
96 : 0 : case 'l':
97 [ # # ]: 0 : if (strcmp(keyword, "load_balance_hosts") == 0)
98 : 0 : return true;
99 : 0 : break;
100 : :
101 : 0 : case 'm':
102 [ # # ]: 0 : if (strcmp(keyword, "max_protocol_version") == 0)
103 : 0 : return true;
104 [ # # ]: 0 : if (strcmp(keyword, "min_protocol_version") == 0)
105 : 0 : return true;
106 : 0 : break;
107 : :
108 : 14 : case 'o':
109 : :
110 : : /*
111 : : * oauth_* options are not ready for server-side use, due to the
112 : : * builtin flow's use of stderr and the inability to constrain the
113 : : * issuer.
114 : : */
115 : :
116 : : /* if (strcmp(keyword, "oauth_ca_file") == 0) */
117 : : /* if (strcmp(keyword, "oauth_client_id") == 0) */
118 : : /* if (strcmp(keyword, "oauth_client_secret") == 0) */
119 : : /* if (strcmp(keyword, "oauth_issuer") == 0) */
120 : : /* if (strcmp(keyword, "oauth_scope") == 0) */
121 : :
122 [ + + ]: 14 : if (strcmp(keyword, "options") == 0)
123 : 9 : return true;
124 : 5 : break;
125 : :
126 : 1004 : case 'p':
127 [ - + ]: 1004 : if (strcmp(keyword, "passfile") == 0)
128 : 0 : return true;
129 [ + + ]: 1004 : if (strcmp(keyword, "password") == 0)
130 : 18 : return true;
131 [ + - ]: 986 : if (strcmp(keyword, "port") == 0)
132 : 986 : return true;
133 : 0 : break;
134 : :
135 : 8 : case 'r':
136 [ - + ]: 8 : if (strcmp(keyword, "replication") == 0)
137 : 0 : return true;
138 [ + - ]: 8 : if (strcmp(keyword, "require_auth") == 0)
139 : 8 : return true;
140 [ # # ]: 0 : if (strcmp(keyword, "requirepeer") == 0)
141 : 0 : return true;
142 : 0 : break;
143 : :
144 : 86 : case 's':
145 [ + + ]: 86 : if (strcmp(keyword, "scram_client_key") == 0)
146 : 8 : return true;
147 [ + + ]: 78 : if (strcmp(keyword, "scram_server_key") == 0)
148 : 8 : return true;
149 [ + + ]: 70 : if (strcmp(keyword, "service") == 0)
150 : 1 : return true;
151 [ - + ]: 69 : if (strcmp(keyword, "ssl_max_protocol_version") == 0)
152 : 0 : return true;
153 [ - + ]: 69 : if (strcmp(keyword, "ssl_min_protocol_version") == 0)
154 : 0 : return true;
155 [ - + ]: 69 : if (strcmp(keyword, "sslcert") == 0)
156 : 0 : return true;
157 [ - + ]: 69 : if (strcmp(keyword, "sslcertmode") == 0)
158 : 0 : return true;
159 [ - + ]: 69 : if (strcmp(keyword, "sslcompression") == 0)
160 : 0 : return true;
161 [ - + ]: 69 : if (strcmp(keyword, "sslcrl") == 0)
162 : 0 : return true;
163 [ - + ]: 69 : if (strcmp(keyword, "sslcrldir") == 0)
164 : 0 : return true;
165 [ - + ]: 69 : if (strcmp(keyword, "sslkey") == 0)
166 : 0 : return true;
167 : :
168 : : /* sslkeylogfile writes to arbitrary file locations. */
169 : : /* if (strcmp(keyword, "sslkeylogfile") == 0) */
170 : :
171 [ - + ]: 69 : if (strcmp(keyword, "sslmode") == 0)
172 : 0 : return true;
173 [ - + ]: 69 : if (strcmp(keyword, "sslnegotiation") == 0)
174 : 0 : return true;
175 [ - + ]: 69 : if (strcmp(keyword, "sslpassword") == 0)
176 : 0 : return true;
177 [ - + ]: 69 : if (strcmp(keyword, "sslrootcert") == 0)
178 : 0 : return true;
179 [ - + ]: 69 : if (strcmp(keyword, "sslsni") == 0)
180 : 0 : return true;
181 : 69 : break;
182 : :
183 : 0 : case 't':
184 [ # # ]: 0 : if (strcmp(keyword, "target_session_attrs") == 0)
185 : 0 : return true;
186 [ # # ]: 0 : if (strcmp(keyword, "tcp_user_timeout") == 0)
187 : 0 : return true;
188 : 0 : break;
189 : :
190 : 22 : case 'u':
191 [ + - ]: 22 : if (strcmp(keyword, "user") == 0)
192 : 22 : return true;
193 : 0 : break;
194 : : }
195 : :
196 : : /* Unknown or disallowed option. */
197 : 74 : return false;
198 : : }
|