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

When loading URL and not logged in, this should load the login form #7201

Merged
merged 1 commit into from Feb 20, 2015

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Feb 13, 2015

refs #7193

I don't think the issue is a regression. At least it doesn't look like it. This is one solution for that fix but not 100% correct. It would trigger the exception as well if an idSite is given for a site that does not exist! Will try to find a better solution.

@tsteur
Copy link
Member Author

tsteur commented Feb 13, 2015

I couldn't find a good way for showing different error if site does not exist compared to not having permission and it also would be information disclosure. It would be easy to find out how many sites are tracked with a Piwik etc.

The only way to solve it would be to check whether a given site exists using the SitesManager\Model as this one does not check for view permission. Problem is that the current code is in core and does not know anything about that plugin so we'd have to trigger an event for this check which is not so nice. Also I think it is good not to disclose any information here. Also the error (site does not exist) should not happen unless users manipulate the URL manually.

@tsteur tsteur added the Needs Review PRs that need a code review label Feb 13, 2015
@diosmosis
Copy link
Member

The issue is due to period = range. A specific method needs to execute new Site(...) regardless of period value. I have hacky fix locally, will post the diff here soon.

@diosmosis
Copy link
Member

diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php
index 7fdfe1d..cbd8a06 100644
--- a/plugins/CoreHome/Controller.php
+++ b/plugins/CoreHome/Controller.php
@@ -156,6 +156,10 @@ class Controller extends \Piwik\Plugin\Controller

     protected function setDateTodayIfWebsiteCreatedToday()
     {
+        $websiteId = Common::getRequestVar('idSite', false, 'int');
+        $website = $websiteId === false ? null : new Site($websiteId); // make sure internal access check is indirectly performed so URLs w/o access
+                                                                       // will be redirected to Login
+
         $date = Common::getRequestVar('date', false);
         if ($date == 'today'
             || Common::getRequestVar('period', false) == 'range'
@@ -163,11 +167,7 @@ class Controller extends \Piwik\Plugin\Controller
             return;
         }

-        $websiteId = Common::getRequestVar('idSite', false, 'int');
-
-        if ($websiteId) {
-
-            $website = new Site($websiteId);
+        if (!empty($website)) {
             $datetimeCreationDate      = $website->getCreationDate()->getDatetime();
             $creationDateLocalTimezone = Date::factory($datetimeCreationDate, $website->getTimezone())->toString('Y-m-d');
             $todayLocalTimezone        = Date::factory('now', $website->getTimezone())->toString('Y-m-d');

This will provide the correct behaviour, but it doesn't solve the underlying problem (that idSite should be handled ONE way in ONE place). Unfortunately, I don't think a proper solution is feasible at the moment.

@tsteur
Copy link
Member Author

tsteur commented Feb 15, 2015

I didn't find that check and had no idea it exists. As you mentioned in your comment it is "indirectly performed". Don't like it so much, this will most likely fail again. Even if we had tests for it, it will be hard to find (it was in this case like this as well as it failed somewhere else in checkSitePermission which is more explicit). Why don't we add a check to FrontController to make it explicit? Meaning if idSite param is given and not empty we would check for the site permission.

@diosmosis
Copy link
Member

If it doesn't break anything I guess it's fine. Just need to make sure for controller actions it redirects to login instead of throwing an exception.

@mattab mattab added this to the Piwik 2.12.0 milestone Feb 16, 2015
@mattab
Copy link
Member

mattab commented Feb 16, 2015

Moved to 2.12.0 unless someone wants to merge it for 2.11.0!

@tsteur
Copy link
Member Author

tsteur commented Feb 17, 2015

Worked on the FrontController idea. Solving it in FrontController.dispatch results in an endless loop as it will fail eg for CoreHome.index, then post an event userNotAuthorized which will try to dispatch eg Login.index which will fail again etc. Of course it would be doable to avoid the endless loop but the FrontController is actually not really responsible for this kinda things. Neither in the init() method of the FrontController. Was not a good idea of mine. I think it actually belongs where it is currently (Controller::checkSitePermission). The method name checkSitePermission is pretty explicit / clear and it will be only executed if needed and it kinda belongs to the Controller. So would personally not do any change but if someone wants to fix it differently go for it

@mattab mattab modified the milestones: Piwik 2.11.1, Piwik 2.12.0 Feb 19, 2015
mattab pushed a commit that referenced this pull request Feb 20, 2015
When loading URL and not logged in, this should load the login form
@mattab mattab merged commit 592f664 into master Feb 20, 2015
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Feb 20, 2015
@tsteur tsteur deleted the 7193 branch March 8, 2015 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants