Skip to content

Commit

Permalink
Merge pull request #64 from namecheap/fix/redirect-vulnerability-yet-…
Browse files Browse the repository at this point in the history
…another-case

fix: yet another case when redirect passes through due to url malformation
  • Loading branch information
wRLSS authored Oct 21, 2024
2 parents 50d5290 + 8a7a6e6 commit e636912
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ilc-sdk",
"version": "5.2.1",
"version": "5.2.4",
"description": "SDK for app development with Isomorphic Layout Composer",
"main": "dist/server/index.js",
"types": "dist/server/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/app/utils/parseAsFullyQualifiedURI.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default function parseAsFullyQualifiedURI(uri: string) {
let origin = '';
try {
// Normalize multiple slashes to a single slash, but don't affect the initial "http://" or "https://"
uri = uri.replace(/([^:])\/{2,}/g, '$1/');

const urlObj = new URL(uri);
origin = urlObj.origin;

// Apply replacement only to the pathname, leaving the rest (search, hash) intact
urlObj.pathname = urlObj.pathname.replace(/\/{2,}/g, '/');

uri = urlObj.pathname + urlObj.search + urlObj.hash;
} catch {}

Expand Down
7 changes: 7 additions & 0 deletions test/app/IlcIntl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ describe('IlcIntl', () => {
});
});

it('returns locale with normalized route when multiple slashes are present', () => {
expect(IlcIntl.parseUrl(baseConfig, '/es///tst.com')).to.eql({
cleanUrl: '/tst.com',
locale: 'es-ES',
});
});

it('returns locale with default culture when no culture present in the route', () => {
expect(IlcIntl.parseUrl(baseConfig, '/es-MX/tst')).to.eql({
cleanUrl: '/tst',
Expand Down

0 comments on commit e636912

Please sign in to comment.