-
Notifications
You must be signed in to change notification settings - Fork 0
[INTER-726] Fix invalid host header #225
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2964a9d
test: use front door for mock tests
TheUnderScorer 3a8a62d
build: update lockfile
TheUnderScorer 341094f
fix: provide correct fpjs-proxy-forwarded-host header when using fron…
TheUnderScorer 4e0db7b
fix: use x-azure-socketip first for resolving client ip
TheUnderScorer 0ccf5a2
fix: strip port from client ip
TheUnderScorer cfdec37
chore: strip port from ipv6 as well
TheUnderScorer d5874ee
chore: use x-azure-socketip instead
TheUnderScorer 7f818ca
fix: rely only on non-spoofable `x-azure-socketip` for resolving clie…
TheUnderScorer 6ccc6e0
test: fix tests
TheUnderScorer 639602e
fix: don't use `host` header for determining request url
TheUnderScorer 868b9e8
test: wait longer for front door
TheUnderScorer 5e0d535
test: wait 6 minutes
TheUnderScorer 62923e6
test: wait 10 minutes
TheUnderScorer cf928d6
test: wrap mock tests in retry policy
TheUnderScorer d368209
test: increase attempts
TheUnderScorer 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,23 @@ | ||
import { stripPort } from './ip' | ||
|
||
describe('Strip port', () => { | ||
it('strip port from ipv4 address', () => { | ||
expect(stripPort('237.84.2.178:80')).toBe('237.84.2.178') | ||
}) | ||
|
||
it('ipv6 without port', () => { | ||
expect(stripPort('5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b')).toBe('5be8:dde9:7f0b:d5a7:bd01:b3be:9c69:573b') | ||
}) | ||
|
||
it('ipv4 without port', () => { | ||
expect(stripPort('237.84.2.178')).toBe('237.84.2.178') | ||
}) | ||
|
||
it('strip port from ipv6 address', () => { | ||
expect(stripPort('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443')).toBe('2001:0db8:85a3:0000:0000:8a2e:0370:7334') | ||
}) | ||
|
||
it.each(['127.0', 'invalid', 'localhost', '2001:0db8:85a3:0000:0000'])('invalid ip: %s', (data) => { | ||
expect(stripPort(data)).toBe(data) | ||
}) | ||
}) |
This file contains hidden or 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 @@ | ||
import { isIPv4, isIPv6 } from 'net' | ||
|
||
export function stripPort(ip: string) { | ||
// Check if it's an IPv6 address with a port | ||
if (ip.startsWith('[')) { | ||
// IPv6 address with port | ||
const closingBracketIndex = ip.indexOf(']') | ||
if (closingBracketIndex !== -1) { | ||
return ip.substring(1, closingBracketIndex) | ||
} | ||
} else { | ||
// IPv4 address with port or IPv6 without brackets | ||
const colonIndex = ip.lastIndexOf(':') | ||
if (colonIndex !== -1) { | ||
const ipWithoutPort = ip.substring(0, colonIndex) | ||
// Validate if the part before the colon is a valid IPv4 or IPv6 address | ||
if (isValidIp(ipWithoutPort)) { | ||
return ipWithoutPort | ||
} | ||
} | ||
} | ||
// If no port is found, return the original IP | ||
return ip | ||
} | ||
|
||
function isValidIp(ip: string) { | ||
return isIPv4(ip) || isIPv6(ip) | ||
} |
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.