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

Admin Toolbar cached when Logged-In Users caching enabled #497

Closed
raamdev opened this issue Jun 11, 2015 · 27 comments
Closed

Admin Toolbar cached when Logged-In Users caching enabled #497

raamdev opened this issue Jun 11, 2015 · 27 comments
Assignees
Milestone

Comments

@raamdev
Copy link
Contributor

@raamdev raamdev commented Jun 11, 2015

Steps to reproduce this bug

  1. Enable Logged-In User caching and set it to "Yes, but DON'T maintain a separate cache"
  2. In Dashboard → Users → My Profile ensure that Show Toolbar when viewing site is Enabled
  3. Visit the site as an administrator to generate a cache file for a page
  4. Logout and visit that same page, now as a user who is not logged in

Expected Behavior

The cached page should be loaded, but without any Admin Toolbar at the top. Since the visitor visiting the page is not logged in, seeing an Admin Toolbar is unexpected.

Observed Behavior

The cached page includes the Admin Toolbar and so the logged-out visitor sees a version of that page that includes that toolbar (attempting to use anything on the toolbar obviously redirects to the login page, but that toolbar really shouldn't be there in the first place).


Potential Fixes

  • When generating a cache file for a page, we could detect when Logged-In User caching is set to "Yes, but DON'T maintain a separate cache" and when the current user has Show Toolbar when viewing site enabled, and then delete the <div> inside the cached HTML that contains id="wpadminbar" before generating the cache file, so that the resulting cache file does not contain that div at all.
  • The other option would be to force-disable the Admin Toolbar when visiting the front-end of the site when Logged-In User caching is set to "Yes, but DON'T maintain a separate cache", with a message inside the Logged-In Users Option Panel that explains why the Admin Toolbar will be disabled. We could then provide a filter to override that behavior in case an advanced site owner wants to disable that functionality and show the Admin Toolbar anyway.

Support threads referencing this issue

@raamdev raamdev added bug pro labels Jun 11, 2015
@raamdev raamdev added this to the Future Release milestone Jun 11, 2015
@jaswrks
Copy link

@jaswrks jaswrks commented Jun 12, 2015

The other option would be to force-disable the Admin Toolbar

Of those two choices, I would vote for this one. Or, I would also vote to get rid of that option altogether; only because this particular feature has the potential to create a security issue if not configured properly. The Admin Bar showing is one mild example of this, but suppose the site owner was running some plugin that displayed blog stats or DB details in some way. If something like that got cached, and the site owner doesn't realize the impact of the ZenCache configuration, it creates a security issue.

This was my doing; i.e., I put that option in there to improve flexibility, but the case you mentioned here is a good reason for us not to have that in my view. I imagine it is used rarely anyway.

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Jun 12, 2015

I would also vote to get rid of that option altogether;

I agree with that. Maybe we can get rid of that option, but make enabling such an option possible through the use of an MU-Plugin, so that if an advanced site owner wants that functionality and knows what they're doing, they can still enable it.

@raamdev raamdev modified the milestones: Next Release (Pro), Future Release Jul 10, 2015
@raamdev raamdev modified the milestones: Next Release (Pro), Next Release (Lite), Future Release (Pro) Jul 27, 2015
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Jul 27, 2015

Just thinking about what removing the "Logged-In User Caching" feature might entail and what kinds of scenarios we'd need to consider:

  • Existing users who have this option enabled and who are actively using it on their site (maybe they even purchased the Pro version specifically for this feature).

    For these users we'll want to keep showing the UI option--removing it and forcing them to enable this via an MU Plugin wouldn't be very good UX. Of course if they disable this option after having been using it, it shouldn't just disappear on them. There should be a flag that, if they had this feature enabled, this feature stays visible to them. (If we want to eventually hide this UI option from even these users, then we'll need to come up with a plan that announces it to them through a Dashboard message, along with instructions for how to continue using it, e.g., via an MU Plugin. I personally don't feel this is necessary.)

  • Existing users who don't have this option enabled.

    We could simply hide the UI menu altogether, so that this option suddenly disappears. (Since this option is potentially dangerous, especially to novice site owners, we shouldn't be presenting it as an option that can simply be enabled.) Then, whenever we get a query asking us what happened to this option, we can link them to a KB Article that explains why we removed it from the UI and demonstrates how to reactivate this feature using an MU Plugin.

  • New users.

    As with existing users who didn't have this option enabled, this feature would simply be hidden from the UI and it would only be possible to enable it via an MU Plugin, after a site owner has had the opportunity to read through a KB Article that explains the dangers of enabling Logged-In User Caching.

@jaswrks
Copy link

@jaswrks jaswrks commented Aug 21, 2015

Next Actions

Covering the Use Cases Listed Above

1. Existing users who have this option enabled

  • See this line of code in the MenuPageOptions class.
    Wrap this line with the following conditional check:

    if ($this->plugin->options['when_logged_in'] === '1') { // i.e., not already set to this option.
        echo '            <option value="1"'.selected($this->plugin->options['when_logged_in'], '1', false).'>'.__('Yes, but DON\'T maintain a separate cache for each user (I know what I\'m doing).', SLUG_TD).'</option>'."\n";
    }
  • Now take it a step further and flag an option that shows this was enabled at some point.

    if ($this->plugin->options['when_logged_in'] === '1' || get_site_option(GLOBAL_NS.'_when_logged_in_was_1')) {
        update_site_option(GLOBAL_NS.'_when_logged_in_was_1', '1');
        echo '            <option value="1"'.selected($this->plugin->options['when_logged_in'], '1', false).'>'.__('Yes, but DON\'T maintain a separate cache for each user (I know what I\'m doing).', SLUG_TD).'</option>'."\n";
    }

2. Existing users who don't have this option enabled.

Already covered by the above suggested changes in point 1.

3. New users.

Already covered by the above suggested changes in point 1.


Disable Admin Bar if when_logged_in is Set to 1

  • After this line of code in the Plugin class, add the following.

    /*[pro strip-from="lite"]*/
    if ($this->options['when_logged_in'] === '1' && $this->applyWpFilters(GLOBAL_NS.'_when_logged_in_no_admin_bar', true)) {
        show_admin_bar(FALSE); // Prevent admin bar from being cached.
    }
    /*[/pro]*/
  • Now go back and add a note in the Logged-In Users config. panel to mention this being the case.


Create MU plugin to enable this feature in future versions of ZenCache whenever it is requested by site owners through our support center; if that happens.

  • Referencing this line of code where a filter is exposed.

    <?php
    add_filter('zencache_options', function(array $options){
        $options['when_logged_in'] = '1';
        return $options;
    });
@raamdev raamdev self-assigned this Aug 21, 2015
@raamdev raamdev modified the milestones: Next Release (Pro), Future Release (Pro) Sep 17, 2015
@jaswrks
Copy link

@jaswrks jaswrks commented Sep 22, 2015

@raamdev Would you mind if @renzms works on this?

@jaswrks
Copy link

@jaswrks jaswrks commented Sep 22, 2015

Next Actions for this Issue

Create a new feature branch feature/497 in websharks/zencache-pro and begin work as follows.

Covering the Use Cases Listed Above

1. Existing users who have this option enabled

  • See this line of code in the MenuPageOptions class.
    Wrap this line with the following conditional check:

    if ($this->plugin->options['when_logged_in'] === '1') { // i.e., not already set to this option.
        echo '            <option value="1"'.selected($this->plugin->options['when_logged_in'], '1', false).'>'.__('Yes, but DON\'T maintain a separate cache for each user (I know what I\'m doing).', SLUG_TD).'</option>'."\n";
    }
  • Now take it a step further and flag an option that shows this was enabled at some point.

    if ($this->plugin->options['when_logged_in'] === '1' || get_site_option(GLOBAL_NS.'_when_logged_in_was_1')) {
        update_site_option(GLOBAL_NS.'_when_logged_in_was_1', '1');
        echo '            <option value="1"'.selected($this->plugin->options['when_logged_in'], '1', false).'>'.__('Yes, but DON\'T maintain a separate cache for each user (I know what I\'m doing).', SLUG_TD).'</option>'."\n";
    }

2. Existing users who don't have this option enabled.

Already covered by the above suggested changes in point 1.

3. New users.

Already covered by the above suggested changes in point 1.


Disable Admin Bar if when_logged_in is Set to 1

  • After this line of code in the Plugin class, add the following.

    /*[pro strip-from="lite"]*/
    if ($this->options['when_logged_in'] === '1' && $this->applyWpFilters(GLOBAL_NS.'_when_logged_in_no_admin_bar', true)) {
        show_admin_bar(FALSE); // Prevent admin bar from being cached.
    }
    /*[/pro]*/
  • Now go back and add a note in the Logged-In Users config. panel to mention this being the case.

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Sep 22, 2015

Would you mind if @renzms works on this?

@jaswsinc Sounds great to me! :-)

@raamdev raamdev assigned renzms and unassigned raamdev Sep 22, 2015
@jaswrks
Copy link

@jaswrks jaswrks commented Sep 22, 2015

@renzms Here's a visual of what you're tweaking (i.e., hiding) as part of your work on this issue.

2015-09-22_12-00-19

@renzms
Copy link

@renzms renzms commented Sep 25, 2015

zencache497

Hi @jaswsinc , uploaded to my test site. Tested and confirmed the option is now hidden.

As for this step:

Now go back and add a note in the Logged-In Users config. panel to mention this being the case.

What should I mention in the notice?

@jaswrks
Copy link

@jaswrks jaswrks commented Sep 26, 2015

Cool.

Now go back and add a note in the Logged-In Users config. panel to mention this being the case.
What should I mention in the notice?

In the instructions above, there is a section titled, "Disable Admin Bar if when_logged_in is Set to 1". So whenever you implement that code that calls upon show_admin_bar(false);, you are hiding the Admin Bar.

What we need is a note in the config. panel whenever when_logged_in = 1. In that scenario, we should explain that the Admin Bar is not going to be shown on the front-end of the site. Otherwise, they won't understand why the Admin Bar suddenly disappeared from their site.

e.g., <p class="warning"> ... </p>

@jaswrks
Copy link

@jaswrks jaswrks commented Sep 26, 2015

Note that while you are hiding the when_logged_in = 1 option by default, it is still possible to enable this; e.g., if it was already enabled, or if you use an MU plugin. That's why we need a note in the config. panel.

@renzms
Copy link

@renzms renzms commented Sep 29, 2015

Hi @jaswsinc,

Can the note be the following?

Note for users who have set "Yes, but DON'T maintain a separate cache": If you had this feature previously enabled, please be aware that the Admin Bar will no longer be shown on the front-end of your website. The option for "Yes, but DON'T maintain a separate cache", is no longer accessible unless using an MU plugin.

@jaswrks
Copy link

@jaswrks jaswrks commented Sep 29, 2015

Something like this...

<?php if($this->plugin->options['when_logged_in'] === '1' && $this->plugin->applyWpFilters(GLOBAL_NS.'_when_logged_in_no_admin_bar', true)): ?>
    echo '<p class="warning">'.sprintf(__('<strong>Warning:</strong> Whenever you enable caching for logged-in users (without a separate cache for each user), the WordPress Admin Bar <em>must</em> be disabled to prevent one user from seeing another user\'s details in the Admin Bar. <strong>Given your current configuration, %1$s will automatically hide the WordPress Admin Bar on the front-end of your site.</strong>', SLUG_TD), esc_html(NAME)).'</p>';
<?php endif; ?>

Warning: Whenever you enable caching for logged-in users (without a separate cache for each user), the WordPress Admin Bar must be disabled to prevent one user from seeing another user's details in the Admin Bar. Given your current configuration, ZenCache will automatically hide the WordPress Admin Bar on the front-end of your site.

@renzms
Copy link

@renzms renzms commented Sep 30, 2015

@jaswsinc ,

Ok thanks, I'll add that in, also which file will I add this to? Plugin.php?

How will I test this though as I never set it as enabled before? I will have hidden the option from my 497 version. If I rollback to a previous version, enable that setting, then overwrite with my 497 version, won't it delete that in the database and not remember I enabled it before?

@jaswrks
Copy link

@jaswrks jaswrks commented Sep 30, 2015

Ok thanks, I'll add that in, also which file will I add this to? Plugin.php?

This should appear just underneath the dropdown menu that you worked on here.

How will I test this though as I never set it as enabled before?

In your working copy of ZenCache, create an MU plugin to enable this feature by force.

Create: /wp-content/mu-plugins/zc-hacks.php

  <?php
  add_filter('zencache_options', function(array $options){
      $options['when_logged_in'] = '1';
      return $options;
  });
@renzms
Copy link

@renzms renzms commented Oct 1, 2015

@jaswsinc Thanks! I will try that to test out the changes via MU plugin.

@raamdev raamdev modified the milestones: Next Release (Pro), Future Release (Pro) Oct 4, 2015
@renzms
Copy link

@renzms renzms commented Oct 5, 2015

@jaswsinc

Tested and successfully working, let me know if its ready for a push. Thanks!:

plugin options renz s test area wordpress 4

@jaswrks
Copy link

@jaswrks jaswrks commented Oct 6, 2015

Tested and successfully working, let me know if its ready for a push. Thanks!

Thank you. Yes, lookin' great in your screenshot!

I need to see a PR though. Don't worry about having everything just right before you open a PR. If you feel ready for a review, even if you're not sure that everything is just right, go ahead and open a PR so that I can review the diff and the changes that you made.

@renzms
Copy link

@renzms renzms commented Oct 6, 2015

@jaswsinc

I need to see a PR though. Don't worry about having everything just right before you open a PR. If you feel ready for a review, even if you're not sure that everything is just right, go ahead and open a PR so that I can review the diff and the changes that you made.

Noted! Will submit a PR now. Thanks!

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Oct 7, 2015

@jaswsinc Reviewing Renz's PR it appears that the intention here is to only remove the option to enable Logged-In User Caching without maintaining a separate cache, is that correct? Earlier in this GitHub issue (namely here: #497 (comment)) I was under the impression that we were removing the entire Logged-In User Caching feature altogether.

However, if that's not the case that's good, because my feeling is that this is a really popular feature (being able to cache logged-in users) and I'd rather not see it go. :-)

@jaswrks
Copy link

@jaswrks jaswrks commented Oct 7, 2015

only remove the option to enable Logged-In User Caching without maintaining a separate cache, is that correct?

That is correct :-) This particular setting has the potential to create a security problem, so removing it from the available options seems like a good idea to me. It can still be enabled with a filter though.

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Oct 7, 2015

