Skip to content

update the services details page#9

Open
Mohamedelmesery2004 wants to merge 2 commits intomainfrom
update-services-details-page
Open

update the services details page#9
Mohamedelmesery2004 wants to merge 2 commits intomainfrom
update-services-details-page

Conversation

@Mohamedelmesery2004
Copy link
Copy Markdown
Collaborator

No description provided.

@vercel
Copy link
Copy Markdown

vercel bot commented Nov 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
abwab-digital1 Ready Ready Preview Comment Nov 9, 2025 1:19pm

Comment thread models/seoSchema.js
META_TITLE_MAX: 70,
META_DESC_MAX: 160,
KEYWORD_MAX: 10,
URL_PATTERN: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w .-]*)*\/?$/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of ' '.

Copilot Autofix

AI 5 months ago

The fix is to refactor the problematic [\/\w .-]* character class to remove ambiguity that leads to excessive backtracking. In this regex, [\/\w .-]* allows for spaces, dots, dashes, slashes, and word characters (alphanumeric plus underscore). To avoid inefficient matching, it is often best to restrict the set to characters that do not overlap in meaning or combine with alternation. For URL paths, a more robust pattern is [^\s]* or [A-Za-z0-9\/_.-]*, which excludes spaces (as URLs rarely contain them) and avoids poorly performing ambiguous branches.

How to fix:

  • On line 8 (SEO_CONSTRAINTS.URL_PATTERN), replace [\/\w .-]* with [A-Za-z0-9\/_.-]* or [A-Za-z0-9\/_.-]* (remove the space and combine word chars with dots and dashes explicitly).
  • This change is isolated to line 8 in models/seoSchema.js.
  • No new imports or method definitions are required.

Suggested changeset 1
models/seoSchema.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/models/seoSchema.js b/models/seoSchema.js
--- a/models/seoSchema.js
+++ b/models/seoSchema.js
@@ -5,7 +5,7 @@
   META_TITLE_MAX: 70,
   META_DESC_MAX: 160,
   KEYWORD_MAX: 10,
-  URL_PATTERN: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w .-]*)*\/?$/
+  URL_PATTERN: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([A-Za-z0-9\/_.-]*)*\/?$/
 };
 
 const SocialMediaSchema = new mongoose.Schema({
EOF
@@ -5,7 +5,7 @@
META_TITLE_MAX: 70,
META_DESC_MAX: 160,
KEYWORD_MAX: 10,
URL_PATTERN: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([\/\w .-]*)*\/?$/
URL_PATTERN: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([A-Za-z0-9\/_.-]*)*\/?$/
};

const SocialMediaSchema = new mongoose.Schema({
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread routes/seo.js
router.get('/services/:id/structured-data', getStructuredData);

// Protected routes (require authentication and admin role)
router.use(protect);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.

Copilot Autofix

AI 5 months ago

To fix the problem, we should add a rate limiting middleware to the routes that require protection, particularly on the sensitive PUT operation. The industry-standard solution is to use the express-rate-limit package, which can be installed as a dependency. The best way to implement this without changing existing functionality is to import (require) express-rate-limit, define a suitable rate limiter (for example, allow a maximum number of requests per user within a time window), and apply it to the sensitive route(s).

Specifically:

  • Add const rateLimit = require('express-rate-limit'); at the top of the file.
  • Define a limiter (e.g., 100 requests per 15 minutes).
  • Apply the limiter to the router.put('/services/:id/seo', ...) route, right before the validation/auth handlers.
  • The rest of the router code remains unchanged.

Suggested changeset 1
routes/seo.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/routes/seo.js b/routes/seo.js
--- a/routes/seo.js
+++ b/routes/seo.js
@@ -1,9 +1,18 @@
 const express = require('express');
 const router = express.Router();
+const rateLimit = require('express-rate-limit');
 const { updateSeo, getSeo, getStructuredData } = require('../controllers/seoController');
 const validateSeoData = require('../middleware/seoValidator');
 const { protect, authorize } = require('../middleware/auth');
 
+// Define rate limiter for protected routes
+const limiter = rateLimit({
+  windowMs: 15 * 60 * 1000, // 15 minutes
+  max: 100, // limit each IP to 100 requests per windowMs
+  standardHeaders: true,
+  legacyHeaders: false,
+});
+
 // Public routes
 router.get('/services/:id/seo', getSeo);
 router.get('/services/:id/structured-data', getStructuredData);
@@ -11,6 +16,6 @@
 // Protected routes (require authentication and admin role)
 router.use(protect);
 
-router.put('/services/:id/seo', validateSeoData, updateSeo);
+router.put('/services/:id/seo', limiter, validateSeoData, updateSeo);
 
 module.exports = router;
EOF
@@ -1,9 +1,18 @@
const express = require('express');
const router = express.Router();
const rateLimit = require('express-rate-limit');
const { updateSeo, getSeo, getStructuredData } = require('../controllers/seoController');
const validateSeoData = require('../middleware/seoValidator');
const { protect, authorize } = require('../middleware/auth');

// Define rate limiter for protected routes
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
standardHeaders: true,
legacyHeaders: false,
});

// Public routes
router.get('/services/:id/seo', getSeo);
router.get('/services/:id/structured-data', getStructuredData);
@@ -11,6 +16,6 @@
// Protected routes (require authentication and admin role)
router.use(protect);

router.put('/services/:id/seo', validateSeoData, updateSeo);
router.put('/services/:id/seo', limiter, validateSeoData, updateSeo);

module.exports = router;
Copilot is powered by AI and may make mistakes. Always verify output.
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