Back to the LMS journey

BrokeStop 4 of 15

Cleaning unsafe code out of formatted text without losing tables, lists and headings

The LMS cleans unsafe code out of formatted text when it is saved. But older announcements and newsletters were shown without that cleaning. Now the cleaner also runs when they are shown, and tables, lists and headings stay.

What went wrong

Announcements and newsletters in the LMS hold formatted text. It is saved as A technical wordHTMLThe code that describes what is on a web page., the code that tells a browser how to lay out a page. When one is saved in the editor, a LMS · The platformContent safetyFormatted text is cleaned of unsafe code when it is saved, and again when it is shown. Uploaded files are renamed, restricted and re-encoded into fresh copies.See it in the LMS build runs over the HTML and removes anything unsafe. A security review found a way round that step. The pages that show announcements and newsletters used the saved text directly. So older or imported text that never went through the editor’s cleaner could get through unchecked. It could reach the LMS · The platformLesson player and progressThe server decides how much of a lesson counts as done. It uses how long a video played and how long each page was open.See it in the LMS build, the editor preview or an email.

What made it hard

Removing all markup before showing the text would also remove useful layout. Course material uses tables, lists and headings. So the cleaner works from rules about which markup and styles are allowed. It removes event handlers, which are bits of markup that run a script. It checks what kind of web address each link and image uses. It also limits the styling rules. If it can’t read the HTML, it gives back the text with every symbol made harmless, so it shows as plain characters.

What I changed

I added the same cleaner to the pages that show announcements and newsletters. Saved text is now cleaned when it is shown, not only when it is saved. So older and imported content gets the same check as new content.

How I know it works

The tests recreate the older-content case. They put harmful HTML straight into storage, skipping the editor. Then they check what comes out. The useful text has to stay. Script markers, event handlers and web addresses that run scripts have to disappear. The May report shows the content checks and the cleaner checks passing.