Blajax was inspired by "hide-this-block" module (http://drupal.org/project/hide_this_block) and the "Block Refresh" module (http://drupal.org/project/block_refresh) and still uses some fragments of their code and ideas. However it is not really a duplication but merges both approaches and, first of all, enhances them widely.

Additions are theming support, CSS integration and enhanced fallback options (if Javascript is not present). Also some design has happened, such as slide and fade effects and the use of icons (which can also be easily changed by theming).

Blajax adds these main features to your block system:

  • a fully themable toolbar for each block (which appears whenever a user has the appropriate permissions)
  • minimize/restore blocks per user
  • enable blocks to be refreshed manually and/or automatically.

Project page link (sandbox): http://drupal.org/node/1328878
Git link: git.drupal.org:sandbox/doitDave/1328878.git

This module is one out of many I designed for an individual project but with the goal to share it. It has been working for over one year now without issues in a productive environment so I decided it to be my first attempt here. Hopefully it is not totally out of scope I hope it will pass and some here would like it.

Up to now it is designed for D6.

Gracefully don't mind the 4 instead of 2 spaces indent; everything else has been checked with coder and already fixed. Edit: else/elseif style as well, I would prefer to keep it as is and assumed this not being a hard issue since I have seen it in various other "real" projects as well!? (fixed; see comments)

Comments

doitDave’s picture

Issue summary: View changes

*Edit: else/elseif style as well, I would prefer to keep it as is and assumed this not being a hard issue since I have seen it in various other "real" projects as well!?

raynimmo’s picture

Status: Needs review » Needs work

Coder with the settings as Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards found a few errors.

blajax.module

Line 105: else statements should begin on a new line
} else {

Line 137: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see blajax_action()

Line 237: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see _blajax_form_validate_block()

Line 238: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see _blajax_form_save_block()

Line 316: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$block_extra = _blajax_block_data($_POST['module'], $_POST['delta']);

Line 323: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$_POST['js']

Line 331: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$user->blajax_token[$_POST['module']][$_POST['delta']] >= time()-15

Line 349: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$_POST['module'],

Line 350: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$_POST['delta'],

Line 351: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$_POST['bid'],

Line 352: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
$_POST['scope']

Line 400: else statements should begin on a new line
} elseif ($blockExtra->title) {

Line 492: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see http://drupal.org/project/js

Line 579: else statements should begin on a new line
} else {

Line 598: else statements should begin on a new line
} else {

Line 923: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see block.module

Line 924: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see block_list()

Line 949: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see _blajax_form_validate_block()

Line 962: else statements should begin on a new line
} else {

Line 972: @see references should be separated by "," followed by a single space and with no trailing punctuation
* @see _blajax_form_save_block()

Line 985: else statements should begin on a new line
} elseif (

blajax.admin.inc

Line 164: in most cases, replace the string function with the drupal_ equivalent string functions
array('!linktype' => t(ucfirst($type)))

Line 170: in most cases, replace the string function with the drupal_ equivalent string functions
array("%linktype" => t(ucfirst($type)))

Line 177: in most cases, replace the string function with the drupal_ equivalent string functions
t(ucfirst($type))

With regards to your comments;

Gracefully don't mind the 4 instead of 2 spaces indent; everything else has been checked with coder and already fixed.*

*Edit: else/elseif style as well, I would prefer to keep it as is and assumed this not being a hard issue since I have seen it in various other "real" projects as well!?

I really dont think its down to you, everyone should adhere to the coding standards and unless you follow those rules then you may really struggle to get this module through to its final release.

doitDave’s picture

Status: Needs work » Needs review

Hi Ray,

thanks a lot for your comments and the fast response!

Regarding the "else" issue and the indents I can make up my mind (I wondered if I could miss this out and avoid re-configuring my dev tools, but you are right, that is no question of importance here). So I fixed this. Same for the "drupal_equivalent function" thing, which I honestly overread in the first euphoria ;)

But, I would appreciate closer advice/opinion on the "$_POST" issue since I checked http://drupal.org/node/178896 before the first commit where I found:

Bad code could take two forms:

  1. Using the $_POST variables directly and creating a form via HTML instead of the Drupal Form API
  2. Using a link and a menu callback to handle a action that modifies data (especially destructive modifications like deletion)

Well, none of both is happening here: They will never be used for displaying (or output at all) and neither would they for menu items. They are actually used for block retrieval with core functions or in sanitized db_queries. Thus, I cannot find a "potential problem" here. Or am I missing out on something?

Further background: Using form api would be very expensive on heavy loaded sites as the module can be configured to poll in short intervals; this is why I actually use direct $_POST data here. (Which of course should not decrease security, but unless it can, why sacrifice performance?)

I have checked for the rest and (hopefully) fixed that.

