-
Notifications
You must be signed in to change notification settings - Fork 0
Sanitize webcontent and discussion #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| ${ | ||
| typeof page.content === "string" | ||
| ? DOMPurify.sanitize(page.content) | ||
| : page.content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would it be that it's not a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above it defaults to ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imscc-packager/src/imscc/types.ts
Line 66 in a5583dd
| content: string | Section[]; |
when it's an assessment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do those sections also have HTML?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.
const sanitizeAnswer = <T extends Answer>(answer: T) => ({
...answer,
text: sanitize(answer.text)
});
const sanitizeAnswerArray = <T extends Answer>(answers: T[] | undefined) => answers ? answers.map(sanitizeAnswer) : undefined;
const sanitizeMatches = (matches: Match[] | undefined) => matches ?
matches.map((match) => ({
pair: [sanitizeAnswer(match.pair[0]), sanitizeAnswer(match.pair[1])]
})): undefined;
const sanitize = (content: string | Section[]) => {
if (typeof content === "string") {
return DOMPurify.sanitize(content);
} else {
const sanitizedSection = content.map((section) => ({
...section,
title: sanitize(section.title),
question: sanitize(section.question),
answers: sanitizeAnswerArray(section.answers),
choices: sanitizeAnswerArray(section.choices),
matches: sanitizeMatches(section.matches)
}));
return sanitizedSection;
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: any user editable field that could possibly be reflected back to a user as HTML needs to be sanitized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do those sections also have HTML?
yes, only questions that can be in html format. currently i sanitized the question in coursemagic side because it's in escaped format, i sanitze it before escaping it. should the imscc-packger be the one that responsible for sanitizing the html?
No description provided.