Skip to content

Instantly share code, notes, and snippets.

@ncuesta
Created February 27, 2012 21:15
Show Gist options
  • Save ncuesta/1927156 to your computer and use it in GitHub Desktop.
Save ncuesta/1927156 to your computer and use it in GitHub Desktop.
Assess symfony 1.X application security
#!/bin/bash
#
# assess-security.sh
#
# AUTHOR: José Nahuel Cuesta Luengo @ncuestal
#
##
# Assess the security status of a symfony 1.X application.
#
# Available arguments
#
# -v : Verbose mode, displays both secured and non-secured modules.
# Default is to display only non-secured.
#
# -c : Create missing security.yml files with a stub one.
# Default is not to do so.
#
# [anything else] : Will be considered the application name to look into.
# Defaults to $DEFAULT_APP (usually 'frontend', see below).
##
DEFAULT_APP=frontend
APP=$DEFAULT_APP
VERBOSE=
CREATE=
IGNORE=(sfGuardAuth sfLucene)
for ARG in $*
do
case "$ARG" in
-v)
# Verbose
VERBOSE=1
;;
-c)
# Create missing files
CREATE=1
;;
*)
# Application name
APP=$ARG
;;
esac
done
if [ ! -d apps/$APP ]
then
echo "Application $APP does not exist."
exit 1
fi
for i in `ls apps/$APP/modules`
do
for IGNORED in ${IGNORE[*]}
do
if [ $i == $IGNORED ]
then
if [ $VERBOSE ]
then
echo " Ignoring module $i."
fi
# Skip this and the outer loop
continue 2
fi
done
MODULE="apps/$APP/modules/$i"
SECURITY="`find $MODULE -name security.yml`"
if [ ! -z $SECURITY ]
then
if [ $VERBOSE ]
then
echo " $i is secured."
fi
else
echo "! $i lacks of security.yml."
if [ $CREATE ]
then
if [ ! -d $MODULE/config ]
then
mkdir $MODULE/config
fi
echo -e "# Autogenerated by `basename $0`\ndefault:\n is_secure: true" > $MODULE/config/security.yml
if [ $? -eq 0 ]
then
echo " - Created stub $MODULE/config/security.yml file."
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment