[RFE] s9y core: Do not leak titles of non-public posts

Discussion corner for Developers of Serendipity.
Post Reply
Anthem
Regular
Posts: 20
Joined: Wed Aug 03, 2005 10:28 pm

[RFE] s9y core: Do not leak titles of non-public posts

Post by Anthem »

When blog entries are marked private or members only (for example with the "Hide/delete entries for non-registered users after a specific timespan"-plugin) the entry body will be hidden or replaced with a 'No entries to print'-message. However the s9y core (currently v1.3.1) will happily leak the title of a non-public entry if one visits its permalink.

In index.php the html-title is set for existing entries, for non-existing entries a 404-header gets generated. However this does not seem to be the right place to check for the public/private setting on entries.

In /include/genpage.inc.php after

Code: Select all

    switch ($serendipity['GET']['action']) {
        // User wants to read the diary
        case 'read':
            if (isset($serendipity['GET']['id'])) {
                $entry = array(serendipity_fetchEntry('id', $serendipity['GET']['id']));
                if (!is_array($entry) || count($entry) < 1) {
                    unset($serendipity['GET']['id']);
                    $entry = array(array());
                }
the following code can be inserted to stop titles from leaking, and generate a 404-header instead:

Code: Select all

else if (!is_array($entry[0])) {
  $serendipity['head_title'] = htmlspecialchars($serendipity['blogTitle']);
  $serendipity['head_subtitle'] = '';
  $serendipity['smarty']->assign('head_title', $serendipity['head_title']);
  $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']);
  header('HTTP/1.0 404 Not found');
}
Note: This code has only been tested in my current setup.
genpage.inc.php may also not be the best place to do this. The _fetchentry-function in /include/functions_entries.inc.php may be a better place, but setting the 404-header there seems a bit unclean.
2b || !2b
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Doesn't the 'genpage' hook get called? Could we use it to set the header, or to return a generic 'Members Only' page?
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Thanks a lot, I believe this fix to do well. I've just committed it to SVN:

http://svn.berlios.de/viewcvs/serendipi ... 20&r2=2302

I went a slightly different IF-check that seems to do well in my installation, can you verify that?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Anthem
Regular
Posts: 20
Joined: Wed Aug 03, 2005 10:28 pm

Post by Anthem »

Hi Garvin,

that does not work for me. For non-public entries $entry has the structure

Code: Select all

Array
(
    [0] => 
)
and thus the if-block is not entered.
2b || !2b
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Hm, strange, I somehow got a different empty result. I just committed another update with the empty array check.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Anthem
Regular
Posts: 20
Joined: Wed Aug 03, 2005 10:28 pm

Post by Anthem »

Of course I'm on 1.3.1, and you're probably on the current source. Maybe the fetchentry function changed in the meantime?
2b || !2b
Post Reply