Skip to content

Commit 4eb8414

Browse files
author
vrana
committed
Convert everything to safe HTML
Summary: Sgrepped for `"=~/</"` and manually changed every HTML. Test Plan: This doesn't work yet but it is hopefully one of the last diffs before Phabricator will be undoubtedly HTML safe. Reviewers: epriestley CC: aran, Korvin Maniphest Tasks: T2432 Differential Revision: https://secure.phabricator.com/D4927
1 parent 718d22d commit 4eb8414

File tree

60 files changed

+486
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+486
-425
lines changed

src/aphront/AphrontRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
final class AphrontRequest {
1010

1111
// NOTE: These magic request-type parameters are automatically included in
12-
// certain requests (e.g., by phabricator_render_form(), JX.Request,
12+
// certain requests (e.g., by phabricator_form(), JX.Request,
1313
// JX.Workflow, and ConduitClient) and help us figure out what sort of
1414
// response the client expects.
1515

src/aphront/console/plugin/DarkConsoleErrorLogPlugin.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function renderPanel() {
3636
$data = $this->getData();
3737

3838
$rows = array();
39-
$details = '';
39+
$details = array();
4040

4141
foreach ($data as $index => $row) {
4242
$file = $row['file'];
@@ -50,7 +50,7 @@ public function renderPanel() {
5050
$row['str'].' at ['.basename($file).':'.$line.']');
5151
$rows[] = array($tag);
5252

53-
$details .= hsprintf(
53+
$details[] = hsprintf(
5454
'<div class="dark-console-panel-error-details" id="row-details-%s">'.
5555
"%s\nStack trace:\n",
5656
$index,
@@ -73,28 +73,30 @@ public function renderPanel() {
7373
}
7474
}
7575

76-
$details .= phutil_tag(
76+
$details[] = phutil_tag(
7777
'a',
7878
array(
7979
'href' => $href,
8080
),
8181
$line);
82-
$details .= "\n";
82+
$details[] = "\n";
8383
}
8484

85-
$details .= '</div>';
85+
$details[] = hsprintf('</div>');
8686
}
8787

8888
$table = new AphrontTableView($rows);
8989
$table->setClassName('error-log');
9090
$table->setHeaders(array('Error'));
9191
$table->setNoDataString('No errors.');
9292

93-
return '<div>'.
94-
'<div>'.$table->render().'</div>'.
95-
'<pre class="PhabricatorMonospaced">'.
96-
$details.'</pre>'.
97-
'</div>';
93+
return hsprintf(
94+
'<div>'.
95+
'<div>%s</div>'.
96+
'<pre class="PhabricatorMonospaced">%s</pre>'.
97+
'</div>',
98+
$table->render(),
99+
phutil_implode_html('', $details));
98100
}
99101
}
100102

src/aphront/console/plugin/DarkConsoleEventPlugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public function renderPanel() {
4242

4343
$out = array();
4444

45-
$out[] =
45+
$out[] = hsprintf(
4646
'<div class="dark-console-panel-header">'.
4747
'<h1>Registered Event Listeners</h1>'.
48-
'</div>';
48+
'</div>');
4949

5050
$rows = array();
5151
foreach ($data['listeners'] as $listener) {
@@ -66,10 +66,10 @@ public function renderPanel() {
6666

6767
$out[] = $table->render();
6868

69-
$out[] =
69+
$out[] = hsprintf(
7070
'<div class="dark-console-panel-header">'.
7171
'<h1>Event Log</h1>'.
72-
'</div>';
72+
'</div>');
7373

7474
$rows = array();
7575
foreach ($data['events'] as $event) {
@@ -93,6 +93,6 @@ public function renderPanel() {
9393
$out[] = $table->render();
9494

9595

96-
return implode("\n", $out);
96+
return phutil_implode_html("\n", $out);
9797
}
9898
}

src/aphront/console/plugin/DarkConsoleRequestPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public function renderPanel() {
6262
$out[] = $table->render();
6363
}
6464

65-
return implode("\n", $out);
65+
return phutil_implode_html("\n", $out);
6666
}
6767
}

src/aphront/console/plugin/DarkConsoleServicesPlugin.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,21 @@ public function renderPanel() {
149149
$log = $data['log'];
150150
$results = array();
151151

152-
$results[] =
152+
$results[] = hsprintf(
153153
'<div class="dark-console-panel-header">'.
154-
phutil_tag(
155-
'a',
156-
array(
157-
'href' => $data['analyzeURI'],
158-
'class' => $data['didAnalyze']
159-
? 'disabled button'
160-
: 'green button',
161-
),
162-
'Analyze Query Plans').
154+
'%s'.
163155
'<h1>Calls to External Services</h1>'.
164156
'<div style="clear: both;"></div>'.
165-
'</div>';
157+
'</div>',
158+
phutil_tag(
159+
'a',
160+
array(
161+
'href' => $data['analyzeURI'],
162+
'class' => $data['didAnalyze']
163+
? 'disabled button'
164+
: 'green button',
165+
),
166+
'Analyze Query Plans'));
166167

167168
$page_total = $data['end'] - $data['start'];
168169
$totals = array();
@@ -271,7 +272,7 @@ public function renderPanel() {
271272

272273
$results[] = $table->render();
273274

274-
return implode("\n", $results);
275+
return phutil_implode_html("\n", $results);
275276
}
276277
}
277278

src/aphront/console/plugin/DarkConsoleXHProfPlugin.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,48 +51,52 @@ public function renderPanel() {
5151
'class' => 'bright-link',
5252
),
5353
'Installation Guide');
54-
return
54+
return hsprintf(
5555
'<div class="dark-console-no-content">'.
5656
'The "xhprof" PHP extension is not available. Install xhprof '.
5757
'to enable the XHProf console plugin. You can find instructions in '.
58-
'the '.$install_guide.'.'.
59-
'</div>';
58+
'the %s.'.
59+
'</div>',
60+
$install_guide);
6061
}
6162

