Skip to content

Conversation

@kostasx
Copy link
Contributor

@kostasx kostasx commented Dec 25, 2025

Potential fix for https://github.com/in-tech-gration/website/security/code-scanning/4

General fix approach

When using data derived from file names to build URL attributes, ensure that the resulting URL cannot use dangerous schemes (javascript:, data:, etc.) and cannot escape the intended path structure. The simplest way here is to sanitize or encode slug before interpolating it into the href, e.g., with encodeURIComponent, and to ensure it is treated purely as a path segment.

Best fix for this code

We only need to change how post.slug is used in components/blog-post-item.tsx. Currently:

<a href={`/blog/${post.slug}`}>

appears twice (around the image and around the title). We can avoid dangerous characters by URL-encoding the slug before interpolation:

const safeSlug = encodeURIComponent(post.slug || "");

and then:

<a href={`/blog/${safeSlug}`}>

This ensures that even if an attacker controls post.slug, characters like :, /, ", <, > etc. will be percent-encoded and cannot introduce a new scheme or break out of the attribute. encodeURIComponent is built-in in the JS runtime, so no new imports are required. Functionality is preserved from the user’s perspective as long as routes are set up consistently (which they should be if other parts of the app also treat slugs as encoded path segments).

We do not modify any other files; util/blog-utils.ts can continue to derive slug from filenames, and BlogList continues to pass posts through unchanged.

Specific changes

File: components/blog-post-item.tsx

  • Add a local safeSlug constant just after the formattedDate computation (or at the start of the component body after the null check).
  • Replace both instances of href={`/blog/${post.slug}`} with href={`/blog/${safeSlug}`}.

No new imports or helper methods are needed.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@netlify
Copy link

netlify bot commented Dec 25, 2025

Deploy Preview for intechgration-io failed.

Name Link
🔨 Latest commit b0210d2
🔍 Latest deploy log https://app.netlify.com/projects/intechgration-io/deploys/694dbe3bed7c7e0008a0158b

@kostasx kostasx marked this pull request as ready for review December 25, 2025 22:47
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.

2 participants