One final thing irritates me: I had set exactly the same options for coder as you did, but the @see messages simply do not show up here! Also, what do they mean? I have sticked (or at least tried to do so) exactly to what is displayed as example in http://drupal.org/node/1354#functions - is this possibly a coder module issue here? I am using 6.x-2.0-rc1.

Any further comment is highly appreciated :)

raynimmo’s picture

I am also using Coder 6.x-2.0-rc1, did you have the settings on 'minor (most)'?

I understand what you mean with regards to the $_POST data never actually being manipulated by an external source but I am sure you may struggle to get your module to a full release unless you patch those vulnerabilities.

I had a mess with your code locally and it is easily patched, but as you said it may be an extra overhead, how much of an overhead I am not really sure.

With regards to Line 316 where you have
$block_extra = _blajax_block_data($_POST['module'], $_POST['data']);
When this is changed to
$block_extra = _blajax_block_data(filter_xss($_POST['module']), filter_xss($_POST['data']));
Then Coder no longer flags that line as a CSRF vulnerability.

Similarily, if you were to use
$block_extra = _blajax_block_data(check_plain($_POST['module']), check_plain($_POST['data']));
That also satisfies the Coder modules checking algorithm.

It may be worth doing some research into whether check_plain() or filter_xss() actually has a noticeable effect on the processing overhead and possibly use the 'lighter' solution.

Maybe someone that is more knowledgable than me on this subject will chime in and answer your question a little more eloquently :)

doitDave’s picture

Hey,

did you have the settings on 'minor (most)'

Yes, I did; actually exactly the same settings that you have mentioned.

Here's what remains on my site after having fixed the rest:

sites/all/modules/blajax/blajax.module

blajax.module

  • Line 317: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)

    $block_extra = _blajax_block_data($_POST['module'], $_POST['delta']);
  • Line 324: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $_POST['js']
  • Line 332: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $user->blajax_token[$_POST['module']][$_POST['delta']] >= time()-15
  • Line 350: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $_POST['module'],
  • Line 351: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $_POST['delta'],
  • Line 352: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $_POST['bid'],
  • Line 353: Potential problem: use the Form API to prevent against CSRF attacks. If you need to use $_POST variables, ensure they are fully sanitized if displayed by using check_plain(), filter_xss() or similar. (Drupal Docs)
    $_POST['scope']

Thinking about the $_POST thing, the few function calls will probably not do too much harm to performance, as it is run in bootstrap.inc. If anyone has further thoughts on that, they are welcome. Especially in the context of integration with js.module (which in fact is performance relevant).

I will test both of your proposals meanwhile :-)

beanluc’s picture

Status: Needs review » Needs work

Since there remain some outstanding items, changing status.

doitDave’s picture

Status: Needs work » Needs review

Outstanding items? All except the $_POST issue has been fixed and as I do not see a security issue there I am waiting for a review that clarifies this point!?! As I already tried to point out: This module is really depending on as few overhead as possible since not every user can run his own i7 server with 4G RAM... of course both proposed options work fine in a test environment, but what on a heavy loaded page?

So, again my appeal that someone who can give a clear statement on this may judge whether this coder minor hint is a false positive here or not. Thanks :)

Thus, status re-reset.

beanluc’s picture

Have you traced all your $_POST variables all the way through? Do you know that at least one of them can eventually become part of the argument to an include_once() call, unsanitized?

I'm not saying that will happen, without either a mistake on your part or malicious intent on a site-administrator's part. But it could. I hope you can understand why I thought you might still be working on those items. I mean, I would.

I saw "I will test both of your proposals meanwhile" and I took that to mean you were working on it. I'm sorry.

It's also not at all clear that the seven bullet-points you listed are things which you don't intend to work on any further. I saw "here's what remains after having fixed the rest". Again, I'm sorry.

doitDave’s picture

Hey,

Have you traced all your $_POST variables all the way through?

Yes, I did, and at last after the coder warnings I would have ;) No, seriously, security cannot be taken care of too much, I agree absolutely on that!

Do you know that at least one of them can eventually become part of the argument to an include_once() call, unsanitized?

Is that given? If it is, please let me know in which context, but as far as I have traced the functions that actually are being used, I couldn't find anything.

I hope you can understand why I thought you might still be working on those items. I mean, I would.

In any other context I would not discuss about that but simply apply those few function calls. But imagine a site with, say, 50 users online and probably a dozen blocks refreshing every minute. I can tell from own experience how fast even a small standalone server can get to its limits. That's why I am trying to reduce overhead here unless security IS a real issue.

Not to be mistaken, if it is a hard rule to never use raw $_POST content and an absolute launch blocker, I would not insist. But if not...

I saw "I will test both of your proposals meanwhile" and I took that to mean you were working on it. I'm sorry.

Oh, okay, yes. That's probably a bit confusing, my fault! I really did test that, and both of course work. But - see above. But first of all my goal is to ensure it would not cause security problems as is.

It's also not at all clear that the seven bullet-points you listed are things which you don't intend to work on any further. I saw "here's what remains after having fixed the rest".

Okay, then I better clarify that, they are all related to the same issue (and will never ever be displayed to a user, but are only used to retrieve block data internally and there, where necessary, of course run through database sanitation procedures).

Again, I'm sorry.

No problem, after all I can't repeat it too often that I really respect and support any security concern and of course any suggestions :)

beanluc’s picture

argument to an include_once() call, unsanitized?

Is that given?

No. It would require either a function-naming mistake on your part, in which case the module wouldn't actually even work, or, malice on some site administrator's part - and those folks already have such power as to not need to exploit something this obscure.

they are all related to the same issue (and will never ever be displayed to a user

Being displayed to a user (or injected into a SQL query) aren't the only things to worry about, only the most obvious.

With that in mind, look closely at where module_invoke($module, 'block', 'view', $delta) sends $module and $delta (unsanitized from $_POST). If the proper function name is not found, module_hook() will search for include files based on the arbitrary string. It's true that if the function name isn't found, the module won't work, but this illustrates the risk, I think.

I haven't made the time to look at what happens with theme('block', $block); but, your $block object presents unsanitized $_POST stuff to theme(). That looks pretty scary, although I don't think the current implementation of theme() will actually do anything with your $block->module or $block->delta properties. Will that always be true?

OK. Neither of those points appear to me to be actual risks in your module, currently. They just illustrate the attention to detail necessary, if you're not going to sanitize. And why I thought you were still working on it.

doitDave’s picture

Appreciated comment, again!

Okay, for module_invoke: Assume an intruder would manipulate the request to url?foo=bar&module=whatever;DROP%20DATABASE&delta=4711..., what will happen:

A call would be made like

module_invoke("whatever;DROP DATABASE","block","view",4711);

Which would eval to

$function = "whatever;DROP DATABASE" . "_" . "block"

being

$function = "whatever;DROP DATABASE_block"

resulting in whatever;DROP DATABASE_block("view",4711)

which would end up in a PHP/Server error. Since this error would only show to the introder I would judge that he'd know "ok, no dealing here". ;)

Different opinions, other examples anyone?

doitDave’s picture

Issue summary: View changes

(Edit info mismatch)

doitDave’s picture

Issue summary: View changes

Updated due to changes

doitDave’s picture

OK, one more day thinking about security I think I found a satisfying and calming solution which uses as less CPU as possible. The raw $_POST array partly runs through a regex replace on PHP level and reduces the "module" parameter to the characters allowed for module names. Still I am not sure whethere there was a leak before but this way it feels as secure as possible.

By now there are also no more coder warnings left.

chakrapani’s picture

Status: Needs review » Needs work

Here you go

Review of the 6.x-1.x branch:

  • Run coder to check your style, some issues were found (please check the Drupal coding standards):
    Severity minor, Drupal Commenting Standards, Internationalization, Drupal Security Checks, Drupal SQL Standards, Drupal Coding Standards
    
    sites/all/modules/pareview_temp/test_candidate/blajax.module:
     +234: [minor] Comment should be read "Implements hook_foo()."
     +473: [minor] Comment should be read "Implements hook_foo()."
     +503: [minor] Comment should be read "Implements hook_foo()."
     +528: [minor] Comment should be read "Implements hook_foo()."
     +553: [minor] Comment should be read "Implements hook_foo()."
     +583: [minor] Comment should be read "Implements hook_foo()."
     +775: [minor] Comment should be read "Implements hook_foo()."
    
    Status Messages:
     Coder found 1 projects, 1 files, 7 minor warnings, 0 warnings were flagged to be ignored
    
  • Remove LICENSE.txt, it will be added by drupal.org packaging automatically.
  • Remove the translations folder, translations are done on http://localize.drupal.org
  • Comments should be on a separate line before the code line, see http://drupal.org/node/1354#inline
    ./blajax.install:14:} // end function blajax_install
    ./blajax.install:66:} // end function blajax_schema
    ./blajax.install:97:} // end function blajax_uninstall
    ./blajax.module:56:      break; // hide
    ./blajax.module:74:      break; // minimize
    ./blajax.module:91:      break; // maximize
    ./blajax.module:92:    } // switch ($action)
    ./blajax.module:116:} // End function blajax_action
    ./blajax.module:154:    break; // hide
    ./blajax.module:165:    break; // edit
    ./blajax.module:177:    break; // minimize
    ./blajax.module:189:    break; // maximize
    ./blajax.module:201:    break; // refresh
    ./blajax.module:202:  } // switch $type
    ./blajax.module:229:} // End function blajax_create_link
    ./blajax.module:302:} // End function blajax_form_block_admin_configure_alter
    ./blajax.module:366:} // End function blajax_get_block
    ./blajax.module:421:        break; // all
    ./blajax.module:426:        break; // subject
    ./blajax.module:430:        break; //default
    ./blajax.module:434:} // End function blajax_get_block_data
    ./blajax.module:468:} // End function blajax_get_caption
    ./blajax.module:523:} // End function blajax_init
    ./blajax.module:548:} // End function blajax_js
    ./blajax.module:578:} // End function blajax_menu
    ./blajax.module:590:} // End function blajax_perm
    ./blajax.module:770:} // End function blajax_preprocess_block.
    ./blajax.module:806:} // End function blajax_theme
    ./blajax.module:861:} // End function theme_blajax_link
    ./blajax.module:896:} // End function theme_blajax_toolbar
    ./blajax.module:922:} // End function theme_blajax_captionbar
    ./blajax.module:979:} // End function _blajax_check_path
    ./blajax.module:1003:} // End function _blajax_form_save_block
    ./blajax.module:1039:} // End function _blajax_form_validate_block
    ./js/blajax.js:152:					case "all": // entire block
    ./blajax.admin.inc:199:} // end function blajax_admin_settings_form
    
  • ./blajax.install: all functions should have doxygen doc blocks, see http://drupal.org/node/1354#functions
    
    function blajax_update_6000() {
    
  • ./blajax.module: all functions should have doxygen doc blocks, see http://drupal.org/node/1354#functions
    
    function _blajax_block_data($module, $delta) {
    --
    
    function _blajax_check_path($configOption) {
    
  • ./blajax.module: The description on the line after the @param/@return documentation is either missing or not formatted correctly. See http://drupal.org/node/1354#functions
    19- *  Which action to perform. Possible options are:
    26- *  The module name as used in any block related function
    29- *  The block delta as used in any block related function
    32- *  The block id as used in any block related function
    127- *  Equivalent to the related action of the link.
    130- *  The module name as used in any block related function
    133- *  The block delta as used in any block related function
    136- *  The block id as used in any block related function
    374- *  The module name as used in any block related function
    377- *  The block delta as used in any block related function
    380- *  The block id as used in any block related function
    383- *  Which data to return (default: 'all')
    386- *  The new block content or parts of it
    442- *  The module name as used in any block related function
    445- *  The block delta as used in any block related function
    448- *  The block id as used in any block related function
    451- *  Fallback value if no different caption has been set
    454- *  The effective caption
    812- *
    814- *
    816- *
    818- *
    820- *
    822- *
    824- *
    826- *
    828- *
    830- *
    832- *
    867- *  The pre-themed link elements
    870- *  The pre-themed caption bar
    873- *
    875- *
    877- *  The module name as used in any block related function
    880- *  The block delta as used in any block related function
    883- *  The block id as used in any block related function
    902- *
    904- *
    906- *
    908- *  The module name as used in any block related function
    911- *  The block delta as used in any block related function
    914- *  The block id as used in any block related function
    930- *  The module name as used in any block related function
    933- *  The block delta as used in any block related function
    955- *  For which option we are to check the path
    958- *  Whether the requested option is active in this path.
    
  • Assignments should have a space before and after the operator, see http://drupal.org/node/318#operators
    ./blajax.module:836:  $type, $path, $query, $class, $id, $label, $tooltip, $module, $delta, $bid, $use_icons=FALSE
    

This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.

doitDave’s picture

Status: Needs work » Needs review

Thanks, chakrapani, for the review!

I fixed everything as noted and committed. Hopefully I forgot nothing!

I think I will have to read myself into the translation documents then. Or can anyone quick-advise me how and when to add my existing translations so there is as few extra work as possible?

Just a question (as I see such differences often here):
Why do some coder executions - with exactly the same settings! - obviously produce different results as others? When I ran coder just before the most recent commit, it had absolutely nothing to claim. Is this a known issue?

Remark:

Coder found 1 projects, 5 files, 0 warnings were flagged to be ignored

beanluc’s picture

Why do some coder executions - with exactly the same settings! - obviously produce different results as others?

I used to experience the same thing. When I moved from Coder X.x-X.x to Coder X.x-X.x-dev versions, I found that there are differences. I believe that most reviewers are using the -dev versions of Coder.

jthorson’s picture

[minor] Comment should be read "Implements hook_foo()."

This particular one was a code style change between Drupal 6 and Drupal 7. It may not appear if using the Drupal 6 version of coder, but will be flagged by the Drupal 7 version (which is being leveraged by some reviewer's automated review scripts).

klausi’s picture

Status: Needs review » Needs work

Review of the 6.x-1.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.

manual review:

  • remove the 6.x-0.x branch, I think you don't need it anymore? Also clean out the master branch, as described here in step 5: http://drupal.org/node/1127732
  • blajax.js: indentation errors, use the same 2 space style as in PHP files
  • ""SELECT caption FROM {blajax} WHERE module='%s' AND delta='%s'",": there should be a space before and after the "="
  • "$success = $action == "refresh" || is_object($test=user_save($user, $user_ext));": same here.
  • "$items["js/blajax/action/%/%/%/%"] = array(": I think you should add a permission who is allowed to use that path.
  • "t('You should be aware that refreshing every !value ...": why are you using the "!" placeholder here? The value should be a integer anyway, so use "@".
doitDave’s picture

Status: Needs work » Needs review

Fixed everything (hope so) even while it was hard to become familiar with the git bash and branch deletion. ;)

Edit: klausi, a permission callback other than "TRUE" would not help here. The callback function (blajax_action) does several checks inline as there is more than one permission to be checked (authenticated user, refresh permission...).

jthorson’s picture

Regarding your 'EDIT' comment in #17 ... unless an anonymous user is expected to be allowed to use the 'auto-refresh/refresh blocks with AJAX' permisisons, then why not a permission callback of 'user_is_logged_in()'; which could help simplify the code?

doitDave’s picture

Hi jthorson, actually this is just BECAUSE I want to keep code simple ;)

All reaction to the Ajax request is handled/coordinated in blajax_action. But there, a difference is made depending on the kind of request. While anonymous of course may not totally hide or even minimize a block, he may refresh it (as long as the site admin decides to allow that). The callback function - IMO - is the first place where I can evaluate more than one permission as the menu system can't.

Any other approach would be rather less simple, since I would have to implement a separate callback function to evaluate these mixed permissions (would end in probably inconsistent code because blajax_action still would need to check it again) or to build multiple menu callbacks which partly do the same.

doitDave’s picture

Some final changes:

  • Identified some final potential XSS risks and fixed them.
  • Designed the project page with the recommended infos (also added clear information on similar, but not duplicate properties with other modules).
  • I have now ran klausi's script. Result (see comment below(*)):
    Review of the 6.x-1.x branch:
    • All text files should end in a single newline (\n). See http://drupal.org/node/318#indenting
      ./blajax.admin.inc ./README.txt ./js/blajax.js ./blajax.install ./blajax.module ./css/blajax.css ./blajax.info
      

    This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner. <-- I'm about to do so! ;)

(*) I simply don't get this clean. I manage all those project files with unix style linebreaks even on my windows machines. They look fair in both Windows and Linux environment. Also when I download the snapshot from the git repo viewer page, there is a trailing newline at the file end. Is this eventually a script issue?

However, now impatiently waiting for the holy spaghetti monster to do some final magic here and let me pass! ;)

natemow’s picture

Cool module -- I'm only seeing the Refresh and Edit options while authenticated as an admin, though; should I be seeing Hide, Minimize, Maximize as well? Am I missing a config option somewhere?

doitDave’s picture

Thanks :)

Well, minimize/maximize/hide is of course only available for the blocks that are allowed to be hidden (see block config). Otherwise, users could hide/minimize e.g. advertisement blocks that the site admin would always like to be seen ;)

But as you may not be the only one to wonder, I have just updated this in the readme.txt - any other suggestion? :-)

As for edit/refresh, the user needs permissions to configure blocks / refresh blocks etc., should I make this clearer at some point?

natemow’s picture

Status: Needs review » Needs work

Got it, thanks -- that last pass was just general UAT. Just did a quick review of the actual code:

  • Missing a t() on '#description' on 'Blajax additions' field in blajax_form_block_admin_configure_alter
  • PAReview is still reporting "All text files should end in a single newline (\n). See http://drupal.org/node/318#indenting" -- I got around this by adding 2 lines to the end of files; I suspect this is more of a Git trimming issue than a problem with PAReview, though. Otherwise, the mod came up clean.
  • [super picky] Personally, I would lose the "// End function" comments and "//-------" visual delimiters...any decent IDE will apply code collapse to delineate functions.

Aside from those minor tweaks, this looks good to me...solid code base, works as described and is generally super-useful on 6.x sites.

doitDave’s picture

Hi!

  • Ups! Thank you for finding the missing t(), really would not have seen that. :)
  • As I stated in #20: There definitely *are* newlines. I have just even appended a second newline to each file - which transfers correctly to the repo but still lets pareview complain. So I re-set it to *one* newline. Please have a manual check by downloading the latest snapshot or looking at the raw data e.g. here (depending on your browser, you might have to look at the raw source of the displayed raw source ;)).