6263
$result = array();
6364

64-
$header =
65+
$header = hsprintf(
6566
'<div class="dark-console-panel-header">'.
66-
phutil_tag(
67-
'a',
68-
array(
69-
'href' => $profile_uri,
70-
'class' => $run
71-
? 'disabled button'
72-
: 'green button',
73-
),
74-
'Profile Page').
67+
'%s'.
7568
'<h1>XHProf Profiler</h1>'.
76-
'</div>';
69+
'</div>',
70+
phutil_tag(
71+
'a',
72+
array(
73+
'href' => $profile_uri,
74+
'class' => $run
75+
? 'disabled button'
76+
: 'green button',
77+
),
78+
'Profile Page'));
7779
$result[] = $header;
7880

7981
if ($run) {
80-
$result[] =
81-
'<a href="/xhprof/profile/'.$run.'/" '.
82+
$result[] = hsprintf(
83+
'<a href="/xhprof/profile/%s/" '.
8284
'class="bright-link" '.
8385
'style="float: right; margin: 1em 2em 0 0;'.
8486
'font-weight: bold;" '.
8587
'target="_blank">Profile Permalink</a>'.
86-
'<iframe src="/xhprof/profile/'.$run.'/?frame=true"></iframe>';
88+
'<iframe src="/xhprof/profile/%s/?frame=true"></iframe>',
89+
$run,
90+
$run);
8791
} else {
88-
$result[] =
92+
$result[] = hsprintf(
8993
'<div class="dark-console-no-content">'.
9094
'Profiling was not enabled for this page. Use the button above '.
9195
'to enable it.'.
92-
'</div>';
96+
'</div>');
9397
}
9498

95-
return implode("\n", $result);
99+
return phutil_implode_html("\n", $result);
96100
}
97101

98102

src/aphront/response/AphrontWebpageResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function setContent($content) {
1313
}
1414

1515
public function buildResponseString() {
16-
return $this->content;
16+
return hsprintf('%s', $this->content);
1717
}
1818

1919
}

src/applications/auth/controller/PhabricatorEmailLoginController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public function processRequest() {
138138

139139
$panel = new AphrontPanelView();
140140
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
141-
$panel->appendChild('
142-
<h1>'.pht('Forgot Password / Email Login').'</h1>');
141+
$panel->appendChild(phutil_tag('h1', array(), pht(
142+
'Forgot Password / Email Login')));
143143
$panel->appendChild($email_auth);
144144
$panel->setNoBackground();
145145

src/applications/auth/controller/PhabricatorLDAPLoginController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function processRequest() {
131131

132132
$panel = new AphrontPanelView();
133133
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
134-
$panel->appendChild('<h1>'.pht('LDAP login').'</h1>');
134+
$panel->appendChild(phutil_tag('h1', array(), pht('LDAP login')));
135135
$panel->appendChild($ldap_form);
136136

137137
$error_view = null;

src/applications/auth/controller/PhabricatorLoginValidateController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function processRequest() {
5353
'<p>%s</p>%s<p>%s</p>',
5454
pht('Login failed:'),
5555
$list,
56-
pht('<strong>Clear your cookies</strong> and try again.')));
56+
pht(
57+
'<strong>Clear your cookies</strong> and try again.',
58+
hsprintf(''))));
5759
$view->appendChild(hsprintf(
5860
'<div class="aphront-failure-continue">'.
5961
'<a class="button" href="/login/">%s</a>'.

src/applications/auth/controller/PhabricatorOAuthDiagnosticsController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ private function renderResults($results) {
186186

187187
$panel_view = new AphrontPanelView();
188188
$panel_view->setHeader($title);
189-
$panel_view->appendChild(
189+
$panel_view->appendChild(hsprintf(
190190
'<p class="aphront-panel-instructions">These tests may be able to '.
191-
'help diagnose the root cause of problems you experience with '.
192-
$provider->getProviderName() .
193-
' Authentication. Reload the page to run the tests again.</p>');
191+
'help diagnose the root cause of problems you experience with %s '.
192+
'Authentication. Reload the page to run the tests again.</p>',
193+
$provider->getProviderName()));
194194
$panel_view->appendChild($table_view);
195195

196196
return $this->buildStandardPageResponse(

src/applications/base/controller/PhabricatorController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ public function didProcessRequest($response) {
203203
$view = new PhabricatorStandardPageView();
204204
$view->setRequest($request);
205205
$view->setController($this);
206-
$view->appendChild(
207-
'<div style="padding: 2em 0;">'.
208-
$response->buildResponseString().
209-
'</div>');
206+
$view->appendChild(hsprintf(
207+
'<div style="padding: 2em 0;">%s</div>',
208+
$response->buildResponseString()));
210209
$response = new AphrontWebpageResponse();
211210
$response->setContent($view->render());
212211
return $response;

src/applications/conduit/controller/PhabricatorConduitListController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public function processRequest() {
5959

6060
$utils = new AphrontPanelView();
6161
$utils->setHeader('Utilities');
62-
$utils->appendChild(
62+
$utils->appendChild(hsprintf(
6363
'<ul>'.
6464
'<li><a href="/conduit/log/">Log</a> - Conduit Method Calls</li>'.
6565
'<li><a href="/conduit/token/">Token</a> - Certificate Install</li>'.
66-
'</ul>');
66+
'</ul>'));
6767
$utils->setWidth(AphrontPanelView::WIDTH_FULL);
6868

6969
$this->setShowSideNav(false);

src/applications/config/response/PhabricatorConfigResponse.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@ public function buildResponseString() {
2323

2424
$view = $this->view->render();
2525

26-
$template = <<<EOTEMPLATE
27-
<!doctype html>
28-
<html>
29-
<head>
30-
<title>Phabricator Setup</title>
31-
{$resources}
32-
</head>
33-
<body class="setup-fatal">
34-
{$view}
35-
</body>
36-
</html>
37-
EOTEMPLATE;
38-
39-
return $template;
26+
return hsprintf(
27+
'<!DOCTYPE html>'.
28+
'<html>'.
29+
'<head>'.
30+
'<meta charset="UTF-8" />'.
31+
'<title>Phabricator Setup</title>'.
32+
'%s'.
33+
'</head>'.
34+
'<body class="setup-fatal">%s</body>'.
35+
'</html>',
36+
$resources,
37+
$view);
4038
}
4139

4240
private function buildResources() {
@@ -49,11 +47,12 @@ private function buildResources() {
4947

5048
$resources = array();
5149
foreach ($css as $path) {
52-
$resources[] = '<style type="text/css">';
53-
$resources[] = Filesystem::readFile($webroot.'/rsrc/css/'.$path);
54-
$resources[] = '</style>';
50+
$resources[] = phutil_tag(
51+
'style',
52+
array('type' => 'text/css'),
53+
Filesystem::readFile($webroot.'/rsrc/css/'.$path));
5554
}
56-
return implode("\n", $resources);
55+
return phutil_implode_html("\n", $resources);
5756
}
5857

5958

src/applications/conpherence/controller/ConpherenceViewController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function renderMessagePaneContent() {
149149
->setMarkupEngine($engine)
150150
->render();
151151
}
152-
$transactions = implode(' ', $rendered_transactions);
152+
$transactions = phutil_implode_html(' ', $rendered_transactions);
153153

154154
$form =
155155
id(new AphrontFormView())
@@ -292,7 +292,7 @@ private function renderFilesWidgetPaneContent() {
292292
->setNoDataString(pht('No files attached to conpherence.'))
293293
->setHeaders(array('', pht('Name')))
294294
->setColumnClasses(array('', 'wide'));
295-
return new PhutilSafeHTML($header->render() . $table->render());
295+
return hsprintf('%s%s', $header->render(), $table->render());
296296
}
297297

298298
private function renderTaskWidgetPaneContent() {
@@ -328,7 +328,7 @@ private function renderTaskWidgetPaneContent() {
328328
->setColumnClasses(array('', 'wide'));
329329
$content[] = $table->render();
330330
}
331-
return new PhutilSafeHTML(implode('', $content));
331+
return phutil_implode_html('', $content);
332332
}
333333

334334
private function renderCalendarWidgetPaneContent() {
@@ -416,7 +416,7 @@ private function renderCalendarWidgetPaneContent() {
416416
}
417417
}
418418

419-
return new PhutilSafeHTML(implode('', $content));
419+
return phutil_implode_html('', $content);
420420
}
421421

422422
private function getCalendarWidgetWeekTimestamps() {

0 commit comments

Comments
 (0)