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

Dev: add a function helper for #14650: Really throw error when user try to hack server #1248

Closed
wants to merge 3 commits into from

Conversation

Shnoulle
Copy link
Collaborator

No description provided.

@Shnoulle Shnoulle requested a review from LouisGac March 25, 2019 08:04
@Shnoulle
Copy link
Collaborator Author

It's just a base idea : adding unlink, file_get_contents etc … all goes to App() with same restriction.

After need to find all rmdirr call (but a grep and it's done)

@Shnoulle
Copy link
Collaborator Author

@Shnoulle Shnoulle requested a review from c-schmitz April 13, 2019 12:32
@Shnoulle
Copy link
Collaborator Author

When error happen :

  1. always log it as error, then server admin can see something happen
  2. If user is a super admin + debug : throw error (debug set or not) by default
  3. In some condition : throw error (sample : user is allowed to edit theme, and theme try to remove a bad file)
  4. In some condition : throw error (for rmdir for example)

@c-schmitz
Copy link
Contributor

Shouldn't all rrmdir calls use the new function and remove the old one?

@Shnoulle
Copy link
Collaborator Author

Yes, it's why it's currently an idea , and need to be improved , update other accessand used in future …

I make it after a security issue about template deletion where any user can remove any dir in server … it's fixed but without alert … Try to hack server => need a log way somewhezre (and in my opinion HTTP error is better).

Related discussion about HTML errors : 9a8a031#comments
Related mantis about HTML errors : https://bugs.limesurvey.org/view.php?id=16470

@cdorin93 cdorin93 removed the request for review from LouisGac October 22, 2020 15:09
@c-schmitz
Copy link
Contributor

@Shnoulle Can you go ahead and implement this for all rrmdir calls?
It probably should also go to /dev branch.

@Shnoulle
Copy link
Collaborator Author

It probably should also go to /dev branch.

Yes , clearly :)

Maybe in https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/LSFileHelper.php and not in LS_Appliction ?

My opinion : we must create a file loader helper too :)

@c-schmitz c-schmitz requested review from olleharstedt and removed request for c-schmitz April 7, 2021 15:30
@c-schmitz
Copy link
Contributor

I don't think the right place to place this function would be in the LSYii_Application class.
@olleharstedt what do you think?

@Shnoulle Shnoulle marked this pull request as draft April 7, 2021 15:42
@Shnoulle
Copy link
Collaborator Author

Shnoulle commented Apr 7, 2021

I leave it as draft, feel free for discussion.

I surely rewrite all when i have time (some plugin make me work hard currently)

Copy link
Collaborator Author

@Shnoulle Shnoulle left a comment

Choose a reason for hiding this comment

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

I don't think the right place to place this function would be in the LSYii_Application class.
@olleharstedt what do you think?

Maybe in https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/LSFileHelper.php and not in LS_Appliction ?

Unsue , FileHelper name is clear, but don't seems totally related.

$baseDir = $this->getConfig('uploaddir');
}
$dirPath = realpath($dirPath);
if(!is_dir($dirPath) || substr($dirPath, 0, strlen($baseDir)) !== $baseDir) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@c-schmitz maybe just check substr($dirPath, 0, strlen($baseDir)) !== $baseDir to throw error ?

Just return false if not exist. A bad directory inside upload are not really an hack i think ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to write a unit-test for this function? One test for happy path, one for failure. It makes it easier to understand the behaviour.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Open to discussion : it's a 2 years old pull request …

But : decision about places before no ?

@olleharstedt
Copy link
Collaborator

olleharstedt commented Apr 8, 2021

We already have rmdirr. Do we need two? 🤔

And yeah, I wouldn't expand the application class with helper functions.

application/helpers/common_helper.php

@olleharstedt
Copy link
Collaborator

Oh, it's a wrapper for rmdirr, kind of. Let me read again.

@Shnoulle
Copy link
Collaborator Author

Shnoulle commented Apr 8, 2021

Yep : it's a wrapper

When fixing : https://bugs.limesurvey.org/view.php?id=14617 Arbitrary FIle Download in LimeSurvey

I think the fix solution are bad : because it's fix ONLY for this call. Then adding a wrapper to

  1. rmdir
  2. readfile
  3. all file action

Dev must use, if not : it's an issue.

And in this wrapper : we can clearly send a Ecxeption : then server manager can have log of bad action.

@Shnoulle
Copy link
Collaborator Author

Shnoulle commented Apr 8, 2021

See the «fix»

1ed10d3

@c-schmitz
Copy link
Contributor

SO, either we finish this up or we close it. It's been around long enough.

@Shnoulle Shnoulle closed this Feb 25, 2022
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.

3 participants