Also thanks for reviewing in general and for your compliments :)

Edit:

that last pass was just general UAT

Which is _really_ appreciated. Should you find anything else missing or lousy documented, please let me know. The worst UAT is the one that the developer performs himself, that is my belief :)
d.

doitDave’s picture

Additions

Coding styles
Yes, you are right about these //end comments as well. They remained from other projects I did but in a good IDE they are really unnecessary. I have dropped them. Other for the //-- separators, as long as Drupal cs does not deprecate them, I would keep them for sentimental reasons ;)
Newline issues
As I said above, I don't think it is a git issue as a re-download proves (at least here on both Win and *x machines.
But a first interesting finding: While I had added the second newline to each file, pareview still complained on missing newlines for these files: [empty]. Reducing them back to one, it re-claims with filenames. Thus, one will definitely have to dig into the script. IMHO. Perhaps I will find some time for that this weekend.
raynimmo’s picture

Have you checked out the latest version of PAReview.sh as it has a bug fix related to the newline detection.

natemow’s picture

Status: Needs work » Reviewed & tested by the community

Looks good to me...I'm putting the RTBC stamp on it; I see the newlines in browser source (though still not in bash), but don't consider the issue a stopper; more experienced reviewers are welcome to chime in, of course.

Some things to consider going forward -- it will be interesting to see how/if this mod plays with D7 contextual links. I also found this backport of the same: http://drupal.org/project/contextual ...I see that your mod's scope is a bit more focused, but it may be worth considering a merge at some point.

