Skip to content

Commit

Permalink
ip whitelist commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cthompson committed Feb 14, 2023
1 parent 97c879c commit a87dbc0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
yarn-error.log
bored-agent.yaml
22 changes: 22 additions & 0 deletions src/stream-impersonator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ export class StreamImpersonator extends Transform {
super();

this.httpParser = new HTTPParser("REQUEST");
const whitelist = process.env.IP_WHITELIST;

let ipArray:string[] = []


if(whitelist !== undefined && whitelist !== "")
{
ipArray = whitelist.split(',');
}

this.httpParser.onHeadersComplete = (info) => {
if (this.upgrade) {
Expand All @@ -42,6 +51,19 @@ export class StreamImpersonator extends Transform {
let token: string | null = null;
const authIndex = headers.findIndex((h) => h[0] === "authorization");

const ipIndex = headers.findIndex((h) => h[0] === "x-forwarded-for");
const ip = headers[ipIndex][1].trim();

//If not coming from an acceptable IP, reject
if(ipArray.length > 0 && ipArray.includes(ip) === false)
{
logger.info('[AUDIT] ip address ' + ip + ' NOT found in whitelist');
this.flushChunks();
}
else{
logger.info('[AUDIT] ip address ' + ip + ' found in whitelist');
}

if (authIndex !== -1) {
token = headers[authIndex][1].trim().replace("Bearer ", "");

Expand Down

0 comments on commit a87dbc0

Please sign in to comment.