Skip to content

Commit

Permalink
fix: normalize monitor names when bundling (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Oct 30, 2023
1 parent 3f5b18b commit d3041b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
MonitorConfig,
} from '../dsl/monitor';
import { PushOptions } from '../common_types';
import { isParamOptionSupported } from './utils';
import { isParamOptionSupported, normalizeMonitorName } from './utils';

// Allowed extensions for lightweight monitor files
const ALLOWED_LW_EXTENSIONS = ['.yml', '.yaml'];
Expand Down Expand Up @@ -139,7 +139,10 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
};

if (type === 'browser') {
const outPath = join(bundlePath, config.name + '.zip');
const outPath = join(
bundlePath,
normalizeMonitorName(config.name) + '.zip'
);
const content = await bundler.build(source.file, outPath);
monitor.setContent(content);
Object.assign(schema, { content, filter });
Expand Down
15 changes: 15 additions & 0 deletions src/push/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,18 @@ export function isLightweightMonitorSupported(
export function isParamOptionSupported(version: string) {
return semver.satisfies(version, '>=8.7.2');
}

/**
* Helper that replaces url paths traversal issues when bundling
*/
export function normalizeMonitorName(p: string, replacement = '_') {
// replace encoded and non encoded dots
p = p.replace(/%2e|\./gi, replacement);
// encoded slashes
p = p.replace(/%2f|%5c/gi, replacement);
// backslashes
p = p.replace(/[/\\]+/g, replacement);
// remove colons
p = p.replace(/[:]+/g, replacement);
return p;
}

0 comments on commit d3041b5

Please sign in to comment.