doitDave’s picture

Hi, thanks for your green lights :)

Short note on the contextual links: When I started creating this module, D7 was far from release and I had no clue that was planned. After all I do not think of a 1:1 port for D7, as the CL approach is fine and all improvements should be made there. We will see. :)

I will check with the new release of pareview asap, thanks for the hint!

klausi’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new7.37 KB

Review of the 6.x-1.x branch:

This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.

Manual review:

  • SOAP? Where exactly does the SOAP support in your module live?
  • $label = theme('blajax_link_label', check_plain($label), ...: do not use check_plain() here, move that to your theme function. Sanitization should always happen as closely as possible to the actual output.
  • ""SELECT * FROM {blajax} WHERE module='%s' AND delta='%s'",": there should be a space before and after "="
  • "$postdata['module'] = preg_replace(": why do you sanitize the $_POST data here? You are not outputting it anywhere to the user and you use the DB API properly which will escape anything dangerous for you. Maybe I miss something, but you should move the sanitization to the places where it actually could be dangerous.
  • blajax_get_caption(): same here, do not check_plain() so early.
  • I'm very happy with your documentation, good work on the function doc blocks!
  • blajax_get_block(): you have a very loooooooong if statement in there, which is very hard to grasp. Try to split it up as described here: http://drupal.org/node/318#linelength
  • You are using your own style of breaking lines (you do it early sometimes). I don't think it violates our coding standards, but it looks quite unusual to me and might be harder to read for some people. However, I don't insist that you change it, just wanted to let you know.
klausi’s picture

Issue summary: View changes

Formatting

doitDave’s picture

Status: Needs review » Needs work

Hi Klausi,

thanks for your points. My response:

SOAP
You're right. Dropped. Don't ask any further. ;)
Newlines
Please! To the rescue! Not again! Please, please read all the recent comments on that. And if you have a solution, I will gladly apply it. I promise! But I have no clue what else to do. Just check the comments here (and, as you know, elsewhere in the queue). There *are* newlines. Have you e.g. checked a snapshot? Really annoying thing, this :-((( See below.
SELECT...
Fixed. Thanks.
drupalcs
Fixed, except:
261 | WARNING | Format should be * Implements hook_foo().
Not here :)
very loooooooong if statement
I agree. Normally. But one advantage of NOT splitting a statement is that evaluation ends as soon as one condition is false. Thus I prefer such constructs whenever CPU is at risk which is the case here as soon as some guys and some self-refreshing blocks are around. in any other case I would just fix it with some intermediate vars and go, but I hope you can understand the point and trust me that I'm not interested in the Most Compact Condition In Least Lines Of Code Award[tm].
Line break style
I'm a window messie. I have rather 60 cols visible in one window than 100. And I hate few things more than horizontal scrolling. And I don't totally agree on readability as I mostly (at least try to) break with a certain sense. Hopefully my way won't hurt anyone and I will have an eye on it the next days. Just for a different sight.
Checking plain "too early":
I don't agree here:
  1. Theming aims to separating code from design. One could discuss whether values are rather code or rather style, but I do not want to leave it to a themer to sanitize my output. So I pass him a checked plain value and do the sanitation at the last point of coding (at least in this context). I cannot see why this should be wrong. So unless forced by any standard or convinced with a good argument, I would not really like to change this. Hope you can agree and/or understand? Or give me the missing link in my mind for a better understanding?
  2. For the $_POST sanitation, please refer to comments #7 to #11 in order not to roll this up again (hey, I was glad there was a solution at last...! :/ )

Thanks for now, next to go!

doitDave’s picture

Status: Needs work » Needs review
raynimmo’s picture

StatusFileSize
new4.41 KB

RE: new lines
Sorry to say it Dave but Klausi's script is spot on, there are no new lines at the end of the files. What it does have is new lines at the end of the previous line but no newline on the very bottom line.

I know you are using TextPad for coding, with the files open, hit 'CTRL+Q' (the cursor should change to a finger pressing a key) then click 'I'. It will show you the indentations and line breaks as dots and small symbols, newlines are like a backwards 'b'. You should have one of these on the very last line to pass the new line test ran by PAReview.sh.

When I first downloaded your module it said...


  • All text files should end in a single newline (\n). See http://drupal.org/node/318#indenting
    ./blajax.admin.inc ./blajax.info ./blajax.install ./blajax.module ./css/blajax.css ./js/blajax.js ./README.txt
    

This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.

Then once I inserted the newline characters it reported back...


This automated report was generated with PAReview.sh, your friendly project application review script. Go and review some other project applications, so we can get back to yours sooner.


check the attached screenshot example (blajax-newline-example.png) Your original code is on the left and the edited version is on the right.

I was going to zip them up and send them to you but I will leave that as an exercise for you :)

note* and all this on a Windows box.

raynimmo’s picture

Status: Needs review » Needs work

changed just so you notice :)

