Skip to content

Commit

Permalink
Allows for more than 2 level path be shared
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwin P Chandran <[email protected]>
  • Loading branch information
ashwin-pc committed Aug 29, 2023
1 parent 88b2012 commit 6db1271
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ describe('shortUrlAssertValid()', () => {
['hostname', 'localhost/app/opensearch-dashboards', PATH_ERROR], // according to spec, this is not a valid URL -- you cannot specify a hostname without a protocol
['hostname and port', 'local.host:5601/app/opensearch-dashboards', PROTOCOL_ERROR], // parser detects 'local.host' as the protocol
['hostname and auth', 'user:[email protected]/app/opensearch-dashboards', PROTOCOL_ERROR], // parser detects 'user' as the protocol
['path traversal', '/app/../../not-opensearch-dashboards', PATH_ERROR], // fails because there are >2 path parts
['path traversal', '/../not-opensearch-dashboards', PATH_ERROR], // fails because first path part is not 'app'
['deep path', '/app/opensearch-dashboards/foo', PATH_ERROR], // fails because there are >2 path parts
['deeper path', '/app/opensearch-dashboards/foo/bar', PATH_ERROR], // fails because there are >2 path parts
['base path', '/base/app/opensearch-dashboards', PATH_ERROR], // fails because there are >2 path parts
['base path', '/base/app/opensearch-dashboards', PATH_ERROR], // fails because first path part is not 'app'
['path with an extra leading slash', '//foo/app/opensearch-dashboards', HOSTNAME_ERROR], // parser detects 'foo' as the hostname
['path with an extra leading slash', '///app/opensearch-dashboards', HOSTNAME_ERROR], // parser detects '' as the hostname
['path without app', '/foo/opensearch-dashboards', PATH_ERROR], // fails because first path part is not 'app'
Expand All @@ -63,10 +60,13 @@ describe('shortUrlAssertValid()', () => {
const valid = [
'/app/opensearch-dashboards',
'/app/opensearch-dashboards/', // leading and trailing slashes are trimmed
'/app/opensearch-dashboards/deeper',
'/app/monitoring#angular/route',
'/app/text#document-id',
'/app/text/deeper#document-id',
'/app/some?with=query',
'/app/some?with=query#and-a-hash',
'/app/some/deeper?with=query#and-a-hash',
];

valid.forEach((url) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function shortUrlAssertValid(url: string) {
}

const pathnameParts = trim(pathname === null ? undefined : pathname, '/').split('/');
if (pathnameParts.length !== 2 || pathnameParts[0] !== 'app' || !pathnameParts[1]) {
if (pathnameParts[0] !== 'app' || !pathnameParts[1]) {
throw Boom.notAcceptable(
`Short url target path must be in the format "/app/{{appId}}", found "${pathname}"`
);
Expand Down

0 comments on commit 6db1271

Please sign in to comment.