Skip to content

Commit

Permalink
[APM] source map bundle_filepath is not cleaned (#105973) (#106273)
Browse files Browse the repository at this point in the history
* cleaning basepath url

* cleaning url

* cleaning url

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
  • Loading branch information
kibanamachine and cauemarcondes authored Jul 20, 2021
1 parent 3f01f1f commit 433e493
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions x-pack/plugins/apm/server/lib/fleet/source_maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
ArtifactSourceMap,
getPackagePolicyWithSourceMap,
getCleanedBundleFilePath,
} from './source_maps';

const packagePolicy = {
Expand Down Expand Up @@ -184,4 +185,19 @@ describe('Source maps', () => {
});
});
});
describe('getCleanedBundleFilePath', () => {
it('cleans url', () => {
expect(
getCleanedBundleFilePath(
'http://localhost:8000/test/e2e/../e2e/general-usecase/bundle.js.map'
)
).toEqual('http://localhost:8000/test/e2e/general-usecase/bundle.js.map');
});

it('returns same path when it is not a valid url', () => {
expect(
getCleanedBundleFilePath('/general-usecase/bundle.js.map')
).toEqual('/general-usecase/bundle.js.map');
});
});
});
9 changes: 9 additions & 0 deletions x-pack/plugins/apm/server/lib/fleet/source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,12 @@ export async function updateSourceMapsOnFleetPolicies({
})
);
}

export function getCleanedBundleFilePath(bundleFilePath: string) {
try {
const cleanedBundleFilepath = new URL(bundleFilePath);
return cleanedBundleFilepath.href;
} catch (e) {
return bundleFilePath;
}
}
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/server/routes/source_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
deleteApmArtifact,
listArtifacts,
updateSourceMapsOnFleetPolicies,
getCleanedBundleFilePath,
} from '../lib/fleet/source_maps';
import { getInternalSavedObjectsClient } from '../lib/helpers/get_internal_saved_objects_client';
import { createApmServerRoute } from './create_apm_server_route';
Expand Down Expand Up @@ -78,6 +79,7 @@ const uploadSourceMapRoute = createApmServerRoute({
bundle_filepath: bundleFilepath,
sourcemap: sourceMap,
} = params.body;
const cleanedBundleFilepath = getCleanedBundleFilePath(bundleFilepath);
const fleetPluginStart = await plugins.fleet?.start();
const coreStart = await core.start();
const esClient = coreStart.elasticsearch.client.asInternalUser;
Expand All @@ -89,7 +91,7 @@ const uploadSourceMapRoute = createApmServerRoute({
apmArtifactBody: {
serviceName,
serviceVersion,
bundleFilepath,
bundleFilepath: cleanedBundleFilepath,
sourceMap,
},
});
Expand Down

0 comments on commit 433e493

Please sign in to comment.