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)
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | drupalcs-result.txt | 3.33 KB | klausi |
| #32 | blajax-newline-example.png | 4.41 KB | raynimmo |
| #29 | drupalcs-result.txt | 7.37 KB | klausi |
Comments
Comment #0.0
doitDave commented*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!?
Comment #1
raynimmo commentedCoder 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;
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.
Comment #2
doitDave commentedHi 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:
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 :)
Comment #3
raynimmo commentedI 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
$_POSTdata 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()orfilter_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 :)
Comment #4
doitDave commentedHey,
Yes, I did; actually exactly the same settings that you have mentioned.
Here's what remains on my site after having fixed the rest:
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 :-)
Comment #5
beanluc commentedSince there remain some outstanding items, changing status.
Comment #6
doitDave commentedOutstanding 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.
Comment #7
beanluc commentedHave 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.
Comment #8
doitDave commentedHey,
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!
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.
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...
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.
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).
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 :)
Comment #9
beanluc commentedNo. 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.
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.
Comment #10
doitDave commentedAppreciated 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?
Comment #10.0
doitDave commented(Edit info mismatch)
Comment #10.1
doitDave commentedUpdated due to changes
Comment #11
doitDave commentedOK, 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.
Comment #12
chakrapani commentedHere you go
Review of the 6.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. Please report any bugs to klausi.
Comment #13
doitDave commentedThanks, 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:
Comment #14
beanluc commentedI 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.
Comment #15
jthorson commented[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).
Comment #16
klausiReview 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:
Comment #17
doitDave commentedFixed 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...).
Comment #18
jthorson commentedRegarding 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?
Comment #19
doitDave commentedHi 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.
Comment #20
doitDave commentedSome final changes:
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. <-- 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! ;)
Comment #21
natemow commentedCool 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?
Comment #22
doitDave commentedThanks :)
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?
Comment #23
natemow commentedGot it, thanks -- that last pass was just general UAT. Just did a quick review of the actual code:
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.
Comment #24
doitDave commentedHi!
Also thanks for reviewing in general and for your compliments :)
Edit:
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.
Comment #25
doitDave commentedAdditions
Comment #26
raynimmo commentedHave you checked out the latest version of PAReview.sh as it has a bug fix related to the newline detection.
Comment #27
natemow commentedLooks 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.
Comment #28
doitDave commentedHi, 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!
Comment #29
klausiReview 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:
Comment #29.0
klausiFormatting
Comment #30
doitDave commentedHi Klausi,
thanks for your points. My response:
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.Thanks for now, next to go!
Comment #31
doitDave commentedComment #32
raynimmo commentedRE: 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...
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.
Comment #33
raynimmo commentedchanged just so you notice :)
Comment #34
doitDave commentedThank 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.
Comment #35
klausiComment #36
doitDave commentedThanks again for looking!
return TRUE;
Comment #37
doitDave commentedComment #38
klausiComment #39
doitDave commentedWhoops. 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:
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?).
Comment #40
doitDave commentedComment #41
klausipareview.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!
Comment #42
klausiForgot attachment.
Comment #43
doitDave commentedOkay, 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? ;)
Comment #44
klausiDiscussion group: http://groups.drupal.org/code-review
Comment #45
doitDave commented/joined. thx!
Comment #46
doitDave commented...ok. "Garden fence" comments now should pass latest drupalcs runs.
Thx again!
Comment #47
tr commentedAll 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.
Comment #48
doitDave commentedI'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.
Comment #49
tr commentedHuh? What are you talking about?
Comment #50
doitDave commentedJust changed my comment, pls have a look again. Will contact you personally also right now. Sorry.
Comment #51
jthorson commentedSome 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'.
Comment #52
jthorson commentedSetting back to RTBC as per 41, and considering my comments above.
Comment #53
elc commentedThanks 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:
Comment #54
doitDave commentedThanks 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!
Comment #55.0
(not verified) commented"SOAP" terminus removed.