@jaswsinc writes (in #497 (comment))...

I would also vote to get rid of that option altogether; only because this particular feature has the potential to create a security issue if not configured properly.

This was where I misunderstood you. Re-reading that now, I realize you were just referring to the Yes, but DON'T maintain a separate cache for each user option, not the entire Logged-In User Caching feature. :-) My mistake.

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Oct 7, 2015

@jaswsinc writes...

It can still be enabled with a filter though.

Has that been implemented yet? I didn't see that in the PR.

@jaswrks
Copy link

@jaswrks jaswrks commented Oct 7, 2015

No, it wasn't introduced as a part of this PR. However, you can accomplish this with a filter that we have for the options array.

<?php
add_filter('zencache_options', function(array $options){
    $options['when_logged_in'] = '1';
    return $options;
});
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Oct 7, 2015

you can accomplish this with a filter that we have for the options array.

Ah, right. I forgot about that. Very cool. :-)

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Oct 7, 2015

Next Pro Release Changelog:

  • Enhancement: In Logged-In User Caching, the "Yes, but DON'T maintain a separate cache for each user" option has been hidden because this particular option has the potential to create a security issue if not configured properly. If you were already using this option, it will not be hidden and it will continue to work. Otherwise, if you require this particular option you can now enable it using a filter (see this comment). Props @renzms @jaswsinc. See Issue #497.
@raamdev raamdev closed this Oct 7, 2015
@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Nov 14, 2015

ZenCache v151114 has been released and includes changes from this GitHub Issue. See the v151114 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#497).

@wpsharks wpsharks locked and limited conversation to collaborators Nov 14, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants