Skip to content

Commit d24c734

Browse files
authored
make sure admin pages are protected (#399)
1 parent 7b1ef90 commit d24c734

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ repos:
110110
language: system
111111
files: ^resources/.*\.php$
112112
exclude: ^resources/lib/UnityHTTPD\.php$
113+
- id: assert-forbidden-used
114+
name: Assert forbidden() is used
115+
entry: bash ./test/assert-forbidden-used.bash
116+
language: system
117+
files: ^webroot/admin/.*\.php$

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
This will enable strict mode and throw an exception rather than returning `false`.
2323
- `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
2424
`resources/**/*.php` should throw exceptions instead.
25+
- all pages under `webroot/admin/` must check for `$USER->isAdmin()` and call `UnityHTTPD::forbidden()` if not admin.
2526

2627
This repository will automatically check PRs for linting compliance.
2728

test/assert-forbidden-used.bash

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set -euo pipefail
2+
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
3+
if [[ $# -lt 1 ]]; then
4+
echo "at least one argument required"
5+
exit 1
6+
fi
7+
8+
rc=0
9+
for file in "$@"; do
10+
grep_rc=0; grep -q UnityHTTPD::forbidden "$file" || grep_rc=$?
11+
case "$grep_rc" in
12+
0)
13+
: ;; # code is good, do nothing
14+
1)
15+
echo "UnityHTTPD::forbidden() was not called in file '$file'!"; rc=1 ;;
16+
*)
17+
echo "grep failed!"; rc=1 ;;
18+
esac
19+
done
20+
exit "$rc"

0 commit comments

Comments
 (0)