Skip to content

Aditya - Job descriptions: sanitize HTML before saving - #2344

Draft
AdiDubbs wants to merge 1 commit into
developmentfrom
Aditya_fix_job_description_sanitization
Draft

Aditya - Job descriptions: sanitize HTML before saving#2344
AdiDubbs wants to merge 1 commit into
developmentfrom
Aditya_fix_job_description_sanitization

Conversation

@AdiDubbs

@AdiDubbs AdiDubbs commented Sep 12, 2026

Copy link
Copy Markdown

Description

Existing job descriptions were cleaned in the database, but createJob and updateJob still accepted unsanitized HTML. New or edited postings could therefore reintroduce raw tags or unsafe markup into summaries. This stores descriptions as readable plain text at both write paths.

This issue concerns Item 40.

Original task

Job descriptions — sanitize HTML before saving through both the job-creation and job-update APIs.

Open master Google Doc Item 40

Master Google Doc task entry

Master Google Doc - Item 40 job description sanitization

Related PRS (if any):

No frontend changes. The existing Collaboration summary cleanup remains unchanged.

Main changes explained:

  1. Adds a reusable stripHtml utility built on the repository’s existing sanitize-html and cheerio dependencies.
  2. Removes markup and script content while preserving readable block and list boundaries.
  3. Decodes safe HTML entities back to readable text.
  4. Applies the utility to string descriptions in both createJob and updateJob.
  5. Preserves non-string values so the existing controller validation behavior is not broadened.
  6. Adds focused create, update, block-boundary, script-removal, entity, plain-text, and empty-value tests.

How to test:

  1. Check out this branch and install dependencies.
  2. Create a job whose description contains paragraphs, emphasis, list items, entities, and a script tag.
  3. Confirm the stored description contains readable plain text, preserves sensible line breaks, decodes entities, and contains no tag or script content.
  4. Update an existing job with the same cases and confirm identical sanitization.
  5. Confirm a plain-text description remains unchanged.
  6. Run jest src/controllers/jobsController.test.js src/utilities/__tests__/htmlContentSanitizer.test.js --runInBand.
  7. Run npm run build.

Automated verification evidence:

This is a backend data-sanitization change with no standalone visual state. The live PR checks passed:

Note:

The focused controller and sanitizer suites pass 45 tests on current development.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant