Security Vulnerabilities

visolveemr wrote on Monday, July 12, 2010:

Hi

We did perform some testing related to audit against the latest changes to sql.inc and had identified two issues.

1. Checksum (to log in the audit) is not calculated correctly

2. The “last insert id” is not stored properly for “select” calls which in turn causes few issues when we enable “query” option in the audit feature.

The patch to fix the above said issues is posted in the tracker
https://sourceforge.net/tracker/index.php?func=detail&aid=2939284&group_id=60081&atid=1245239

Do share your views.

Thanks
ViCarePlus Team
services@vicareplus.com

bradymiller wrote on Monday, July 12, 2010:

Visolve,
Thanks for doing this. Feel free to commit your bug fixes.
-brady

visolveemr wrote on Tuesday, July 13, 2010:

Hi

Patch has been committed to OpenEMR CVS.

Thanks
ViCarePlus team
services@vicareplus.com

bradymiller wrote on Tuesday, July 27, 2010:

The patient searching scripts and related functions have been “cleansed”:
http://github.com/openemr/openemr/commit/a9aa64513e4556aeb2f36b049e86aac47b3fef42

-brady

tmccormi wrote on Wednesday, July 28, 2010:

Question regarding use of htmlspecialchars and the xl() function.

Lots of new code has this, increasingly hard to read construction:

echo htmlspecialchars(xl("To add notes, please click "),ENT_NOQUOTES);

Why can’t we just add the htmlspecialchars wrapper to be inside the xl() functions?

-Tony

bradymiller wrote on Wednesday, July 28, 2010:

hey,

This was discussed. This function basically convert html entities and quotes(depending on settings) to something else. If we knew all translated functions are outputted to the screen, then this would be fine. However, this isn’t the case. Some translations are used within the algorithm and some may get placed in the database; the escaping would then screw these processes up. Once the entire codebase uses this function, it will no longer be hard to read.  This simple function around every variable that a user can “touch” will put an end to cross-scripting attacks. It’s that simple.

Considering the work that’s already been done (which were all initially posted for review); this ship has already sailed.

Also, as an aside, easier with this spacing (which I’m now using):

echo htmlspecialchars( xl("To add notes, please click "), ENT_NOQUOTES);

-brady

bradymiller wrote on Wednesday, July 28, 2010:

hey,

Here’s the list of commits so far on this project:
Patient searching modules: http://github.com/openemr/openemr/commit/a9aa64513e4556aeb2f36b049e86aac47b3fef42
Transactions module: http://github.com/openemr/openemr/commit/f56f469c9d2481f3d440c79db1917e0a38f076a9
Patient history module: http://github.com/openemr/openemr/commit/a4817af442d569525b24129ed75afa915030a4dd
Immunization module: http://github.com/openemr/openemr/commit/5d06c6f08d04405a80b036810a8523a7cb680a31
Authorization module: http://github.com/openemr/openemr/commit/e08e3327b83f36164db0177c9acb8b7a1c3f9ddb
demographics.php script: http://github.com/openemr/openemr/commit/c0bfa8a51106cd97842374d5ae719bb5b469b763
Language admin gui module: http://github.com/openemr/openemr/commit/28f02594d450ce1e1546557b4cee040b8bedc194

Read through several of them. Once you’re used to it, it starts looking wrong when htmlspecialchars is not used.

-brady

bradymiller wrote on Tuesday, August 03, 2010:

The pnotes-messaging scripts and related functions have been “cleansed”:
http://github.com/openemr/openemr/commit/21e15cce4507d36c7ffd234f2c4f034b38d1087e

Thomas,
I also modularized some of the messages.php script and blindly (unable to test) fixed a bug in the interface/main/messages/lab_results_messages.php . It’s a simple bug fix, but would be great if you could do a sanity test to ensure the lab reminders still work fine.

-brady

yehster wrote on Wednesday, August 03, 2011:

Revisiting this thread because of it’s mention in the OEMR 5 discussion.

With regard to the readability of xl/htmlspecialcharacters, why not add another wrapper function (xlh) that one could use when translating a string that you are certain is output as html.  This would simply and improve readability.  Also, if we encapsulate the function it would be much easier to use. 

A developer still has to know when to use xl versus xlh (instead of the old method xl + htmlspecialchars), but it’s a 1 character change in the code rather than 20 or so.

