Fixed security breach & code format & Makefile

- Fixed the security issue mentioned by @jaapmarcus by using the same PDO methods as other functions.
- Fixed code style using php-cs-fixer
- Fixed the Makefile that was using spaces insead of tabs (#116)
This commit is contained in:
CatFlip™ committed 2022-05-30 17:27:16 -05:00
1 parent bf33bdfafc
commit abadee3ef0
2 files changed
+73 -70

No files matched your search

+52 -52
View File
@@ -6,44 +6,44 @@ DOCKER_DB_CONTAINER_EXEC = $(DOCKER_COMPOSE) exec database
DOCKER_PHP_EXECUTABLE_CMD = php -dmemory_limit=1G
help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
all: start-recreate reinstall
start: ## Start app
$(DOCKER_COMPOSE) up -d
$(DOCKER_COMPOSE) up -d
ifeq (,$(wildcard ./src/bb-config.php))
cp ./src/bb-config-sample.php ./src/bb-config.php
$(DOCKER_PHP_CONTAINER_EXEC) $(DOCKER_PHP_EXECUTABLE_CMD) ./bin/prepare.php
cp ./src/bb-config-sample.php ./src/bb-config.php
$(DOCKER_PHP_CONTAINER_EXEC) $(DOCKER_PHP_EXECUTABLE_CMD) ./bin/prepare.php
endif
start-recreate: ## Start app with full rebuild
$(DOCKER_COMPOSE) up -d --build --force-recreate --remove-orphans
$(DOCKER_COMPOSE) up -d --build --force-recreate --remove-orphans
stop: ## Stop app
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) stop
remove: stop ## Stop and remove app
$(DOCKER_COMPOSE) rm -f
$(DOCKER_COMPOSE) rm -f
logs: ## Show app logs
$(DOCKER_COMPOSE) logs -ft --tail=50
$(DOCKER_COMPOSE) logs -ft --tail=50
exec-php: ## Enter PHP container shell
$(DOCKER_PHP_CONTAINER_EXEC) bash
$(DOCKER_PHP_CONTAINER_EXEC) bash
cache-flush: ## Flush Twig cache
$(DOCKER_PHP_CONTAINER_EXEC) rm -fr src/bb-data/cache/*
$(DOCKER_PHP_CONTAINER_EXEC) rm -fr src/bb-data/cache/*
exec-db: ## Enter DB container shell
$(DOCKER_DB_CONTAINER_EXEC) bash
$(DOCKER_DB_CONTAINER_EXEC) bash
install: start ## Install app after start
$(DOCKER_PHP_CONTAINER_EXEC) composer install --working-dir=src --no-progress --no-suggest --prefer-dist --no-dev
$(DOCKER_PHP_CONTAINER_EXEC) composer install --working-dir=src --no-progress --no-suggest --prefer-dist --no-dev
reinstall: ## Reinstall app
rm -rf ./src/bb-config.php
make install
rm -rf ./src/bb-config.php
make install
test: start ## Run app tests
echo "Running unit tests"
@@ -54,51 +54,51 @@ test: start ## Run app tests
$(DOCKER_PHP_CONTAINER_EXEC) ./src/vendor/bin/phpunit --dont-report-useless-tests ./tests/bb-modules/
build: ## Build App with Docker CI image
docker run --rm \
--mount type=bind,source=$(PWD),target=/opt -w /opt \
-e TRAVIS_TAG \
fordnox/docker-builder-ci \
make release
docker run --rm \
--mount type=bind,source=$(PWD),target=/opt -w /opt \
-e TRAVIS_TAG \
fordnox/docker-builder-ci \
make release
release: ## App release
echo "TRAVIS_BUILD_NUMBER:" $(TRAVIS_BUILD_NUMBER)
echo "TRAVIS_TAG:" $(TRAVIS_TAG)
npm install
gulp build
ant release
echo "TRAVIS_BUILD_NUMBER:" $(TRAVIS_BUILD_NUMBER)
echo "TRAVIS_TAG:" $(TRAVIS_TAG)
npm install
gulp build
ant release
revbump:
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1,$$2,$$3+1}' ) ;\
echo "unstable release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1,$$2,$$3+1}' ) ;\
echo "unstable release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
minorbump:
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1,$$2+1,0}' ) ;\
echo "unstable release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1,$$2+1,0}' ) ;\
echo "unstable release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
majorbump:
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1+1,0,0}' ) ;\
echo "release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
set -e ;\
git tag --sort=v:refname | tail -1
NEW_VERSION=$$( git tag --sort=v:refname | tail -1 | awk 'BEGIN{FS=OFS="."}{print $$1+1,0,0}' ) ;\
echo "release $$NEW_VERSION" ;\
git tag $$NEW_VERSION
git push --tags
build-run: ## Run app in LAMP container after build
# used to test app after build
# run `make build` before running this target
# mysql user: admin pass: admin
# access phpmyadmin http://localhost/phpmyadmin/
docker container stop boxbilling &>/dev/null || true
docker container rm -f boxbilling &>/dev/null || true
docker run -i -t --name boxbilling -p "80:80" \
-v ${PWD}/build/source:/app \
-e MYSQL_ADMIN_PASS=admin \
mattrayner/lamp:latest
# used to test app after build
# run `make build` before running this target
# mysql user: admin pass: admin
# access phpmyadmin http://localhost/phpmyadmin/
docker container stop boxbilling &>/dev/null || true
docker container rm -f boxbilling &>/dev/null || true
docker run -i -t --name boxbilling -p "80:80" \
-v ${PWD}/build/source:/app \
-e MYSQL_ADMIN_PASS=admin \
mattrayner/lamp:latest
+21 -18
View File
@@ -1,4 +1,5 @@
<?php
/**
* BoxBilling.
*
@@ -37,7 +38,7 @@ class Service
$query = 'SELECT value
FROM setting
WHERE param = :param
';
';
$pdo = $this->di['pdo'];
$stmt = $pdo->prepare($query);
$stmt->execute(['param' => $param]);
@@ -96,11 +97,13 @@ class Service
}
$query = "SELECT param, value
FROM setting
WHERE param IN('".implode("', '", $params)."')
WHERE param IN('" . implode("', '", $params) . "')
";
$rows = $this->di['db']->getAll($query);
$result = [];
foreach ($rows as $row) {
$pdo = $this->di['pdo'];
$stmt = $pdo->prepare($query);
$stmt->execute();
while ($row = $stmt->fetch()) {
$result[$row['param']] = $row['value'];
}
@@ -128,19 +131,19 @@ class Service
];
$results = $this->_getMultipleParams($c);
$baseurl = $this->di['config']['url'];
$logo_url = $this->di['array_get']($results, 'company_logo', null);
if (null !== $logo_url && false === strpos($logo_url, 'http')) {
$logo_url = $baseurl.$logo_url;
$baseUrl = $this->di['config']['url'];
$logoUrl = $this->di['array_get']($results, 'company_logo', null);
if (null !== $logoUrl && false === strpos($logoUrl, 'http')) {
$logoUrl = $baseUrl . $logoUrl;
}
return [
'www' => $baseurl,
'www' => $baseUrl,
'name' => $this->di['array_get']($results, 'company_name', null),
'email' => $this->di['array_get']($results, 'company_email', null),
'tel' => $this->di['array_get']($results, 'company_tel', null),
'signature' => $this->di['array_get']($results, 'company_signature', null),
'logo_url' => $logo_url,
'logo_url' => $logoUrl,
'address_1' => $this->di['array_get']($results, 'company_address_1', null),
'address_2' => $this->di['array_get']($results, 'company_address_2', null),
'address_3' => $this->di['array_get']($results, 'company_address_3', null),
@@ -159,7 +162,7 @@ class Service
$locales = [];
if ($handle = opendir($path)) {
while (false !== ($entry = readdir($handle))) {
if ('.svn' != $entry && '.' != $entry && '..' != $entry && is_dir($path.DIRECTORY_SEPARATOR.$entry)) {
if ('.svn' != $entry && '.' != $entry && '..' != $entry && is_dir($path . DIRECTORY_SEPARATOR . $entry)) {
$locales[] = $entry;
}
}
@@ -173,7 +176,7 @@ class Service
$details = [];
foreach ($locales as $locale) {
$file = $path.'/'.$locale.'/LC_MESSAGES/messages.po';
$file = $path . '/' . $locale . '/LC_MESSAGES/messages.po';
if (file_exists($file)) {
$lNames = $this->getLocales();
@@ -238,8 +241,8 @@ class Service
$msgs['info'][] = 'Cron was never executed. Make sure you have setup cron job.';
}
$install = BB_PATH_ROOT.'/install';
if ($this->di['tools']->fileExists(BB_PATH_ROOT.'/install')) {
$install = BB_PATH_ROOT . '/install';
if ($this->di['tools']->fileExists(BB_PATH_ROOT . '/install')) {
$msgs['info'][] = sprintf('Install module "%s" still exists. Please remove it for security reasons.', $install);
}
@@ -264,7 +267,7 @@ class Service
$themeService = $this->di['mod_service']('theme');
$theme = $themeService->getThemeConfig($client);
foreach ($theme['paths'] as $path) {
if ($this->di['tools']->fileExists($path.DIRECTORY_SEPARATOR.$file)) {
if ($this->di['tools']->fileExists($path . DIRECTORY_SEPARATOR . $file)) {
return true;
}
}
@@ -282,7 +285,7 @@ class Service
try {
$twig->addGlobal('client', $this->di['api_client']);
} catch (\Exception $e) {
error_log('api_client could not be added to template: '.$e->getMessage());
error_log('api_client could not be added to template: ' . $e->getMessage());
}
}
} else {
@@ -357,7 +360,7 @@ class Service
$serverPort = $request->getServer('SERVER_PORT');
if (isset($serverPort) && '80' != $serverPort && '443' != $serverPort) {
$pageURL .= $request->getServer('SERVER_NAME').':'.$request->getServer('SERVER_PORT');
$pageURL .= $request->getServer('SERVER_NAME') . ':' . $request->getServer('SERVER_PORT');
} else {
$pageURL .= $request->getServer('SERVER_NAME');
}
@@ -368,7 +371,7 @@ class Service
$this_page = reset($a);
}
return $pageURL.$this_page;
return $pageURL . $this_page;
}
public function getPeriod($code)