Skip to content

Commit 8f59665

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Fix prototype pollution via Style JSON
GitOrigin-RevId: 0b2abac9efd08a9346f96481317f7f12eba24e84
1 parent 1848ce5 commit 8f59665

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/style-spec/group_by_layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function groupByLayout(
6969
[id: string]: string;
7070
},
7171
): Array<Array<LayerSpecification>> {
72-
const groups: Record<string, LayerSpecification[]> = {};
72+
const groups = Object.create(null) as Record<string, LayerSpecification[]>;
7373

7474
for (let i = 0; i < layers.length; i++) {
7575
const layer = layers[i];

src/style/style_layer_index.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,31 @@ import type {TypedStyleLayer} from './style_layer/typed_style_layer';
55
import type {LayerSpecification} from '../style-spec/types';
66
import type {ConfigOptions} from './properties';
77

8-
export type LayerConfigs = {
9-
[_: string]: LayerSpecification;
10-
};
8+
export type LayerConfigs = Record<string, LayerSpecification>;
119

1210
export type Family<Layer extends TypedStyleLayer> = Array<Layer>;
1311

1412
class StyleLayerIndex {
1513
scope: string;
16-
familiesBySource: {
17-
[source: string]: {
18-
[sourceLayer: string]: Array<Family<TypedStyleLayer>>;
19-
};
20-
};
21-
keyCache: {
22-
[source: string]: string;
23-
};
14+
familiesBySource: Record<string, Record<string, Array<Family<TypedStyleLayer>>>>;
15+
keyCache: Record<string, string>;
2416

2517
_layerConfigs: LayerConfigs;
26-
_layers: {
27-
[_: string]: TypedStyleLayer;
28-
};
18+
_layers: Record<string, TypedStyleLayer>;
2919
_options: ConfigOptions | null | undefined;
3020

3121
constructor(layerConfigs?: Array<LayerSpecification> | null) {
32-
this.keyCache = {};
33-
this._layers = {};
34-
this._layerConfigs = {};
22+
this.keyCache = Object.create(null) as Record<string, string>;
23+
this._layers = Object.create(null) as Record<string, TypedStyleLayer>;
24+
this._layerConfigs = Object.create(null) as LayerConfigs;
3525
if (layerConfigs) {
3626
this.replace(layerConfigs);
3727
}
3828
}
3929

4030
replace(layerConfigs: Array<LayerSpecification>, options?: ConfigOptions | null) {
41-
this._layerConfigs = {};
42-
this._layers = {};
31+
this._layerConfigs = Object.create(null) as LayerConfigs;
32+
this._layers = Object.create(null) as Record<string, TypedStyleLayer>;
4333
this.update(layerConfigs, [], options);
4434
}
4535

@@ -60,7 +50,7 @@ class StyleLayerIndex {
6050
delete this._layers[id];
6151
}
6252

63-
this.familiesBySource = {};
53+
this.familiesBySource = Object.create(null) as StyleLayerIndex['familiesBySource'];
6454

6555
const groups = groupByLayout(Object.values(this._layerConfigs), this.keyCache);
6656

@@ -75,7 +65,7 @@ class StyleLayerIndex {
7565
const sourceId = layer.source || '';
7666
let sourceGroup = this.familiesBySource[sourceId];
7767
if (!sourceGroup) {
78-
sourceGroup = this.familiesBySource[sourceId] = {};
68+
sourceGroup = this.familiesBySource[sourceId] = Object.create(null) as Record<string, Array<Family<TypedStyleLayer>>>;
7969
}
8070

8171
const sourceLayerId = layer.sourceLayer || '_geojsonTileLayer';

0 commit comments

Comments
 (0)