Compare commits

..

1 Commits

Author SHA1 Message Date
9cc4c7ac74 feat(altcha): add altcha validation layer to login
Some checks reported warnings
Cadoles/hydra-sql/pipeline/pr-develop This commit is unstable
2025-04-02 13:32:55 +02:00
7 changed files with 97 additions and 45 deletions

View File

@ -109,3 +109,18 @@ ex : `'redis:?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sen
| `postgres` | Base de donnée postgres support du test et pour hydra | `5432` |
| `mariadb` | Base de donnée mariadb support du test | `3306` |
| `pgadmin` | pour administrer la base de donnée | `8085` |
### Configuration d'Altcha
Altcha est activable/désactivable par un feature flag disponible à la route /flag/altcha (port 8082 par défaut).
La valeur de ce flag est stockée dans Redis (clé `altcha`) afin de pouvoir la modifier à la volée. Par sécurité, un fallback sur la variable d'environnement `ALTCHA_ENABLED` est effectué si la clé n'existe pas dans Redis.
Exemple de désactivation:
```shell
curl --request PUT \
--url http://localhost:8082/flag/altcha \
--header 'Content-Type: application/json' \
--data '{
'\''flagValue'\'': false
}'
```

View File

@ -4,20 +4,29 @@ namespace App\Flag\Controller;
use App\Flag\FlagEnum;
use Predis\ClientInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
class FlagController extends AbstractController
{
#[Route('/flag', name: 'flag_update', methods: ['PUT'])]
public function updateFlag(ClientInterface $redis, FlagEnum $flagName, bool $flagValue): Response
#[Route('/flag/{flagName}', name: 'flag_update', methods: ['PUT'])]
public function updateFlag(ClientInterface $redis, Request $request, string $flagName): Response
{
$redis->set($flagName->value, $flagValue);
try {
FlagEnum::from($flagName);
} catch (\ValueError $e) {
throw new \InvalidArgumentException('invalid flag name provided');
}
$flagValue = $request->query->getBoolean('flagValue');
$redis->set($flagName, $flagValue);
return new JsonResponse(
[\sprintf('flag %s has been %s.', $flagName->value, $flagValue ? 'enabled' : 'disabled')]
[\sprintf('flag %s has been %s.', $flagName, $flagValue ? 'enabled' : 'disabled')]
);
}
}

View File

@ -42,7 +42,6 @@ class LoginType extends AbstractType
if ($this->flagAccessor->isFlagEnabled(FlagEnum::Altcha, $this->altchaEnabled)) {
$builder->add('altcha', AltchaType::class, [
'label' => false,
'translation_domain' => 'form',
]);
};
}

View File

@ -3,7 +3,15 @@
.altcha label {
margin-bottom: 0;
}
.panel-body {
max-width: 400px;
}
</style>
<div>
<h3>
{% trans from 'form' %}altcha.widget.title{% endtrans %}
</h3>
<div class="panel-body">
<altcha-widget
challengejson={{challengeJson}}
name={{form.vars.full_name}}
@ -15,4 +23,9 @@
{{ debug ? 'debug' : ''}}
{{ mockError ? 'mockerror' : ''}}
></altcha-widget>
<div class="alert alert-info">
{% trans from 'form' %}altcha.widget.info{% endtrans %}
</div>
</div>
</div>
{% endblock %}

View File

@ -19,31 +19,39 @@
</trans-unit>
<trans-unit id="4kfMq14" resname="altcha.validator.server_validation_error">
<source>altcha.validator.server_validation_error</source>
<target xml:space="preserve">Verification failed. Try again later.</target>
<target>Verification failed. Try again later.</target>
</trans-unit>
<trans-unit id="7mZdXx_" resname="altcha.widget.error">
<source>altcha.widget.error</source>
<target xml:space="preserve">Verification failed. Try again later.</target>
<target>Verification failed. Try again later.</target>
</trans-unit>
<trans-unit id="Yg33QZt" resname="altcha.widget.expired">
<source>altcha.widget.expired</source>
<target xml:space="preserve">Verification expired. Try again.</target>
<target>Verification expired. Try again.</target>
</trans-unit>
<trans-unit id="3y0.Bhb" resname="altcha.widget.label">
<source>altcha.widget.label</source>
<target xml:space="preserve">I'm not a robot</target>
<target>I'm not a robot</target>
</trans-unit>
<trans-unit id="QFBWtGD" resname="altcha.widget.verified">
<source>altcha.widget.verified</source>
<target xml:space="preserve">Verified</target>
<target>Verified</target>
</trans-unit>
<trans-unit id="SfOrgtj" resname="altcha.widget.verifying">
<source>altcha.widget.verifying</source>
<target xml:space="preserve">Verifying...</target>
<target>Verifying...</target>
</trans-unit>
<trans-unit id="9dhbPuz" resname="altcha.widget.waitalert">
<source>altcha.widget.waitalert</source>
<target xml:space="preserve">Verifying... please wait.</target>
<target>Verifying... please wait.</target>
</trans-unit>
<trans-unit id="9k5hI.D" resname="altcha.widget.title">
<source>altcha.widget.title</source>
<target>Verification</target>
</trans-unit>
<trans-unit id="vGcy2C3" resname="altcha.widget.info">
<source>altcha.widget.info</source>
<target>Please check the box above to validate that you are not a robot. If you encounter any problem while doing this, please update your browser.</target>
</trans-unit>
</body>
</file>

View File

@ -19,31 +19,39 @@
</trans-unit>
<trans-unit id="4kfMq14" resname="altcha.validator.server_validation_error">
<source>altcha.validator.server_validation_error</source>
<target xml:space="preserve">Échec de la vérification. Réessayez plus tard.</target>
<target>Échec de la vérification. Réessayez plus tard.</target>
</trans-unit>
<trans-unit id="7mZdXx_" resname="altcha.widget.error">
<source>altcha.widget.error</source>
<target xml:space="preserve">Échec de la vérification. Réesayez plus tard.</target>
<target>Échec de la vérification. Réesayez plus tard.</target>
</trans-unit>
<trans-unit id="Yg33QZt" resname="altcha.widget.expired">
<source>altcha.widget.expired</source>
<target xml:space="preserve">Vérification expirée. Réessayez.</target>
<target>Vérification expirée. Réessayez.</target>
</trans-unit>
<trans-unit id="3y0.Bhb" resname="altcha.widget.label">
<source>altcha.widget.label</source>
<target xml:space="preserve">Je ne suis pas un robot</target>
<target>Je ne suis pas un robot</target>
</trans-unit>
<trans-unit id="QFBWtGD" resname="altcha.widget.verified">
<source>altcha.widget.verified</source>
<target xml:space="preserve">Vérifié</target>
<target>Vérifié</target>
</trans-unit>
<trans-unit id="SfOrgtj" resname="altcha.widget.verifying">
<source>altcha.widget.verifying</source>
<target xml:space="preserve">Vérification en cours...</target>
<target>Vérification en cours...</target>
</trans-unit>
<trans-unit id="9dhbPuz" resname="altcha.widget.waitalert">
<source>altcha.widget.waitalert</source>
<target xml:space="preserve">Vérification en cours... veuillez patienter.</target>
<target>Vérification en cours... veuillez patienter.</target>
</trans-unit>
<trans-unit id="9k5hI.D" resname="altcha.widget.title">
<source>altcha.widget.title</source>
<target>Vérification</target>
</trans-unit>
<trans-unit id="vGcy2C3" resname="altcha.widget.info">
<source>altcha.widget.info</source>
<target>Veuillez cocher la case ci dessus afin de valider que vous n'êtes pas un robot. Si vous rencontrez un problème lors de cette action, mettez à jour votre navigateur.</target>
</trans-unit>
</body>
</file>