alphadevx /
alpha
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Alpha\Controller; |
||
| 4 | |||
| 5 | use Alpha\Util\Logging\Logger; |
||
| 6 | use Alpha\Util\Config\ConfigProvider; |
||
| 7 | use Alpha\Util\Security\SecurityUtils; |
||
| 8 | use Alpha\Util\Http\Request; |
||
| 9 | use Alpha\Util\Http\Response; |
||
| 10 | use Alpha\View\View; |
||
| 11 | use Alpha\View\Widget\SmallTextBox; |
||
| 12 | use Alpha\View\Widget\Button; |
||
| 13 | use Alpha\Controller\Front\FrontController; |
||
| 14 | use Alpha\Model\Type\SmallText; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Controller used to generate secure URLs from the query strings provided. |
||
| 18 | * |
||
| 19 | * @since 1.0 |
||
| 20 | * |
||
| 21 | * @author John Collins <[email protected]> |
||
| 22 | * @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
||
| 23 | * @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
||
| 24 | * All rights reserved. |
||
| 25 | * |
||
| 26 | * <pre> |
||
| 27 | * Redistribution and use in source and binary forms, with or |
||
| 28 | * without modification, are permitted provided that the |
||
| 29 | * following conditions are met: |
||
| 30 | * |
||
| 31 | * * Redistributions of source code must retain the above |
||
| 32 | * copyright notice, this list of conditions and the |
||
| 33 | * following disclaimer. |
||
| 34 | * * Redistributions in binary form must reproduce the above |
||
| 35 | * copyright notice, this list of conditions and the |
||
| 36 | * following disclaimer in the documentation and/or other |
||
| 37 | * materials provided with the distribution. |
||
| 38 | * * Neither the name of the Alpha Framework nor the names |
||
| 39 | * of its contributors may be used to endorse or promote |
||
| 40 | * products derived from this software without specific |
||
| 41 | * prior written permission. |
||
| 42 | * |
||
| 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||
| 44 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||
| 45 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||
| 46 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
| 47 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
||
| 48 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
| 49 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 50 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
| 51 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||
| 52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
| 53 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
||
| 54 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
| 55 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 56 | * </pre> |
||
| 57 | */ |
||
| 58 | class GenSecureQueryStringController extends Controller implements ControllerInterface |
||
| 59 | { |
||
| 60 | /** |
||
| 61 | * Trace logger. |
||
| 62 | * |
||
| 63 | * @var \Alpha\Util\Logging\Logger |
||
| 64 | * |
||
| 65 | * @since 1.0 |
||
| 66 | */ |
||
| 67 | private static $logger = null; |
||
|
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
| 68 | |||
| 69 | /** |
||
| 70 | * Constructor. |
||
| 71 | * |
||
| 72 | * @since 1.0 |
||
| 73 | */ |
||
| 74 | public function __construct() |
||
| 75 | { |
||
| 76 | self::$logger = new Logger('GenSecureQueryStringController'); |
||
| 77 | self::$logger->debug('>>__construct()'); |
||
| 78 | |||
| 79 | // ensure that the super class constructor is called, indicating the rights group |
||
| 80 | parent::__construct('Admin'); |
||
| 81 | |||
| 82 | $this->setTitle('Generate Secure Query Strings'); |
||
| 83 | |||
| 84 | self::$logger->debug('<<__construct'); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Handle GET requests. |
||
| 89 | * |
||
| 90 | * @param \Alpha\Util\Http\Request $request |
||
| 91 | * |
||
| 92 | * @return \Alpha\Util\Http\Response |
||
| 93 | * |
||
| 94 | * @since 1.0 |
||
| 95 | */ |
||
| 96 | public function doGET($request) |
||
| 97 | { |
||
| 98 | self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
||
| 99 | |||
| 100 | $body = View::displayPageHead($this); |
||
| 101 | |||
| 102 | $body .= $this->renderForm(); |
||
| 103 | |||
| 104 | $body .= View::displayPageFoot($this); |
||
| 105 | |||
| 106 | self::$logger->debug('<<doGET'); |
||
| 107 | |||
| 108 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Handle POST requests. |
||
| 113 | * |
||
| 114 | * @param \Alpha\Util\Http\Request $request |
||
| 115 | * |
||
| 116 | * @return \Alpha\Util\Http\Response |
||
| 117 | * |
||
| 118 | * @since 1.0 |
||
| 119 | */ |
||
| 120 | public function doPOST($request) |
||
| 121 | { |
||
| 122 | self::$logger->debug('>>doPOST($request=['.var_export($request, true).'])'); |
||
| 123 | |||
| 124 | $params = $request->getParams(); |
||
| 125 | |||
| 126 | $body = View::displayPageHead($this); |
||
| 127 | |||
| 128 | $body .= '<p class="alert alert-success">'; |
||
| 129 | if (isset($params['QS'])) { |
||
| 130 | $body .= FrontController::generateSecureURL($params['QS']); |
||
| 131 | self::$logger->action('Generated the secure URL in admin: '.FrontController::generateSecureURL($params['QS'])); |
||
| 132 | } |
||
| 133 | $body .= '</p>'; |
||
| 134 | |||
| 135 | $body .= $this->renderForm(); |
||
| 136 | |||
| 137 | $body .= View::displayPageFoot($this); |
||
| 138 | |||
| 139 | self::$logger->debug('<<doPOST'); |
||
| 140 | |||
| 141 | return new Response(200, $body, array('Content-Type' => 'text/html')); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Renders the HTML form for generating secure URLs. |
||
| 146 | * |
||
| 147 | * @return string |
||
| 148 | * |
||
| 149 | * @since 1.0 |
||
| 150 | */ |
||
| 151 | private function renderForm() |
||
| 152 | { |
||
| 153 | $config = ConfigProvider::getInstance(); |
||
| 154 | |||
| 155 | $html = '<p>Use this form to generate secure (encrypted) URLs which make use of the Front Controller. Always be sure to specify an action controller'. |
||
| 156 | ' (act) at a minimum.</p>'; |
||
| 157 | $html .= '<p>Example 1: to generate a secure URL for viewing article object 00000000001, enter <em>act=Alpha\Controller\ArticleController&ActiveRecordID=00000000001</em></p>'; |
||
| 158 | $html .= '<p>Example 2: to generate a secure URL for viewing an Atom news feed of the articles, enter'. |
||
| 159 | ' <em>act=Alpha\Controller\FeedController&ActiveRecordType=Alpha\Model\Article&type=Atom</em></p>'; |
||
| 160 | |||
| 161 | $html .= '<form action="'.$this->request->getURI().'" method="post" accept-charset="UTF-8"><div class="form-group">'; |
||
| 162 | $string = new SmallTextBox(new SmallText(''), 'Parameters', 'QS'); |
||
| 163 | $html .= $string->render(); |
||
| 164 | $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut'); |
||
| 165 | $temp = new Button('submit', 'Generate', $fieldname); |
||
| 166 | $html .= $temp->render(); |
||
| 167 | $html .= '</div></form>'; |
||
| 168 | |||
| 169 | return $html; |
||
| 170 | } |
||
| 171 | } |
||
| 172 |