# xml-parser-xxe

Rule `sonarjs/xml-parser-xxe`. XML parsers should not be vulnerable to XXE attacks

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1388 by reach, #689 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/xml-parser-xxe` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2755/) |

## Code examples

### Incorrect: the rule reports this

```js
const libxmljs = require("libxmljs");
var fs = require('fs');

var xml = fs.readFileSync('xxe.xml', 'utf8');

var xmlDoc = libxmljs.parseXmlString(xml, { noblanks: true, noent: true, nocdata: true }); // Noncompliant: noent set to true
```

### Correct: the rule accepts this

```js
const libxmljs = require("libxmljs");
var fs = require('fs');

var xml = fs.readFileSync('xxe.xml', 'utf8');

var xmlDoc = libxmljs.parseXmlString(xml); // Compliant: noent set to false by default
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/xml-parser-xxe": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/x-powered-by](https://lintradar.dev/rules/sonarjs/x-powered-by.md): Web application technologies should not disclose version information
- [sonarjs/weak-ssl](https://lintradar.dev/rules/sonarjs/weak-ssl.md): Weak SSL/TLS protocols should not be used
- [sonarjs/void-use](https://lintradar.dev/rules/sonarjs/void-use.md): "void" should not be used
- [sonarjs/vitest-mock-at-module-scope](https://lintradar.dev/rules/sonarjs/vitest-mock-at-module-scope.md): Vi.mock should be declared at module scope
- [sonarjs/use-type-alias](https://lintradar.dev/rules/sonarjs/use-type-alias.md): Type aliases should be used
- [sonarjs/updated-loop-counter](https://lintradar.dev/rules/sonarjs/updated-loop-counter.md): Loop counters should not be assigned within the loop body

---

Web page: https://lintradar.dev/rules/sonarjs/xml-parser-xxe. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
