-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New example of IP blocking #213
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0877c3b
Merge pull request #15 from akamai/master
hikaneko 542b5d1
New example of IP blocking
hikaneko fc81a10
Merge pull request #16 from hikaneko/hikaneko-patch-1
hikaneko 7c47f9f
Update main.js
hikaneko b78d687
Update README.md
hikaneko 591f9bd
Delete edgecompute/examples/traffic-filtering/block-based-on-ip/prope…
hikaneko ea945a7
Delete edgecompute/examples/traffic-filtering/block-based-on-ip/setva…
hikaneko ace7f15
Update main.js
hikaneko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
edgecompute/examples/traffic-filtering/block-based-on-ip/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# block-based-on-ip | ||
|
||
*Keyword(s):* constructed-response, edge logic, blocklist, allow list<br> | ||
*[Since](https://techdocs.akamai.com/edgeworkers/docs/about-the-javascript-api):* 1.0 | ||
|
||
This example implements a block list depending on ip addresses. If a user's IP address is on the list, a 403 deny will occur. | ||
|
||
## Usage Examples | ||
```` | ||
// Incoming Request | ||
GET / HTTP/1.1 | ||
Host: www.example.com | ||
(User's IP in a list) | ||
|
||
// Response to Browser | ||
HTTP/1.1 403 Forbidden | ||
{} | ||
```` | ||
## Property Variable | ||
To enable EdgeWorker to get a user's IP address, the Set Variable behavior must be configured in Property Manager. | ||
![Property Variable](propertyvariable.png) | ||
![Set Variable](setvariable.png) | ||
|
||
## Similar Uses | ||
Allowlist or blocklist capabilities can be setup based on other end user request context information such as connecting IP, Geo, Device Characteristics, Accept-Language, User-Agent, etc. | ||
|
||
## Resources | ||
See the repo [README](https://github.com/akamai/edgeworkers-examples#Resources) for additional guidance. |
4 changes: 4 additions & 0 deletions
4
edgecompute/examples/traffic-filtering/block-based-on-ip/bundle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"edgeworker-version": "0.1", | ||
"description" : "Deny based on ip list" | ||
} |
4 changes: 4 additions & 0 deletions
4
edgecompute/examples/traffic-filtering/block-based-on-ip/ipList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const blockedIPs = [ | ||
'1.2.3.4', | ||
'5.6.7.8' | ||
]; |
14 changes: 14 additions & 0 deletions
14
edgecompute/examples/traffic-filtering/block-based-on-ip/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { blockedIPs } from './ipList.js'; | ||
|
||
export async function onClientRequest(request) { | ||
const clientIP = request.getVariable('PMUSER_IP'); | ||
|
||
if (blockedIPs.includes(clientIP)) { | ||
request.respondWith( | ||
403, | ||
{ 'Content-Type': ['application/json;charset=utf-8'] }, | ||
'{}', | ||
'Denied Response' | ||
); | ||
} | ||
} |
Binary file added
BIN
+16.6 KB
edgecompute/examples/traffic-filtering/block-based-on-ip/propertyvariable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.7 KB
edgecompute/examples/traffic-filtering/block-based-on-ip/setvariable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using the new request.clientIp property instead of the PM variable. It will be easier to set up.