🛡RisXSS
Eradicate all XSS flaws of your React or Vue application using a single ESLint rule.
How to install RisXSS ?
- First, use your favorite package manager to add eslint-plugin-risxss in your devDependencies, for example with yarn :
yarn add eslint-plugin-risxss --dev
To do so, add these lines in your eslint config, for instance if you use .eslintrc.js
config file :
If your project uses React/Javascript :
module.exports = {
env: {
browser: true,
es6: true
},
extends: 'eslint:recommended',
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['react', 'risxss'],
rules: {
'risxss/catch-potential-xss-react': 'error'
}
};
If your project uses React/TypeScript :
module.exports = {
env: {
browser: true,
es6: true
},
parser: '@typescript-eslint/parser',
extends: 'eslint:recommended',
parserOptions: {
project: './tsconfig.json',
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['risxss'],
rules: {
'risxss/catch-potential-xss-react': 'error'
}
};
If your project uses Vue.js
module.exports = {
env: {
browser: true
},
extends: ['plugin:vue/essential'],
parserOptions: {
parser: 'babel-eslint'
},
plugins: ['vue', 'risxss'],
rules: {
'risxss/catch-potential-xss-vue': 'error'
}
};
Rules
Configuring the rules
Sometimes you have your own rules to prevent XSS and you don't use DOMPurify.sanitize on your inputs. You can add your own function name to the RisXSS whitelist by passing them as options.
:warning: We still recommend using DOMPurify to sanitize your inputs :warning:
module.exports = {
env: {
browser: true
},
extends: ['plugin:vue/essential'],
parserOptions: {
parser: 'babel-eslint'
},
plugins: ['vue', 'risxss'],
rules: {
'risxss/catch-potential-xss-vue': ['error', {
trustedLibraries: ['xss']
}]
}
};
import { sanitize } from 'xss';
export const DesktopPostCard = ({ post }) => (
<div dangerouslySetInnerHTML={{ __html: sanitize(post.content) }} />
);
License
MIT