doitDave’s picture

Status: Needs work » Needs review

Thank you, Ray.

Things could be so much easier for most people here if the documentation would simply read

All text files should with a blank line (that is actually two \n at the very end).

For me and I suppose for many others a "newline" is the "\n" character. What is meant here is obviously a blank line.

Ok. Whatever. Fixed again. Tired.

klausi’s picture

  • There are many examples where sanitization is done in theme functions, see theme_image() for example. However, you removed the check_plain() from the return statement of an API function, so I'm satisfied.
  • blajax_create_link(): for the l() at the end: no need to check_plain($tooltip) here, this will be done by drupal_attributes() in l() for you (and double escaping is bad).
  • Regarding the post data: you want to save CPU cycles on the long if statement, but you keep the preg_place() for every request (which is much more expensive)? You argument is not consistent here :-P _blajax_block_data() is safe for any data provided. blajax_get_block_data() looks more vulnerable: $delta is never sanitized and you pass it as is to the theme function. I'm not sure how an attacker could exploit that (would have to do a POST request on your behalf with script code in it that is then passed through Drupal and rendered in you browser to get the XSS effect). Anyway, "case "all"" in blajax_get_block_data() looks like the perfect place to do sanitization.
  • ""SELECT custom,title FROM {blocks} WHERE bid=%d",": there should be a space before and after "=". And after ",".
doitDave’s picture

Status: Needs review » Needs work

Thanks again for looking!

blajax_create_link() / l() / check_plain()
Ok, done!
CPU argument not consistent
Depends on the perspective. I put safety over performance where necessary, but I don't want too waste CPU where possible. Is that really an antagonism? ;) OK: I have, again, traced those variables. You are right. $_POST['module'] cannot do anything bad; it is not evaluated anywhere in a dangerous way. So I can gladly lose this CPU-expensive preg. for $delta, it is only used in database calls as far as I could find and thus not considered dangerous atm. The only point where a $delta/$module/$bid is passed to themes is in preprocess_block, but there it's obtained from block module and thus not coming from $_POST. The only remain is the one you claimed. I have fixed it there.
SELECT custom,title
Fixed.

return TRUE;

doitDave’s picture

Status: Needs work » Needs review
klausi’s picture

  • I think you changed the wrong line in blajax_create_link()? I was refering to check_plain($tooltip) on line 250. $label on line 219 must be sanitized as it is user provided data (or you do it in your theme function).
  • blajax_get_block_data(): $bid and $delta must be numbers, right? So I suggest to just cast them to integers instead of using check_plain().
doitDave’s picture

Status: Needs review » Needs work

Whoops. You are right. Dammit! ;) Fixed.

Good idea to do a typecast - for $bid. Great! But $delta may also be a string as of API docs. So there's no getting around it here.

Committed.

Edit:
Just installed the latest versions of drupalcs and PArewiev.

Review of the 6.x-1.x branch:

  • Drupal Code Sniffer has found some code style issues (please check the Drupal coding standards):
    
    FILE: .../web/dp709/sites/all/modules/pareview_temp/test_candidate/blajax.module
    --------------------------------------------------------------------------------
    FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
    --------------------------------------------------------------------------------
     261 | WARNING | Format should be * Implements hook_foo().
    --------------------------------------------------------------------------------
    

