Skip to content

Commit

Permalink
Fix “You are not authorised to view this” when mod_expires enabled (#…
Browse files Browse the repository at this point in the history
…13516)

* Fix “You are not authorised to view this” when mod_expires enabled

Closes #8731 Dec 18, 2015
Closes #8757 Dec 21, 2015
Closes #9013 Jan 28, 2016
Closes #9145 Feb 17, 2016
Closes #9615 Mar 26, 2016
Closes #10753 Jun 7, 2016

* code style

* Unit test refactoring (cannot do it the old way as relative dynamic dates in headers)

* Remove duplicate header output for charset

* Better Unit Tests

* More unit tests :)

* Close after setting headers

* Do not cache the response to this, its a redirect
  • Loading branch information
Phil Taylor authored and rdeutz committed Jan 10, 2017
1 parent 87e9b4d commit a6316f0
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class LanguagesControllerOverride extends JControllerForm
*/
public function edit($key = null, $urlVar = null)
{
// Do not cache the response to this, its a redirect
JFactory::getApplication()->allowCache(false);

$app = JFactory::getApplication();
$cid = $this->input->post->get('cid', array(), 'array');
$context = "$this->option.edit.$this->context";
Expand Down
6 changes: 4 additions & 2 deletions libraries/joomla/application/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,13 @@ public function redirect($url, $status = 303)
// All other cases use the more efficient HTTP header for redirection.
$this->header($this->responseMap[$status]);
$this->header('Location: ' . $url);
$this->header('Content-Type: text/html; charset=' . $this->charSet);
}
}

// Close the application after the redirect.
// Set appropriate headers
$this->respond();

// Close the application after the redirect.
$this->close();
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/legacy/controller/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ public function cancel($key = null)
*/
public function edit($key = null, $urlVar = null)
{
// Do not cache the response to this, its a redirect, and mod_expires and google chrome browser bugs cache it forever!
JFactory::getApplication()->allowCache(false);

$model = $this->getModel();
$table = $model->getTable();
$cid = $this->input->post->get('cid', array(), 'array');
Expand Down
128 changes: 104 additions & 24 deletions tests/unit/suites/libraries/cms/application/JApplicationCmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,32 @@ public function testRedirect()
$this->class->redirect($url, false);

$this->assertEquals(
array(
array('HTTP/1.1 303 See other', true, null),
array('Location: ' . $base . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 303 See other', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $base . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down Expand Up @@ -481,12 +501,32 @@ public function testRedirectLegacy()
);

$this->assertEquals(
array(
array('HTTP/1.1 303 See other', true, null),
array('Location: ' . $base . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 303 See other', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $base . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down Expand Up @@ -526,12 +566,32 @@ public function testRedirectLegacyWithEmptyMessageAndEmptyStatus()

// The redirect gives a 303 error code
$this->assertEquals(
array(
array('HTTP/1.1 303 See other', true, null),
array('Location: ' . $base . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 303 See other', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $base . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down Expand Up @@ -621,12 +681,32 @@ public function testRedirectWithMoved()
$this->class->redirect($url, true);

$this->assertEquals(
array(
array('HTTP/1.1 301 Moved Permanently', true, null),
array('Location: ' . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 301 Moved Permanently', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,32 @@ public function testRedirect()
$this->class->redirect($url, false);

$this->assertEquals(
array(
array('HTTP/1.1 303 See other', true, null),
array('Location: ' . $base . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 303 See other', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $base . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down Expand Up @@ -1178,12 +1198,32 @@ public function testRedirectWithMoved()
$this->class->redirect($url, true);

$this->assertEquals(
array(
array('HTTP/1.1 301 Moved Permanently', true, null),
array('Location: ' . $url, true, null),
array('Content-Type: text/html; charset=utf-8', true, null),
),
$this->class->headers
array('HTTP/1.1 301 Moved Permanently', true, null),
$this->class->headers[0]
);

$this->assertEquals(
array('Location: ' . $url, true, null),
$this->class->headers[1]
);

$this->assertEquals(
array('Content-Type: text/html; charset=utf-8', true, null),
$this->class->headers[2]
);

$this->assertRegexp('/Expires/',$this->class->headers[3][0]);

$this->assertRegexp('/Last-Modified/',$this->class->headers[4][0]);

$this->assertEquals(
array('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true, null),
$this->class->headers[5]
);

$this->assertEquals(
array('Pragma: no-cache', true, null),
$this->class->headers[6]
);
}

Expand Down

0 comments on commit a6316f0

Please sign in to comment.