Skip to content

Commit 4948261

Browse files
committed
Add Symfony app
1 parent b90b75a commit 4948261

24 files changed

Lines changed: 1495 additions & 3 deletions

File tree

docs/execute/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Build images used for system tests.
4343
+ Specific to the `GRAPHQL_APPSEC` scenario: `gqlgen`, `graph-gophers`, `graphql-go`
4444
* For `java`: `spring-boot` (default),`akka-http`,`jersey-grizzly2`,`play`,`ratpack`,`resteasy-netty3`,`spring-boot-3-native`,`spring-boot-jetty`,`spring-boot-openliberty`,`spring-boot-payara`,`spring-boot-undertow`,`spring-boot-wildfly`,`uds-spring-boot`,`vertx3`,`vertx4`
4545
* For `nodejs`: `express4` (default), `express4-typescript`, `express5`, `nextjs`, `fastify`
46-
* For `php`: `apache-mod-8.0` (default), `apache-mod-8.1`, `apache-mod-8.2`, `apache-mod-7.4`, `apache-mod-7.3`, `apache-mod-7.2`, `apache-mod-7.1`, `apache-mod-7.0`, `apache-mod-8.2-zts`, `apache-mod-8.1-zts`, `apache-mod-8.0-zts`, `apache-mod-7.4-zts`, `apache-mod-7.3-zts`, `apache-mod-7.2-zts`, `apache-mod-7.1-zts`, `apache-mod-7.0-zts`, `php-fpm-8.5`, `php-fpm-8.2`, `php-fpm-8.1`, `php-fpm-8.0`, `php-fpm-7.4`, `php-fpm-7.3`, `php-fpm-7.2`, `php-fpm-7.1`, `php-fpm-7.0`, `laravel11x`
46+
* For `php`: `apache-mod-8.0` (default), `apache-mod-8.1`, `apache-mod-8.2`, `apache-mod-7.4`, `apache-mod-7.3`, `apache-mod-7.2`, `apache-mod-7.1`, `apache-mod-7.0`, `apache-mod-8.2-zts`, `apache-mod-8.1-zts`, `apache-mod-8.0-zts`, `apache-mod-7.4-zts`, `apache-mod-7.3-zts`, `apache-mod-7.2-zts`, `apache-mod-7.1-zts`, `apache-mod-7.0-zts`, `php-fpm-8.5`, `php-fpm-8.2`, `php-fpm-8.1`, `php-fpm-8.0`, `php-fpm-7.4`, `php-fpm-7.3`, `php-fpm-7.2`, `php-fpm-7.1`, `php-fpm-7.0`, `laravel11x`, `symfony7x`
4747
* For `python`: `flask-poc` (default), `fastapi`, `uwsgi-poc`, `django-poc`, `python3.12`
4848
* For `ruby`: `rails70` (default), `rack`, `sinatra21`, and lot of other sinatra/rails versions
4949

manifests/php.yml

Lines changed: 42 additions & 0 deletions
Large diffs are not rendered by default.

tests/appsec/test_automated_login_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,10 @@ def validate_iden(meta: dict):
11551155
libs_without_user_id_on_failure = ["nodejs", "java"]
11561156

11571157
# Weblog variants that omit appsec.events.users.login.failure.usr.exists (library-wide skips use libs_without_user_exist).
1158-
weblogs_without_user_exist = ["laravel11x"]
1158+
weblogs_without_user_exist = ["laravel11x", "symfony7x"]
11591159

11601160
# Weblog variants that omit usr.id on login failure (library-wide: libs_without_user_id_on_failure).
1161-
weblogs_without_user_id_on_failure = ["laravel11x"]
1161+
weblogs_without_user_id_on_failure = ["laravel11x", "symfony7x"]
11621162

11631163

11641164
def login_failure_includes_usr_exists_meta() -> bool:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ARG PHP_VERSION=8.2
2+
ARG VARIANT=release
3+
4+
FROM datadog/dd-appsec-php-ci:php-$PHP_VERSION-$VARIANT
5+
6+
ENV PHP_VERSION=8.2
7+
ENV DD_TRACE_ENABLED=1
8+
ENV DD_TRACE_GENERATE_ROOT_SPAN=1
9+
ENV DD_TRACE_AGENT_FLUSH_AFTER_N_REQUESTS=0
10+
ENV DD_TRACE_HEADER_TAGS=user-agent
11+
12+
EXPOSE 7777/tcp
13+
14+
ADD binaries* /binaries/
15+
ADD utils/build/docker/php /tmp/php
16+
17+
# Pre-create .env with APP_SECRET and APP_ENV
18+
RUN mkdir -p /var/www/html && \
19+
echo "APP_ENV=prod" > /var/www/html/.env && \
20+
php -r "echo 'APP_SECRET=' . bin2hex(random_bytes(16)) . PHP_EOL;" >> /var/www/html/.env && \
21+
echo "APP_DEBUG=0" >> /var/www/html/.env && \
22+
echo "SYMFONY_DB_PATH=/tmp/symfony.db" >> /var/www/html/.env
23+
24+
RUN chmod +x /tmp/php/apache-mod/build.sh
25+
RUN /tmp/php/apache-mod/build.sh symfony7x
26+
27+
# Use Symfony-specific Apache config (DocumentRoot public/, AllowOverride All)
28+
RUN cp /tmp/php/weblogs/symfony7x/.apache.conf /etc/apache2/mods-available/php.conf && \
29+
sed -i "s/%PHP_MAJOR_VERSION//g" /etc/apache2/mods-available/php.conf && \
30+
ln -sf /etc/apache2/mods-available/php.conf /etc/apache2/mods-enabled/php.conf
31+
32+
# pdo_sqlite, dom, and tokenizer are needed by Symfony (mirrors laravel11x pattern; tokenizer for attribute routing)
33+
RUN printf "extension=dom.so\nextension=pdo_sqlite.so\nextension=tokenizer.so\n" >> /etc/php/php.ini
34+
35+
# Create log directory before running PHP (php.ini writes error_log there)
36+
RUN mkdir -p /var/log/system-tests
37+
38+
# Create SQLite database and seed test users (script is at /var/www/html/bin/init-db.php via build.sh)
39+
RUN SYMFONY_DB_PATH=/tmp/symfony.db php /var/www/html/bin/init-db.php && \
40+
chmod 666 /tmp/symfony.db
41+
42+
# Warm up Symfony cache
43+
RUN cd /var/www/html && APP_ENV=prod php bin/console cache:warmup
44+
45+
# Install ddtrace (same pattern as apache-mod-X.Y.Dockerfiles)
46+
ADD utils/build/docker/php/common/install_ddtrace.sh /install_ddtrace.sh
47+
RUN /install_ddtrace.sh 1
48+
49+
# Set writable permissions on var/ directory
50+
RUN chmod -R 775 /var/www/html/var && \
51+
chown -R www-data:www-data /var/www/html/var
52+
53+
RUN rm -rf /tmp/php/
54+
55+
ADD utils/build/docker/php/apache-mod/entrypoint.sh /
56+
WORKDIR /binaries
57+
ENTRYPOINT []
58+
RUN echo "#!/bin/bash\ndumb-init /entrypoint.sh" > app.sh
59+
RUN chmod +x app.sh
60+
CMD [ "./app.sh" ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<IfModule mod_php%PHP_MAJOR_VERSION.c>
2+
<VirtualHost *:7777>
3+
DocumentRoot /var/www/html/public
4+
AllowEncodedSlashes NoDecode
5+
<Directory /var/www/html/public>
6+
AllowOverride All
7+
Require all granted
8+
</Directory>
9+
</VirtualHost>
10+
<FilesMatch "\.php$">
11+
SetHandler application/x-httpd-php
12+
Require all granted
13+
</FilesMatch>
14+
PHPIniDir "/etc/php/php.ini"
15+
</IfModule>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "weblog/acme",
3+
"description": "Just a package to test the composer libraries are sent",
4+
"type": "library",
5+
"require": {},
6+
"version": "1.0.0",
7+
"autoload": {
8+
"psr-4": {
9+
"Acme\\": "src/"
10+
}
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Acme;
4+
5+
class Acme {
6+
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
8+
require dirname(__DIR__).'/vendor/autoload.php';
9+
10+
$input = new ArgvInput();
11+
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'prod', true);
12+
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
13+
14+
$kernel = new Kernel($env, $debug);
15+
$app = new Application($kernel);
16+
$app->run($input);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$dbPath = getenv('SYMFONY_DB_PATH') ?: '/tmp/symfony.db';
4+
$db = new PDO("sqlite:$dbPath");
5+
$db->exec('CREATE TABLE IF NOT EXISTS users (id VARCHAR(255) PRIMARY KEY, username VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(255))');
6+
7+
$hash1 = password_hash('1234', PASSWORD_BCRYPT);
8+
$db->exec("INSERT OR IGNORE INTO users (id, username, password, name) VALUES ('social-security-id', 'test', '$hash1', 'test')");
9+
10+
$hash2 = password_hash('1234', PASSWORD_BCRYPT);
11+
$db->exec("INSERT OR IGNORE INTO users (id, username, password, name) VALUES ('591dc126-8431-4d0f-9509-b23318d3dce4', 'testuuid', '$hash2', 'testuuid')");
12+
13+
echo "Database initialized at $dbPath\n";
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "php/symfony-weblog",
3+
"type": "project",
4+
"require": {
5+
"php": ">=8.2",
6+
"ext-ctype": "*",
7+
"ext-iconv": "*",
8+
"stripe/stripe-php": "^10.0",
9+
"symfony/console": "^7.2",
10+
"symfony/framework-bundle": "^7.2",
11+
"symfony/security-bundle": "^7.2",
12+
"symfony/process": "^7.2",
13+
"symfony/yaml": "^7.2",
14+
"weblog/acme": "*"
15+
},
16+
"repositories": [
17+
{
18+
"type": "path",
19+
"url": "./Acme",
20+
"options": {
21+
"symlink": true
22+
}
23+
}
24+
],
25+
"autoload": {
26+
"psr-4": {
27+
"App\\": "src/"
28+
}
29+
},
30+
"config": {
31+
"optimize-autoloader": true,
32+
"preferred-install": "dist",
33+
"sort-packages": true,
34+
"allow-plugins": {
35+
"symfony/flex": false
36+
},
37+
"platform": {
38+
"ext-ctype": "8.2.0",
39+
"ext-iconv": "8.2.0",
40+
"ext-curl": "8.2.0",
41+
"ext-json": "8.2.0",
42+
"ext-mbstring": "8.2.0",
43+
"ext-openssl": "8.2.0",
44+
"ext-pdo": "8.2.0",
45+
"ext-session": "8.2.0",
46+
"ext-tokenizer": "8.2.0",
47+
"ext-xml": "8.2.0"
48+
}
49+
},
50+
"minimum-stability": "stable",
51+
"prefer-stable": true
52+
}

0 commit comments

Comments
 (0)