Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print exception messages in html #26460

Merged
merged 2 commits into from Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 4 additions & 13 deletions apps/dav/lib/Files/BrowserErrorPagePlugin.php
Expand Up @@ -80,38 +80,29 @@ public function logException(\Exception $ex) {
}
$this->server->httpResponse->addHeaders($headers);
$this->server->httpResponse->setStatus($httpCode);
$body = $this->generateBody($ex);
$body = $this->generateBody();
$this->server->httpResponse->setBody($body);
$this->sendResponse();
}

/**
* @codeCoverageIgnore
* @param \Exception $ex
* @param int $httpCode
* @return bool|string
*/
public function generateBody(\Exception $exception) {
public function generateBody() {
$request = \OC::$server->getRequest();
$content = new OC_Template('dav', 'exception', 'guest');
$content->assign('title', $this->server->httpResponse->getStatusText());
$content->assign('message', $exception->getMessage());
$content->assign('errorClass', get_class($exception));
$content->assign('errorMsg', $exception->getMessage());
$content->assign('errorCode', $exception->getCode());
$content->assign('file', $exception->getFile());
$content->assign('line', $exception->getLine());
$content->assign('trace', $exception->getTraceAsString());
$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
$content->assign('remoteAddr', $request->getRemoteAddress());
$content->assign('requestID', $request->getId());
return $content->fetchPage();
}

/*
/**
* @codeCoverageIgnore
*/
public function sendResponse() {
$this->server->sapi->sendResponse($this->server->httpResponse);
exit();
}
}
14 changes: 0 additions & 14 deletions apps/dav/templates/exception.php
Expand Up @@ -6,25 +6,11 @@
?>
<span class="error error-wide">
<h2><strong><?php p($_['title']) ?></strong></h2>
<p><?php p($_['message']) ?></p>
<br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about wrapping this in $_['debugMode'] like the trace below ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really worth from my pov - dav exceptions should not really hit the browser and are logged in the server log anyhow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then in that case we can also remove the "Trace" block, because that one doesn't make much sense without the message either

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed - see dda2132


<h2><strong><?php p($l->t('Technical details')) ?></strong></h2>
<ul>
<li><?php p($l->t('Remote Address: %s', $_['remoteAddr'])) ?></li>
<li><?php p($l->t('Request ID: %s', $_['requestID'])) ?></li>
<?php if($_['debugMode']): ?>
<li><?php p($l->t('Type: %s', $_['errorClass'])) ?></li>
<li><?php p($l->t('Code: %s', $_['errorCode'])) ?></li>
<li><?php p($l->t('Message: %s', $_['errorMsg'])) ?></li>
<li><?php p($l->t('File: %s', $_['file'])) ?></li>
<li><?php p($l->t('Line: %s', $_['line'])) ?></li>
<?php endif; ?>
</ul>

<?php if($_['debugMode']): ?>
<br />
<h2><strong><?php p($l->t('Trace')) ?></strong></h2>
<pre><?php p($_['trace']) ?></pre>
<?php endif; ?>
</span>