mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Restore PGREQUIRESSL recognition in libpq.
Commit65c3bf19fdmoved handling of the, already then, deprecated requiressl parameter into conninfo_storeval(). The default PGREQUIRESSL environment variable was however lost in the change resulting in a potentially silent accept of a non-SSL connection even when set. Its documentation remained. Restore its implementation. Also amend the documentation to mark PGREQUIRESSL as deprecated for those not following the link to requiressl. Back-patch to 9.3, where commit65c3bf1first appeared. Behavior has been more complex when the user provides both deprecated and non-deprecated settings. Before commit65c3bf1, libpq operated according to the first of these found: requiressl=1 PGREQUIRESSL=1 sslmode=* PGSSLMODE=* (Note requiressl=0 didn't override sslmode=*; it would only suppress PGREQUIRESSL=1 or a previous requiressl=1. PGREQUIRESSL=0 had no effect whatsoever.) Starting with commit65c3bf1, libpq ignored PGREQUIRESSL, and order of precedence changed to this: last of requiressl=* or sslmode=* PGSSLMODE=* Starting now, adopt the following order of precedence: last of requiressl=* or sslmode=* PGSSLMODE=* PGREQUIRESSL=1 This retains the65c3bf1behavior for connection strings that contain both requiressl=* and sslmode=*. It retains the65c3bf1change that either connection string option overrides both environment variables. For the first time, PGSSLMODE has precedence over PGREQUIRESSL; this avoids reducing security of "PGREQUIRESSL=1 PGSSLMODE=verify-full" configurations originating under v9.3 and later. Daniel Gustafsson Security: CVE-2017-7485
This commit is contained in:
		@@ -6710,6 +6710,9 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
 | 
			
		||||
      </indexterm>
 | 
			
		||||
      <envar>PGREQUIRESSL</envar> behaves the same as the <xref
 | 
			
		||||
      linkend="libpq-connect-requiressl"> connection parameter.
 | 
			
		||||
      This environment variable is deprecated in favor of the
 | 
			
		||||
      <envar>PGSSLMODE</envar> variable; setting both variables suppresses the
 | 
			
		||||
      effect of this one.
 | 
			
		||||
     </para>
 | 
			
		||||
    </listitem>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4608,6 +4608,30 @@ conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * Interpret the deprecated PGREQUIRESSL environment variable.  Per
 | 
			
		||||
		 * tradition, translate values starting with "1" to sslmode=require,
 | 
			
		||||
		 * and ignore other values.  Given both PGREQUIRESSL=1 and PGSSLMODE,
 | 
			
		||||
		 * PGSSLMODE takes precedence; the opposite was true before v9.3.
 | 
			
		||||
		 */
 | 
			
		||||
		if (strcmp(option->keyword, "sslmode") == 0)
 | 
			
		||||
		{
 | 
			
		||||
			const char *requiresslenv = getenv("PGREQUIRESSL");
 | 
			
		||||
 | 
			
		||||
			if (requiresslenv != NULL && requiresslenv[0] == '1')
 | 
			
		||||
			{
 | 
			
		||||
				option->val = strdup("require");
 | 
			
		||||
				if (!option->val)
 | 
			
		||||
				{
 | 
			
		||||
					if (errorMessage)
 | 
			
		||||
						printfPQExpBuffer(errorMessage,
 | 
			
		||||
										  libpq_gettext("out of memory\n"));
 | 
			
		||||
					return false;
 | 
			
		||||
				}
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * No environment variable specified or the variable isn't set - try
 | 
			
		||||
		 * compiled-in default
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user