Server-side sanitization and using custom tags and attributes in responses
Server-side sanitization is applied to the alt.html and alt.markdown Q&A response fields to prevent stored cross-site scripting (XSS) attacks. QnABot on AWS uses the sanitize-html
For more information on default allowed HTML tags and attributes, see the default options
-
<img>,<details>, and<summary>tags -
The
styleattribute on<p>elements (restricted towhite-space: pre-line) -
The
translateattribute on<span>elements
Important
Any tags or attributes not in the allowlist will be removed from Q&A responses. If your responses use custom HTML tags or attributes, you must add them to the allowlist in source/bin/sanitizeAllowlist.js.
Instructions for adding custom tags/attributes to the allowlist
QnABot on AWS maintains a single, canonical allowlist configuration file, source/bin/sanitizeAllowlist.js. A build-time script automatically generates two runtime copies from this single file: one for the Fulfillment Lambda (source/lambda/es-proxy-layer/lib/sanitizeOutput.js) and one for the Content Designer (source/website/js/components/designer/sanitizeOutput.js). Both copies stay in sync. Do not edit the generated sanitizeOutput.js files directly—they are overwritten on every build. For more information, see source/bin/README.md
To add custom tags or attributes to the sanitization allowlist:
-
Download the latest QnABot on AWS source code (v7.4.4 or later) from the GitHub repository (https://github.com/aws-solutions/qnabot-on-aws).
-
Open
source/bin/sanitizeAllowlist.jsin the QnABot source code. -
Add your custom tags to
extraAllowedTags:extraAllowedTags: [ 'question', 'references', 'chatHistory', 'followUpMessage', 'details', 'summary', 'img', 'custom-tag', // add your custom tags here ], -
Add custom attributes to
extraAllowedAttributesif needed:extraAllowedAttributes: { a: ['href'], p: ['style'], span: ['translate', 'style'], 'custom-tag': ['src', 'width', 'height'], // add your custom attributes here }, -
Rebuild and redeploy the guidance following the instructions in the README
in the GitHub repository. The allowlist sync runs automatically as part of the build (for example, npm run uporupdate, orbuild-s3-dist.sh). You do not need to regenerate the twosanitizeOutput.jsfiles manually.
Important
Only add tags and attributes that you have thoroughly reviewed for security implications. Adding unsafe tags or attributes could re-introduce XSS vulnerabilities.