Skip to content

Integrate Semgrep for static analysis (SAST)#121

Closed
connorcarpenter15 wants to merge 59 commits into
mainfrom
feature/semgrep
Closed

Integrate Semgrep for static analysis (SAST)#121
connorcarpenter15 wants to merge 59 commits into
mainfrom
feature/semgrep

Conversation

@connorcarpenter15

Copy link
Copy Markdown

Summary

This PR integrates Semgrep into the project on a dedicated testing branch named for the tool and documents installation, run artifacts, and an assessment of the tool.


1. Evidence of successful installation (trackable file changes)

The following files were added or modified to install and configure Semgrep:

Change File Purpose
Added requirements-semgrep.txt Python dependency list for Semgrep; install with pip install -r requirements-semgrep.txt.
Added .semgrepignore Ignore patterns (e.g. node_modules/, vendor/, build/, public/language/, *.min.js) so the scan focuses on project code.
Modified package.json New NPM script: "semgrep": "semgrep scan --config auto" so the tool can be run via npm run semgrep after Semgrep is installed (Python/pip).

Note: Semgrep is distributed as a Python package, not an NPM package. No new NPM packages were added; the script assumes semgrep is on PATH after installing from requirements-semgrep.txt.


2. Artifacts demonstrating successful run

The following artifacts show that Semgrep was run successfully on this repository:

  • semgrep-output.txt — Full human-readable report (1,868 lines) from semgrep scan --config auto, including all findings with file paths, line numbers, rule IDs, and messages.
  • semgrep-output.json — Machine-readable JSON output of the same run (e.g. for CI or tooling).

Summary from the run:

  • Findings: 188 (all blocking under the default config)
  • Rules run: 305 (from community “auto” config)
  • Targets scanned: 1,549 files (tracked by git)
  • Skipped: 4,197 files matching .semgrepignore (e.g. node_modules/, public/language/)

3. Assessment: pros, cons, and customization

3.1 Customization

A priori (before use):

  • Installation: One-time install via pip install -r requirements-semgrep.txt. No NPM packages; the only project change is the semgrep script in package.json and the config/ignore files above.
  • Config: We use --config auto, which pulls the community rule set. No custom rules were written for this test.
  • Scope: .semgrepignore was added to exclude node_modules/, vendor/, build/, public/language/, coverage/, .nyc_output/, and *.min.js, reducing noise and scan time.

Over time:

  • Tuning: Rules can be disabled or customized in a local config (e.g. .semgrep.yml) or by choosing a subset of rule IDs. Severity and blocking behavior can be adjusted.
  • CI: The same command can be run in CI; exit code is non-zero when there are blocking findings, so the pipeline can fail on new issues.
  • Custom rules: Semgrep supports custom rules (e.g. for project-specific patterns); we did not add any for this evaluation.

3.2 Strengths (with evidence)

  • Multi-language and broad coverage: The run applied 305 rules across JS, YAML, JSON, Dockerfile, bash, HTML, etc. (e.g. 864 JS files, 309 YAML). One tool covers many surfaces.
  • Actionable, linked guidance: Each finding includes a short message and a “Details” link (e.g. https://sg.run/...) to documentation and remediation.
  • Structured output: JSON output includes CWE/OWASP metadata, severity, and line/column ranges, which supports automation and reporting.
  • Low integration cost: No new NPM deps; a single script and an ignore file are enough to run it locally or in CI.
  • Useful infra/security checks: It flagged real configuration issues (e.g. Docker Compose services without no-new-privileges or with writable root filesystem) and common app-security patterns (e.g. path traversal, regex injection, prototype pollution, session/cookie settings).

Quantitative:

  • 188 findings in one run; many are in a small set of files (e.g. path-traversal and regex rules account for a large share), which helps prioritize.
  • Severity mix in this run: 174 WARNING, 12 ERROR, 2 INFO (from JSON summary).
  • Top rule by count: path-join-resolve-traversal (113); others include detect-non-literal-regexp (17), express-path-join-resolve-traversal (8), prototype-pollution-loop (7).

3.3 Weaknesses (with evidence)

  • False positives and noise: Several rules are conservative. For example, many path.join/path.resolve usages are flagged as possible path traversal even when inputs are constrained (e.g. internal config or fixed segments). Tuning or disabling rules per file/pattern will be needed for a clean baseline.
  • No NPM integration: Semgrep is Python-based, so teams that only use Node/npm must install Python and run pip install -r requirements-semgrep.txt. There is no npm install-only story.
  • Blocking-by-default: With --config auto, 188 blocking findings may be too strict for an initial rollout; teams may want to start with a smaller rule set or non-blocking severity and then tighten over time.
  • Limited project-specific context: Rules are generic (e.g. “ensure CSRF middleware”); they don’t know this app’s actual CSRF setup. Some findings (e.g. in install/web.js) may not apply to production code paths.

Quantitative:

  • 113 of 188 findings are from a single rule family (path-join-resolve-traversal), which can dominate the report and require bulk review or rule customization.
  • 4,197 files were skipped via .semgrepignore; without that, the run would be slower and noisier.

3.4 Conclusion

Semgrep is a strong fit for broad, multi-language static analysis with minimal setup. For this repo, it quickly surfaced infrastructure and application-security issues and produced both human- and machine-readable artifacts. The main follow-up work is to reduce noise (e.g. by adjusting or disabling rules and refining .semgrepignore) and to integrate the command into CI with a policy for which findings are blocking.

connorcarpenter15 and others added 30 commits February 2, 2026 17:51
Store the forwarded message ID when adding new messages to the database.
Update the API endpoints in `src/messaging/data.js` to properly add
forwarded messages to message objects when returning data to the
frontend.

Also, update OpenAPI schemas to reflect forwarded message additions.
…riting part into the db, and reading forwarded message from db is also available. Partially modified the front-end.
Added pop up that displays the chats you can forward the current message to, when the user is hovering over a message.
feat(backend): add forwarded messages
Add the forward button based on the updates from Varidhi.
Update the message view to incorporate a forwarded message view if the
forwarded message attribute is populated.
Fix the scope of the forwardMid test to properly call the API.
Add forward messaging feature. Users can now forward an message in the chats from one room to another by clicking a button next to reply.
Fix lint and error  message attempt 2
Allow registered users to save custom color theme preferences via the
existing settings API (`PUT /api/v3/users/:uid/settings`). Seven new
fields are stored in the user:{uid}:settings hash:

  - `customThemeColor_headerBg` / `customThemeColor_headerText`
  - `customThemeColor_bodyBg` / `customThemeColor_bodyText`
  - `customThemeColor_linkColor`
  - `customThemeColor_buttonBg` / `customThemeColor_buttonText`

Values are validated as 6-digit hex colors (`#RRGGBB`) on save and
HTML-escaped via `validator.escape()` on read to prevent XSS. Empty
strings are accepted to clear a color.

No new routes, controllers, or database keys — the implementation
follows the existing bootswatchSkin pattern in `src/user/settings.js`.

Tests: 4 new cases covering valid save, invalid rejection, empty
values, and XSS sanitization.
Added a custom skin option in the settings and added a color picker.
- Add reactions.js with addReaction, removeReaction, toggleReaction, getReactions, and deleteReactions
- Register reactions module in messaging index
Endpoints for message reactions feature. (Issue 2)
- GET /:roomId/messages/:mid/reactions
- POST /:roomId/messages/:mid/reactions
Issue 3:
Include reactions in message payload
Issue 4:
Broadcast full reactions array to room on add/remove
connorcarpenter15 and others added 29 commits February 23, 2026 11:36
Update the CI test workflow to run on dev branches.
Custom Color Theme: Backend Implementation
Update the OpenAPI SettingsObj schema to properly store new custom
colortheme parameters.
Custom Skin Color Picker: Frontend Implementation
- Replace 2-field (customPrimaryColor/customSecondaryColor) frontend
  with the 7-field backend model (customThemeColor_headerBg,
  headerText, bodyBg, bodyText, linkColor, buttonBg, buttonText)
- Add 7 color picker pairs to settings.tpl with reset button
- Rewrite applyCustomColors() to map each field to correct CSS
  targets (body bg/text via root vars, sidebar/brand via selectors)
- Update header.tpl FOUC prevention script to use 7-field model
- Target harmony theme elements (.sidebar-left, .sidebar-right,
  .brand-container) instead of non-existent .navbar
- Update api.js to pass all 7 fields to client config
- Remove unused customPrimaryColor/customSecondaryColor from backend
  settings.js and OpenAPI schemas
- Add translation keys to en-GB/user.json (was only in en-US)
- Fix no-bitwise lint warnings in shadeColor helper
- Fix indentation in render.js
Custom Color Theme: Full-Stack Implementation (#10)
feat(chat): implement frontend reaction system for chat messages

- Add initReactionHandlers to handle reaction button clicks
- Integrate emoji-dialog picker for selecting reactions
- Implement toggleReaction API call to backend
- Add click handler for existing reaction pills (toggle behavior)

feat(chat): handle real-time reaction updates via socket event

- Add socket listener for event:chats.reaction
- Implement onReactionUpdate to dynamically re-render reaction pills
- Preserve reaction add button while refreshing reaction list
- Re-parse emojis using app.parseAndTranslate
- Render reaction pills with emoji and count
- Highlight reactions made by current user
- Add reaction-add button for emoji picker integration
- Add chat-reactions layout and pill design
- Style emoji and count display
- Add active state for user reactions
- Add hover interactions for pills and add button
- Hide reaction-add button until message hover
feat(chat): implement frontend reactions system
Message-Reactions: Full-Stack Implementation

All CI test cases passed.
Add user documentation covering usage instructions, user testing steps,
and automated test locations for the three sprint features: message
forwarding, message reactions, and custom color scheme.
Add UserGuide.md for sprint features
Update the Docker Compose file to give NodeBB root user privileges for
deploying on the VM.
chore: Grant root privileges to NodeBB Docker service
Add a `vm_deploy.yml` file to set up a GitHub workflow for deploying to
the VM.
Add semgrep, an AI-assisted SAST tool to provide static analysis for the
repository. Run semgrep on the codebase and save the output to both a
JSON and txt file.
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.

5 participants