Skip to content

Commit

Permalink
fix: Allow target=_blank in anchors (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Dec 6, 2023
1 parent bf8d67f commit 8ef4c63
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api.planx.uk/modules/flows/findReplace/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const findAndReplaceSchema = z.object({
replace: z
.string()
.optional()
.transform((val) => val && DOMPurify.sanitize(val)),
.transform(
(val) => val && DOMPurify.sanitize(val, { ADD_ATTR: ["target"] }),
),
}),
});

Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/ui/ReactMarkdownOrHtml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function ReactMarkdownOrHtml(props: {
<HTMLRoot
color={props.textColor}
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(incrementHeaders),
__html: DOMPurify.sanitize(incrementHeaders, { ADD_ATTR: ["target"] }),
}}
id={props.id}
/>
Expand Down
2 changes: 1 addition & 1 deletion sharedb.planx.uk/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function sanitiseOperation(op) {
*/
function sanitise(input) {
if ((input && typeof input === "string") || input instanceof String) {
return DOMPurify.sanitize(input);
return DOMPurify.sanitize(input, { ADD_ATTR: ["target"] });
} else if ((input && typeof input === "object") || input instanceof Object) {
return Object.entries(input).reduce((acc, [k, v]) => {
v = sanitise(v);
Expand Down

0 comments on commit 8ef4c63

Please sign in to comment.