For the single warning, see comments above (I suggest extending the drupalcs rules for these specific hook implementations, btw. Will raise an issue on the project's queue. Also, is there a way to always being informed about the latest devs of both tools except for manually checking their repos?).

doitDave’s picture

Status: Needs work » Needs review
klausi’s picture

Status: Needs work » Reviewed & tested by the community

pareview.sh and drupalcs are under heavy development right now, I suggest to git pull them every time before you start working. I'm not aware of any git notification system that tells you about new commits (maybe there are some RSS feeds somewhere).

drupalcs complains about your artificial function separators (// -----------), see attachment. You could use /* ... */ style comments, if you don't want drupalcs to complain, as they are not checked.

Yes, hook_form_FORM_ID_alter() is a false positive :-(

Otherwise I think this is ready.

and a big doitDave++ for looking into so many other project application issues. Thanks!

klausi’s picture

StatusFileSize
new3.33 KB

Forgot attachment.

doitDave’s picture

Okay, I will either switch to /* ---- */ or drop my beloved horizontal garden fences anyhow. I will reflect on it.

/* ----- OT ----- */

And when you thank for me reviewing other stuff, I have to

a) say a big thanks for your work not just in the queue but first of all on these really really helpful tools. I will try to go on supporting here and also the tool development, be it at least by raising issues such as the false positive I just added there today.
b) repeat what has been said so often: Anyone complaining about the long-lasting review process should either support the process as good as he may himself or re-consider his complaint ;)

Adding to b): We should also really make it clearer to all that anyone is not just encouraged but also "allowed" to do so (once he has read the related docs, that is). Many may have concerns whether they, as "newbies", may simple "judge" on others' work (and some feel offended in their work if other "newbies" do; that's what I have experienced as well).

I'm sure this should be discussed in a more appropriate place - where is that, btw? ;)

klausi’s picture

doitDave’s picture

/joined. thx!

doitDave’s picture

...ok. "Garden fence" comments now should pass latest drupalcs runs.

Thx again!

tr’s picture

Status: Reviewed & tested by the community » Needs work

All your files end with a blank line. This is wrong. Use Drupal core as an example and you will see that no core files have trailing blank lines.

doitDave’s picture

I'm speechless right at the moment.

What is this going to be? Do you feel indirectly offended in any way by http://drupal.org/node/1339850#comment-5267124 then please get in direct contact.

I am willing for any constructive argueing. But not for this.

Okay. Just read http://drupal.org/node/1340276#comment-5267276 and this gets clearer. Pardon me.

But honestly. As long is there no clear point from either side. Do we all want to artificially prolong the queue with this or can this please be considered non-blocking until there is unity? This is _REALLY_!_!_!_ annoying for any applicant.

tr’s picture

Status: Needs work » Needs review

Huh? What are you talking about?

doitDave’s picture

Just changed my comment, pls have a look again. Will contact you personally also right now. Sorry.

jthorson’s picture

Some interpret 'end with a single newline' as there should be no more than one at the end of the file, and others interpret it as 'the end of a file (last line) should contain a single newline'. If we're talking core patches, then strictly the former is the correct interpretation - but I know that I personally always assumed the second.

Let's try not to hold up applications for basic coding standards violations ... this will get sorted out through automation as we turn it up (since a bot will only enforce one interpretation or the other) ... but for now, I don't really think it's worth holding up applications for this particular coding standards debate, which doesn't really affect readability of the code in any way.

That said, I'd still block any files which don't have 'at least one' newline (due to the 'no newline at end of file' error that future patches would trigger), and no file should ever have 'more than two'.

jthorson’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC as per 41, and considering my comments above.

elc’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your contribution, David! Welcome to the community of project contributors on drupal.org.

I've granted you the git vetted user role which will let you promote this to a full project and also create new projects as either sandbox or "full" projects depending on which you feel is best.

Thanks, also, for your patience with the review process. You have been a great help in the review process by reviewing other projects, and I hope you continue that involvement. I have found this part of the d.o community to be one of the best places for picking up on a huge amount of knowledge about the different ways to get things done and continue to learn things every day.

Please also consider the following:

Remove block as dependency
There is no need to include core required modules as there is no way to not have them installed.
Consistency of quotes
You have single and double quotes mixed without any real pattern. Even within the same concatenated string. There's no guideline on which you should be using, but using single quotes as much as possible is faster for PHP to handle. There are two exceptions - when variable expansion is desired, and to avoid escaping apostrophes.
git commit messages
Please refer to Commit messages - providing history and credit about giving yourself some credit and properly formatting commit messages.
doitDave’s picture

Thanks everyone in the comments for his efforts, his patience, his time and most of all the many learnings I can take with me from this process. Although partially driving me nuts, this has been an experience I do not want to miss.

@ELC: Special thanks for your final hints, especially for pointing me to the quote style thing. To be honest, I never really had that actively on my radar although I know about the backgrounds. Great!

And yes, I will stick to helping in the review queue. I have already joined the related group, just to mention, and added some proposals.

Cheers!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

"SOAP" terminus removed.