Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

  • Create Netlify Edge function feed.ts in functions/ directory that:
    • Checks the request's country using Netlify's geo-location context
    • Blocks requests from China (CN) with 403 Forbidden
    • Otherwise proxies the request to serve feed.xml content
  • Configure edge function path using config export in feed.ts
  • Simplify implementation by removing unused variables
  • Revert accidental package-lock.json changes
  • Verify linting and formatting passes
Original prompt

Create a Netlify Edge function that works on /feed.xml and blocks all requests from China, otherwise allowing the content of /feed.xml to be read.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 2, 2025
@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for fr-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/fr-eslint/deploys/68dee9a22ba4e40008e8d1d0
😎 Deploy Preview https://deploy-preview-796--fr-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for hi-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/hi-eslint/deploys/68dee9a2e0ba33000835dcec
😎 Deploy Preview https://deploy-preview-796--hi-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for new-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/new-eslint/deploys/68dee9a282fbe70008dc6d47
😎 Deploy Preview https://deploy-preview-796--new-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for zh-hans-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/zh-hans-eslint/deploys/68dee9a2baef1700082613b7
😎 Deploy Preview https://deploy-preview-796--zh-hans-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for de-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/de-eslint/deploys/68dee9a2ff8b9c00087f324a
😎 Deploy Preview https://deploy-preview-796--de-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for ja-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/ja-eslint/deploys/68dee9a28381140008a208cc
😎 Deploy Preview https://deploy-preview-796--ja-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

1 similar comment
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for pt-br-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/pt-br-eslint/deploys/68dee9a282fbe70008dc6d4c
😎 Deploy Preview https://deploy-preview-796--pt-br-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Oct 2, 2025

Deploy Preview for es-eslint ready!

Name Link
🔨 Latest commit 709d5bd
🔍 Latest deploy log https://app.netlify.com/projects/es-eslint/deploys/68dee9a2e0ba33000835dce7
😎 Deploy Preview https://deploy-preview-796--es-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

2 similar comments
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

2 similar comments
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase
  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Copilot AI changed the title [WIP] Create a Netlify Edge function that works on /feed.xml and blocks all requests from China, otherwise allowing the content of /feed.xml to be read. Add Netlify Edge function to block China from accessing feed.xml Oct 2, 2025
@eslint-github-bot
Copy link

Hi @Copilot!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

Copilot AI requested a review from nzakas October 2, 2025 13:14
Copilot finished work on behalf of nzakas October 2, 2025 13:14
@nzakas nzakas changed the title Add Netlify Edge function to block China from accessing feed.xml fix: Add Netlify Edge function to block China from accessing feed.xml Oct 2, 2025
@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Oct 2, 2025
@nzakas nzakas marked this pull request as ready for review October 2, 2025 17:25
netlify.toml Outdated
function = "og"
path = "/og"

[[edge_functions]]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this with defining the path in the edge function file, e.g.

export const config = {
    path: "/feed.xml"
}

or, typed:

import type { Config } from "@netlify/edge-functions";
...
export const config: Config = {
    path: "/feed.xml"
}

but idk if you want to add the needed dependency for that one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot revert the changes in this file and insert this into the edge function file:

export const config = {
    path: "/feed.xml"
}

Copilot finished work on behalf of nzakas October 2, 2025 20:00
@nzakas
Copy link
Member

nzakas commented Oct 2, 2025

@copilot revert the changes netlify.toml and add this code to feed.ts:

export const config = {
    path: "/feed.xml"
}

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot revert the changes netlify.toml and add this code to feed.ts:

...

Done in d398cdb. The netlify.toml changes have been reverted and the path configuration is now defined using the config export in feed.ts.

Copilot finished work on behalf of nzakas October 2, 2025 20:19
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Netlify's rate limiting instead, so that all of China doesn't stay blocked until a more comprehensive solution is figured out?

@@ -0,0 +1,21 @@
export const config = {
path: "/feed.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with blocking all requests from any one region is that it also blocks that region's legitimate traffic. I imagine there are quite a few real users who would be blocked from subscribing to the feed by this. To start, we could instead rate limit the requests to make this more dynamic to spiked times & regions:

Suggested change
path: "/feed.xml"
path: "/feed.xml",
rateLimit: {
aggregateBy: ["ip", "domain"],
windowSize: 60,
windowLimit: 100,
}

https://docs.netlify.com/manage/security/secure-access-to-sites/rate-limiting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen the specific requests / their aggregations causing issues. If they're split across domain/IP and the only commonality is just "China" then this wouldn't work. At that point I'd suggest using an edge function after all, with a basic quota set up per-country. It could use Netlify Blobs as a basic key-value store.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is available on only enterprise accounts.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of yesterday this is available to all! was done as part of the AI launch...
What you don't get without enterprise is advanced rules that can apply that for China only, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha thanks.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoshuaKGoldberg I can provide more stats from our systems. We would have better observability for all customers soon enough, but meanwhile I'm glad to assist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that'd be great, yes please (and thank you for engaging+offering!). I'm mostly curious about the mentioned characteristics of the mass-requesting users: what commonalities exist between them? Do they only match on geo code / country? Is there something more granular, such as domain or IP, that we can match on?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen various IP ranges coming from data centers in China, and I don't have at the moment other "stable" markers to isolate that traffic - there's a specific user-agent string, but this can change over time as the bot in question gets updates, etc.
If I have any more tools or information at my disposal, I'll update you on this!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately: I think an ideal solution would be to cache the responses to any static endpoint/page, including the feed, at the CDN level. As in, putting the CDN in front of Netlify. I've used Cloudflare in the past to have zero-cost caching for similar situations. But if this is urgently costing the project money then ACK that it's too much work for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd then have to move all of our DNS to Cloudflare, which introduces another provider we need to keep track of and manage access to. I just don't think this is important enough for that extra overhead.

Copy link

@eladroz eladroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another suggested optimization, which doesn't block the release.

}

// For all other countries, serve the feed.xml content
return await context.next();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually remove this line -
If you just end the function (or do an early return somewhere), this also signals to Netlify to proceed with the actual content serving. Edge functions only terminate response processing if they return a Response object (like in the code above when denying access).
The explicit await context.next() is great for when you actually want to capture the response and transform it (the response headers, the body, whatever), but here it's not needed - and it carries some additional latency because when you await the content, control goes back to the edge function before returning to the client. With a simple return, this doesn't need to happen.
The impact of this added latency in this case is a non-issue, but one less line is cleaner :-) I guess we need Netlify eslint rules! 🙂

Also, I realized this behavior is not really super clear in our docs, so would fix that as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove this line.

Copilot finished work on behalf of nzakas October 2, 2025 20:56
@nzakas
Copy link
Member

nzakas commented Oct 2, 2025

@copilot revert changes to package.json

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot revert changes to package.json

Done in 2da64a3. The accidental changes to package-lock.json have been reverted.

Copilot finished work on behalf of nzakas October 2, 2025 21:00
@nzakas nzakas merged commit f29f17b into main Oct 2, 2025
35 of 37 checks passed
@nzakas nzakas deleted the copilot/fix-faa4fce6-d2bf-43fa-b0d0-4c3edd15c761 branch October 2, 2025 21:10
@github-project-automation github-project-automation bot moved this from Needs Triage to Complete in Triage Oct 2, 2025
@kecrily
Copy link
Member

kecrily commented Oct 4, 2025

If anyone notices this and wants to know why, you can check out https://x.com/geteslint/status/1973732635676684540

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

Labels

bug Something isn't working

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

5 participants