~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/digibug/DigibugPrintPhotos.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-12-24 05:36:33 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071224053633-1ha6lnfqkfvpgdia
Tags: 2.2.4-1
* New upstream release (Urgency high due to security fixes.
  Closes: #457644)
* debian/control: 
  + Update Standards-Version (No changes needed)
  + Add Homepage field, remove Homepage from Description
* debian/rules: No longer set DH_COMPAT (use debian/compat instead)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * @package Digibug
24
24
 * @subpackage UserInterface
25
25
 * @author Alan Harder <alan.harder@sun.com>
26
 
 * @version $Revision: 16471 $
 
26
 * @version $Revision: 17265 $
27
27
 */
28
28
class DigibugPrintPhotosView extends GalleryView {
29
29
 
59
59
        if (empty($cartItemIds) || empty($returnUrl)) {
60
60
            return GalleryCoreApi::error(ERROR_BAD_PARAMETER);
61
61
        }
 
62
        $ret = $this->assertIsInternalUrl($returnUrl);
 
63
        if ($ret) {
 
64
            return $ret;
 
65
        }
62
66
 
63
67
        /* Load the necessary item data */
64
68
        $itemIds = array_keys($cartItemIds);
113
117
                return $ret;
114
118
            }
115
119
 
116
 
            if (!isset($permissions['digibug.print'])) {
117
 
                /* Skip any cart items for which we don't have print permission */
 
120
            if (!isset($permissions['digibug.print']) || !isset($permissions['core.view'])) {
 
121
                /* Skip any cart items for which we don't have permission */
118
122
                continue;
119
123
            }
120
124
 
213
217
 
214
218
        return null;
215
219
    }
 
220
 
 
221
    /**
 
222
     * Assert that the given URL is internal to the application
 
223
     * @param string $url URL to check
 
224
     * @return GalleryStatus a status code
 
225
     * @deprecated This is a copy of GalleryUrlGenerator::assertIsInternalUrl from core API 7.43.
 
226
     */
 
227
    function assertIsInternalUrl($url) {
 
228
        global $gallery;
 
229
        $urlGenerator =& $gallery->getUrlGenerator();
 
230
 
 
231
        if (!empty($url)) {
 
232
            /* Detect header injection attempts */
 
233
            if (!GalleryUtilities::isSafeHttpHeader($url)) {
 
234
                $message = sprintf('Invalid URL! The requested URL %s contains malicious '
 
235
                                 . 'characters.',
 
236
                                   $urlGenerator->makeUrl($urlGenerator->getCurrentRequestUri()));
 
237
                return GalleryCoreApi::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__, $message);
 
238
            }
 
239
 
 
240
            /*
 
241
             * Check for phishing attacks, don't allow return URLs to other sites or to other paths.
 
242
             * Therefore first get the validPath, e.g. '/gallery2/' Do not allow ../ to break out of
 
243
             * the path Allow all URLs that don't start with a protocol and neither with '/', eg.
 
244
             * v/albumname but also www.EVIL.com is fine, since it's interpreted as a relative URL
 
245
             */
 
246
            $validPath = '/'
 
247
                . str_replace($urlGenerator->makeUrl(''), '', $urlGenerator->getCurrentUrlDir());
 
248
            /*
 
249
             * We check for ../ and /../ patterns and on windows \../ would also break out,
 
250
             * normalize to URL / *nix style paths to check fewer cases
 
251
             */
 
252
            $normUrl = str_replace("\\", '/', $url);
 
253
            if (((empty($urlGenerator->_file[0]) || strpos($url, $urlGenerator->_file[0]) !== 0)
 
254
                        && strpos($normUrl, $validPath) !== 0
 
255
                        && strpos($url, $urlGenerator->getCurrentUrlDir()) !== 0
 
256
                        && !( !preg_match('{^\s*\w*://}i', $normUrl)
 
257
                            && preg_match('{^\s*[^/\s]}i', $normUrl)))
 
258
                    || preg_match('{^\s*\.\./}', $normUrl)
 
259
                    || strpos($normUrl, '/../') !== false) {
 
260
                $message = sprintf('Invalid URL! The requested URL %s tried to insert a '
 
261
                                 . 'redirection to %s which is not a part of this Gallery.',
 
262
                                   $urlGenerator->makeUrl($urlGenerator->getCurrentRequestUri()),
 
263
                                   $url);
 
264
                return GalleryCoreApi::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__, $message);
 
265
            }
 
266
        }
 
267
        return null;
 
268
    }
216
269
}
217
270
?>