PHPackages                             voku/anti-xss-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. voku/anti-xss-twig

ActiveLibrary[Templating &amp; Views](/categories/templating)

voku/anti-xss-twig
==================

Twig extension for XSS protection.

3.0.1(7y ago)116.1k1[4 PRs](https://github.com/voku/anti-xss-twig/pulls)MITPHPPHP &gt;=7.0.0

Since Mar 22Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/voku/anti-xss-twig)[ Packagist](https://packagist.org/packages/voku/anti-xss-twig)[ RSS](/packages/voku-anti-xss-twig/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (11)Used By (0)

[![Build Status](https://camo.githubusercontent.com/e7c39c91e65747f88e792199a61906a720da9009462afd8c8850a3b26a7dd60b/68747470733a2f2f7472617669732d63692e6f72672f766f6b752f616e74692d7873732d747769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/voku/anti-xss-twig)[![Coverage Status](https://camo.githubusercontent.com/1f45103fd3d7a08b2edb4860143c201a3a5534cbcd59a0a47f67b216bd133d00/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f766f6b752f616e74692d7873732d747769672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/voku/anti-xss-twig?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a8b7bc30493975f45b517b0720973e03a7bb223c3af1304360562b883e639dcf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766f6b752f616e74692d7873732d747769672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/voku/anti-xss-twig/?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/28939560f4980fef34b099e133ccff80d5dcf92ddd04be959d285537f32d956b/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6336653532313364326663303432316661303932336339393262363033356331)](https://www.codacy.com/app/voku/anti-xss-twig?utm_source=github.com&utm_medium=referral&utm_content=voku/anti-xss-twig&utm_campaign=Badge_Grade)[![SensioLabsInsight](https://camo.githubusercontent.com/76f4d4e88cbf849c693e0f96287326cb9bb195cfbcd9fc07d878e9892312d99e/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37383431666438372d656133652d346365322d396265382d6530313030666263316332352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/7841fd87-ea3e-4ce2-9be8-e0100fbc1c25)[![Latest Stable Version](https://camo.githubusercontent.com/a219aa6d80dc38b3c097aff84648dc17df1e6ff55e9d94ccade51e89d5c65d27/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f616e74692d7873732d747769672f762f737461626c65)](https://packagist.org/packages/voku/anti-xss-twig)[![Total Downloads](https://camo.githubusercontent.com/cea4f2ccc972cc2e0453d4ec67097f6fcea8cf076920d45e8cdcb43411230f05/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f616e74692d7873732d747769672f646f776e6c6f616473)](https://packagist.org/packages/voku/anti-xss-twig)[![Latest Unstable Version](https://camo.githubusercontent.com/3fea177d9716c436c9a869c427193d4d8edb2c6422c44c277a7bd6879c2a1fb2/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f616e74692d7873732d747769672f762f756e737461626c65)](https://packagist.org/packages/voku/anti-xss-twig)[![License](https://camo.githubusercontent.com/1771d250123988740ce036a8331cfbc254be76f266c987d1d1e143130f5335d6/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f616e74692d7873732d747769672f6c6963656e7365)](https://packagist.org/packages/voku/anti-xss-twig)

AntiXSS for Twig
================

[](#antixss-for-twig)

Description
-----------

[](#description)

A [Twig](http://twig.sensiolabs.org/) extension for [voku/anti-xss](https://github.com/voku/anti-xss).

Currently supported Twig features are:

- Tag (*recommended*)

    - `{% xss_clean %} bar {% end_xss_clean %}`
- Function

    - `{{ xss_clean(' bar') }}`
- Filter

    - `{{ 'bar' | xss_clean }}`
- [Installation](#installation)
- [Usage](#usage)
- [History](#history)

Installation
------------

[](#installation)

1. Install and use [composer](https://getcomposer.org/doc/00-intro.md) in your project.
2. Require this package via composer:

```
composer require voku/anti-xss-twig
```

Usage
-----

[](#usage)

First register the extension with Twig:

```
use voku\helper\AntiXSS;
use voku\twig\AntiXssExtension;

$twig = new Twig_Environment($loader);
$antiXss = new AntiXSS();
$twig->addExtension(new AntiXssExtension($antiXss));
```

Then use it in your templates:

```
{% xss_clean %} bar {% end_xss_clean %}

```

```
$twig->addExtension(new AntiXssExtension($antiXss));
```

History
-------

[](#history)

See [CHANGELOG](CHANGELOG.md) for the full history of changes.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance61

Regular maintenance activity

Popularity27

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~146 days

Total

5

Last Release

2802d ago

Major Versions

1.0.0 → 2.0.02017-11-19

2.0.1 → 3.0.02017-12-23

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6456fe693db197c458272cb758bf78958bc7d3e787ccd59db4bf3cf41654316a?d=identicon)[voku](/maintainers/voku)

---

Top Contributors

[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (15 commits)")

---

Tags

hacktoberfesthtmlphpphp7securityxsstwigsecurityhtmlextensionxss

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/voku-anti-xss-twig/health.svg)

```
[![Health](https://phpackages.com/badges/voku-anti-xss-twig/health.svg)](https://phpackages.com/packages/voku-anti-xss-twig)
```

###  Alternatives

[latte/latte

☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites. Introduces context-sensitive escaping.

1.3k16.0M750](/packages/latte-latte)[twig/string-extra

A Twig extension for Symfony String

22149.2M204](/packages/twig-string-extra)[twig/markdown-extra

A Twig extension for Markdown

12115.5M117](/packages/twig-markdown-extra)[symfony/ux-twig-component

Twig components for Symfony

22017.2M313](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1636.5M115](/packages/symfony-ux-live-component)[twig/html-extra

A Twig extension for HTML

788.8M70](/packages/twig-html-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