sunsetsystems wrote on Wednesday, August 03, 2011:

Concept sounds good, reduces a lot of repetition.  Maybe an argument for the xl() function though, instead of creating a new function.

Rod
www.sunsetsystems.com

bradymiller wrote on Wednesday, August 03, 2011:

Hi,

Haven’t revisited this topic for some time. Nice to see it get some attention.

Rod, wouldn’t rec incorporate htmlspecialchars into the xl() function ( see my post #21 above for reason).

Yehster, a year ago I was opposed to creating new custom functions because during the code reviews it really seemed like developers had a much more difficult time using custom functions than the standard php functions (likely because looking them up is not accessible as the standard php function via google). Since then, though, Aron on the CDR GUI did convince me that at least abbreviating the htmlspecialchars made sense, and he actually has this code in this script here interface/super/rules/include/common.php, which worked well in the CDR admin module :

/**
 * This is a shortcut for htmlspecial vars.
 * @param <type> $txt 
 */
function out( $txt ) {
    return htmlspecialchars( $txt , ENT_QUOTES );
}

Then is out(xl()). I’d rec not trying to combine it into the xl() function or else again there will be lots of errors by developers(note that even a simple thing such as the ‘e’ parameter in the xl() function (this is now depreciated) eludes most developers; I think because most developers mimick code/patterns and don’t look up the actual functions).  Also a bit complicated because occasionally need to use addslashes rather than out and also have some other custom xl functions in library/translations.inc.
-brady

bradymiller wrote on Wednesday, August 03, 2011:

Rod,
error in my post reference; I meant post# 46.
-brady

stephen-smith wrote on Thursday, August 04, 2011:

Off-Topic, but the “e” parameter to xl() and some other functions was a pretty foolish but of coding.  “xl(stuff,‘e’)” saves a grand total of one (1) character over “echo xl(stuff)” and is actually harder to type.  It also made the xl function be not well-typed since the return type of the function depended on not just the types of the arguments but also their values.

I don’t think the result of xl() should automatically be HTML-escaped, but it would be nice to have both an abbreviation for htmlspecialchars AND an abbreviation for xl+htmlspecialchars.  I’ll add this to my TODO list.

bradymiller wrote on Thursday, August 04, 2011:

hi,
I’m neutral on the combination function, but it won’t hurt anything to have around.Since ‘out’ has already been used in the CDR Admin framework to wrap htmlspecialchars, would recommend the following:
out for the htmlspecialchars wrapper
out_xl (or something like this) for the htmlspecialchars/xl combo wrapper

-brady

stephen-smith wrote on Saturday, August 06, 2011:

My branch should be ready, I’m trying to find a up-to-date OpenEMR installation to test it on.  Once I run it through some simple tests, I’ll open a patch tracker item and start my review clock. :slight_smile:

stephen-smith wrote on Saturday, August 06, 2011:

Tested out using the sweet setup at FAIKVM.com.  One fix required (gitorious link above has already update), because I haven’t written PHP code in… a while.  Created a tracker item

bradymiller wrote on Friday, August 12, 2011:

Hi,

Was hoping to get developers (all are welcome) input regarding what our goals should be for a set of standard htmlspecialchars and htmlspecialchars/translation wrapper functions, which is currently being discussed on this tracker item here:
http://sourceforge.net/tracker/?func=detail&aid=3387325&group_id=60081&atid=493003

The hope is that we finalize a standard function set that we begin to use throughout the entire codebase (including for the Security project code walk-through).

-brady

tmccormi wrote on Saturday, August 13, 2011:

i’m in favor of letting Stephen commit his stuff, myself.  I do think that the out() function name is a bit less intuitive that text() but I’m ok with either or both for now.  No particular opinion about the ENT_QUOTES as I’m one of those guy that has no idea what it’s for.
-Tony

bradymiller wrote on Sunday, January 15, 2012:

Hi,

Just checked in two commits into sourceforge to implement the security model in the following:
Address Book module: http://github.com/openemr/openemr/commit/c3243ac074795657a35b04609b83dac7ed423af0
add_edit_issue.php script: http://github.com/openemr/openemr/commit/34874e7e1e4e76ec44fb62a07136121462b306e1

-brady

bradymiller wrote on Sunday, January 15, 2012:

Also,

Note the updated security model described here:
http://www.open-emr.org/wiki/index.php/Codebase_Security#Plan

-brady