@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refine the "Mangled Webserver Response" setup check

Summary:
Ref T13259. In some configurations, making a request to ourselves may return a VPN/Auth response from some LB/appliance layer.

If this response begins or ends with whitespace, we currently detect it as "extra whitespace" instead of "bad response".

Instead, require that the response be nearly correct (valid JSON with some extra whitespace, instead of literally anything with some extra whitespace) to hit this specialized check. If we don't hit the specialized case, use the generic "mangled" response error, which prints the actual body so you can figure out that it's just your LB/auth thing doing what it's supposed to do.

Test Plan:
- Rigged responses to add extra whitespace, got "Extra Whitespace" (same as before).
- Rigged responses to add extra non-whitespace, got "Mangled Junk" (same as before).
- Rigged responses to add extra whitespace and extra non-whitespace, got "Mangled Junk" with a sample of the document body instead of "Extra Whitespace" (improvement).

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13259

Differential Revision: https://secure.phabricator.com/D20235

+20 -22
-1
src/aphront/configuration/AphrontApplicationConfiguration.php
··· 776 776 'filler' => str_repeat('Q', 1024 * 16), 777 777 ); 778 778 779 - 780 779 return id(new AphrontJSONResponse()) 781 780 ->setAddJSONShield(false) 782 781 ->setContent($result);
+20 -21
src/applications/config/check/PhabricatorWebServerSetupCheck.php
··· 129 129 } 130 130 131 131 $structure = null; 132 - $caught = null; 133 132 $extra_whitespace = ($body !== trim($body)); 134 133 135 - if (!$extra_whitespace) { 136 - try { 137 - $structure = phutil_json_decode($body); 138 - } catch (Exception $ex) { 139 - $caught = $ex; 140 - } 134 + try { 135 + $structure = phutil_json_decode(trim($body)); 136 + } catch (Exception $ex) { 137 + // Ignore the exception, we only care if the decode worked or not. 141 138 } 142 139 143 - if (!$structure) { 144 - if ($extra_whitespace) { 145 - $message = pht( 146 - 'Phabricator sent itself a test request and expected to get a bare '. 147 - 'JSON response back, but the response had extra whitespace at '. 148 - 'the beginning or end.'. 149 - "\n\n". 150 - 'This usually means you have edited a file and left whitespace '. 151 - 'characters before the opening %s tag, or after a closing %s tag. '. 152 - 'Remove any leading whitespace, and prefer to omit closing tags.', 153 - phutil_tag('tt', array(), '<?php'), 154 - phutil_tag('tt', array(), '?>')); 155 - } else { 140 + if (!$structure || $extra_whitespace) { 141 + if (!$structure) { 156 142 $short = id(new PhutilUTF8StringTruncator()) 157 143 ->setMaximumGlyphs(1024) 158 144 ->truncateString($body); ··· 166 152 "\n\n". 167 153 'Something is misconfigured or otherwise mangling responses.', 168 154 phutil_tag('pre', array(), $short)); 155 + } else { 156 + $message = pht( 157 + 'Phabricator sent itself a test request and expected to get a bare '. 158 + 'JSON response back. It received a JSON response, but the response '. 159 + 'had extra whitespace at the beginning or end.'. 160 + "\n\n". 161 + 'This usually means you have edited a file and left whitespace '. 162 + 'characters before the opening %s tag, or after a closing %s tag. '. 163 + 'Remove any leading whitespace, and prefer to omit closing tags.', 164 + phutil_tag('tt', array(), '<?php'), 165 + phutil_tag('tt', array(), '?>')); 169 166 } 170 167 171 168 $this->newIssue('webserver.mangle') ··· 174 171 ->setMessage($message); 175 172 176 173 // We can't run the other checks if we could not decode the response. 177 - return; 174 + if (!$structure) { 175 + return; 176 + } 178 177 } 179 178 180 179 $actual_user = idx($structure, 'user');