PHP Filesystem manipulation security concerns -
i looking best practices, modules, etc. securely file system manipulation via php application. cms-like application not use database, instead markdown files placed in folders , processed @ display time. therefore, there lot of moving files around, renaming files, writing files, etc.
i looking either find libraries (e.g., equivalent orm) manage such actions, input sanitization, moving files. etc. rather start scratch. if nothing available, listing of best practices, etc.
so far have found guidance php.net.
more information: plan build web based end-user interface sits ontop of stacey. have test environment end user interface, , when changes ready synced production environment. non-db based system. stacey convenient manage , work developer standpoint, user's don't want work directly markdown , move files, etc.
also: please limit answer php issues; server things chrooting or locking down server dependent upon user's individual environment , needs. development standpoint, want focus on securing distributed code.
i don't know of specific libraries -- filesystem support in php extensive i'm not sure why they'd necessary. might better off starting existing cms , modifying want -- understand might not possible. sounds sort of thing should using database, guess know that.
i can't claim know exact best practice, more general advice.
first, web server -- , therefore php scritps -- running user. depends on configuration , particular server underlying os. ideally want make sure user has access filesystem area using storage. deny access everywhere else apart read-access needs (your scripts, etc) , read-write storage area. exact way depends on system.
that's last line of defense, not rely on it, it's there safety net.
it's not clear cause files renamed, moved, altered it's safe bet it's user input. therefore need make sure sanitize user input, if page name becomes file name want not want let enter ../../index.php page name , nuke main site.
always assume worst case: user knows internals of system intimately , aiming damage. not rely on 'security obscurity' or 'nobody ever that'.
what (and have done before) 2 fold. first wrap filesystem functions class provides same functions methods. job of class check happening allowed, means it's going have read paths , filenames , work out location of changes.
secondly, sanitize user input malicious when first arrives. might want @ using escapeshellarg or url encoding, or else depending on input is.
you mention files processed @ run-time, if users allowed write scripts (or worse php gets executed) have lot more issues , may have fundamental problem. that's not clear question.
hope helps.
Comments
Post a Comment