generated from MeasureAuthoringTool/madie-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from MeasureAuthoringTool/MAT-7204
MAT-7204: Add WAF Intercept
- Loading branch information
Showing
4 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios from "axios"; | ||
import DOMPurify from "dompurify"; | ||
|
||
const wafIntercept = () => | ||
axios.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
// Check for WAF block | ||
if ( | ||
error?.response?.status === 403 && | ||
error?.response?.headers["content-type"].includes("text/html") && | ||
JSON.stringify(error.response.data).includes("[email protected]") | ||
) { | ||
// eslint-disable-next-line no-console | ||
console.log("WAF Interceptor Triggered"); | ||
|
||
const supportID = error.response.data.includes("ID:") | ||
? error.response.data.split("ID:")[1].split("<br>")[0].trim() | ||
: ""; | ||
const body = error.response.data.split("<body>")[1].split("<br>")[0]; | ||
const purifiedBody = DOMPurify.sanitize(body, { ALLOWED_TAGS: [] }); | ||
|
||
const wafEvent = new CustomEvent("wafReject", { | ||
detail: { message: purifiedBody, supportId: supportID }, | ||
}); | ||
document.dispatchEvent(wafEvent); | ||
throw new Error(purifiedBody); // no tags allowed, removes all HTML tags. | ||
} | ||
|
||
return Promise.reject(error); | ||
} | ||
); | ||
export default wafIntercept; |