Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #09790: Use conditions to get a subset of list_participants #349

Closed
wants to merge 1 commit into from
Closed

Conversation

Jan-E
Copy link
Contributor

@Jan-E Jan-E commented Jul 22, 2015

@c-schmitz
Copy link
Contributor

The way you are doing this would allow for SQL injections. You will need to find a more formal way of using conditions.

@Jan-E
Copy link
Contributor Author

Jan-E commented Jul 22, 2015

The external application that calls the Remotecontrol API has to deal with possible SQL-injection attempts. Mine does: it strips slashes in the e-mail address and used filter_var to see if it is a valid e-mail address.

Many functions in the LSRC are not doing anything against SQL-injection attempts. Take update_response() for instance. As far as I can see there is no check against SQL Injections.

@Shnoulle
Copy link
Collaborator

Not true.

https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/remotecontrol/remotecontrol_handle.php#L2360

Using Yii with PDO. Here you don't use PDO, then can have SQL injection.

@Jan-E
Copy link
Contributor Author

Jan-E commented Jul 22, 2015

OK. Is findByAttributes() safe for SQL Injections? If so, I could try to switch to something like Token::model($iSurveyID)->findByAttributes( ... )

@Jan-E
Copy link
Contributor Author

Jan-E commented Jul 23, 2015

I suppose findAllByAttributes() is not vulnerable for SQL Injections, otherwise this would be vulnerable as well:
https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/remotecontrol/remotecontrol_handle.php#L2344

Using findAllByAttributes() I wote the following code for list_participants:

$aAttributeValues = array();
if (count($aConditions)) {
    $aBasicDestinationFields = Tokens_dynamic::model($iSurveyID)->tableSchema->columnNames;
    $aAttributeValues = array_intersect_key($aConditions, array_flip($aBasicDestinationFields));
}

if($bUnused)
    $oTokens = Token::model($iSurveyID)->incomplete()->findAllByAttributes($aAttributeValues, array('order' => 'tid', 'limit' => $iLimit, 'offset' => $iStart));
else
    $oTokens = Token::model($iSurveyID)->findAllByAttributes($aAttributeValues, array('order' => 'tid', 'limit' => $iLimit, 'offset' => $iStart));

This is called by $aConditions = array('email' => 'info@example.com'). Would that be acceptable?

@Jan-E
Copy link
Contributor Author

Jan-E commented Jul 23, 2015

Shortened the code a little bit, because part of it was just copying $aConditions to $aAttributeValues.

@Jan-E
Copy link
Contributor Author

Jan-E commented Jul 28, 2015

@c-schmitz I have created new PR's for the master & develop branch with this code:

#355
#356

If findAllByAttributes() is vulnerable for SQL Injections, the LSRC has a lot of issues. So I must assume this use of findAllByAttributes is acceptable.

We need this for our custom registration app. Waiting for 6 seconds to get and check the list of all participants is a no-go;.

@Jan-E
Copy link
Contributor Author

Jan-E commented Aug 14, 2015

Closing, because #355 and #356 were merged.

@Jan-E Jan-E closed this Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants