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

Move and Split include/security #5946

Merged
merged 7 commits into from Oct 19, 2018

Conversation

theatischbein
Copy link

@theatischbein theatischbein commented Oct 17, 2018

To issue #3878 I did

  • split up include/security.php as proposed in the ethercalc into
    • /src/Core/Authentication.php
    • /src/Util/Security.php
  • rename function Authentication::authenticate_success to Authentication::success
  • remove old calls of require_onces(security.php) (sometimes the file wasn't even needed)
  • replace in Authentication.php old System::baseUrl() with $a = self::getApp() and $a->getBaseUrl()

Strange thing was:

  • in some file there were functions from former /include/security.php but no require_onces(security.php)
  • Are they included by some other use Friendica\... call ?
  • Now in those classes I add the proper use call

Also needed PR in addon friendica/friendica-addons#756

@MrPetovan
Copy link
Collaborator

MrPetovan commented Oct 17, 2018

Under the previous require system, some common libraries (database, security, etc...) would end up systematically included, which means that a require call in certain files wouldn't be needed in order to have the functions accessible. Of course this was a terrible practice and I'm glad you're participating to the effort or moving to an explicit autoload system.

Copy link
Collaborator

@MrPetovan MrPetovan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work, I have several requests, mainly about names/locations.

*
* @return string Hashed data
*/
public static function cookie_hash($user)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you move global functions to a class, please rename the methods to camelCase. You can also add details on the method behavior.

For example, I would rename this method to getCookieHashForUser since it returns data (get- prefix) and has a mandatory User record parameter (-ForUser suffix).

* @param int $time
* @param array $user Record from "user" table
*/
public static function new_cookie($time, $user = [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this method to setCookie.

* @param type $interactive
* @param type $login_refresh
*/
public static function success($user_record, $login_initial = false, $interactive = false, $login_refresh = false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this method to setAuthenticatedSessionForUser.

/**
* @brief Kills the "Friendica" cookie and all session data
*/
public static function nuke_session()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this method to deleteSession.

Addon::callHooks('logged_in', $a->user);

if (($a->module !== 'home') && isset($_SESSION['return_url'])) {
goaway($a->getbaseUrl() . '/' . $_SESSION['return_url']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be the object of a future PR, but please keep in mind in your refactoring that goaway() or any other HTTP redirection function/method should only be called from within a module, in this case the Login module.


public static function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'form_security_token')
{
if (!check_form_security_token($typename, $formname)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for this lone call to a non-existent function once you removed include/security.php.

}
}

?>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the closing PHP tag and leave a single new line at the end of the file.

if ($user) {
$value = json_encode(["uid" => $user["uid"],
"hash" => self::cookie_hash($user),
"ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for global functions, their corresponding file should be require_once by this file until we move them to classes.

src/Core/Authentication.php Show resolved Hide resolved
}

if ($login_initial) {
logger('auth_identities: ' . print_r($a->identities, true), LOGGER_DEBUG);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for global functions, their corresponding file should be require_once by this file until we move them to classes.

@MrPetovan MrPetovan added this to the 2018.12 milestone Oct 17, 2018
$local_user = local_user();
$remote_user = remote_user();

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**is used to indicate doxygen documentation. Please use /* for inline comments

AND deny_gid = ''
";

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**is used to indicate doxygen documentation. Please use /* for inline comments

*/
if ($local_user && $local_user == $owner_id) {
$sql = '';
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**is used to indicate doxygen documentation. Please use /* for inline comments

@MrPetovan
Copy link
Collaborator

I'm sorry you have some conflicts to solve after the last merge.

@MrPetovan
Copy link
Collaborator

Have you checked for any remaining instances of the global function names you removed in the whole repo (vendor/ excluded)?

@theatischbein
Copy link
Author

Do you mean the function names from include/security.php with global function names ?

@MrPetovan
Copy link
Collaborator

Yes I do. There were a couple remaining when you first submitted the PR, so I just want to make sure you double-checked everywhere. Watch out for function references as callbacks, some IDEs (like NetBeans) will miss those function references because it's a simple string.

@theatischbein
Copy link
Author

theatischbein commented Oct 17, 2018

I had a typo and not all files were changed by refactoring.
Now I checked for all old function names. There are only left in comments or logs.
Edit: As I write this, I think I should change the logs to...

@MrPetovan
Copy link
Collaborator

Please update comments and logging strings as well.

@MrPetovan MrPetovan merged commit ec0d3a6 into friendica:develop Oct 19, 2018
@MrPetovan
Copy link
Collaborator

Thank you for your work once again!

@annando
Copy link
Collaborator

annando commented Oct 19, 2018

@jonnytischbein There's a problem:

PHP Warning: require_once(include/security.php): failed to open stream: No such file or directory in /path/to/friendica/mod/pubsub.php on line 9

@MrPetovan
Copy link
Collaborator

I'm on it.

@annando
Copy link
Collaborator

annando commented Oct 19, 2018

Please have a look at src/Protocol/DFRN.php as well.

@MrPetovan
Copy link
Collaborator

Yup.

@tobiasd
Copy link
Collaborator

tobiasd commented Oct 20, 2018

This seems to have broken my system. The system chokes and throws an error 500; so far I could not find anything in the logs.

@theatischbein
Copy link
Author

theatischbein commented Oct 20, 2018

At which page do you get this error? Or at any page?
Do you know which addons you have activated? Because there were changes too. (Did you pull in addon?)

I can't reproduce am error 500 at current develop.

@tobiasd
Copy link
Collaborator

tobiasd commented Oct 20, 2018

Addons is a good hint yes. Maybe it is the projects addon I'll have a look.

@tobiasd
Copy link
Collaborator

tobiasd commented Oct 20, 2018

Jupp pinging @fabrixxm so he can check ;-)

@MrPetovan
Copy link
Collaborator

There were a couple of addons that required the include/security.php file, have you updated them?

@theatischbein
Copy link
Author

theatischbein commented Oct 20, 2018

Yes in friendica/friendica-addons#756

But since I missed some in the base repo, I'm not trusting my methods with grep and IDE :/
On my branch that you merge shouldn't be any require_ones. (I checked just now) They only were used in windowsphonepush.php and advancedcontentfilter.php

@MrPetovan
Copy link
Collaborator

I can confirm there aren't any more instances of security.php in addon, but maybe @tobiasd didn't pull the addon repo.

Repository owner deleted a comment from tobiasd Oct 21, 2018
Repository owner deleted a comment from tobiasd Oct 21, 2018
@MrPetovan
Copy link
Collaborator

@theatischbein
Copy link
Author

theatischbein commented Oct 21, 2018

Seems to be an addon projects which isn't included in the addon repo.

@tobiasd
Copy link
Collaborator

tobiasd commented Oct 21, 2018

Sorry for the tone of my comment @jonnytischbein I really appreciate your efforts of support in that issue. Since the projects addon is not official you don't need to worry about it not being updated with the rest :-)

@MrPetovan you as well sorry!

@MrPetovan
Copy link
Collaborator

It's all good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants