Skip to content

Commit c641f94

Browse files
bozdozbozdoz
andauthored
Security updates (#138)
* updates gitlab-ci to include jest tests * extracts sanitize functions for associative arrays * updates attributions to more secure markdown syntax only * verifies nonces in admin; resolves #135 * updates shortcodes atts to escape with filter_var and htmlspecialchars; resolves #136 * test the test stage * force test ci update * force update stage * update gitlab ci test job * popup_text is already escaped and set with textContent * const -> var * geojson atts are already escaped * removes unnecessary attribution changes * removes trailing commas * only test javascript when it changes * bump major version * fixes extra variables in shape popup script * update docker images * updates node dependencies * removes overwritting from all extract calls * removes unwanted HTML tags in attribution Co-authored-by: bozdoz <[email protected]>
1 parent 984cd6b commit c641f94

23 files changed

+2918
-6699
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Node.js CI
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.js'
7+
push:
8+
paths:
9+
- '**.js'
410

511
jobs:
612
build:

.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
variables:
22
GIT_DEPTH: 5
33

4+
stages:
5+
- test
6+
- deploy
7+
48
image: alpine:3.11
59

610
before_script:
@@ -11,6 +15,17 @@ before_script:
1115
- cp -r * /repo/trunk
1216
- cd /repo
1317

18+
test:
19+
stage: test
20+
before_script:
21+
- apk add --no-cache nodejs npm
22+
script:
23+
- npm ci
24+
- npm test
25+
rules:
26+
- changes:
27+
- '**/*.js'
28+
1429
new version:
1530
stage: deploy
1631
script:

class.leaflet-map.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/**
33
* Leaflet Map Class File
44
*
5-
* PHP Version 5.5
6-
*
75
* @category Admin
86
* @author Benjamin J DeLong <[email protected]>
97
*/
@@ -249,7 +247,29 @@ function remove_empty_string ($var) {
249247
}
250248

251249
/**
252-
* Sanitize JSON
250+
* Sanitize any given validations, but concatenate with the remaining keys from $arr
251+
*/
252+
public function sanitize_inclusive($arr, $validations) {
253+
return array_merge(
254+
$arr,
255+
$this->sanitize_exclusive($arr, $validations)
256+
);
257+
}
258+
259+
/**
260+
* Sanitize and return ONLY given validations
261+
*/
262+
public function sanitize_exclusive($arr, $validations) {
263+
// remove nulls
264+
$arr = $this->filter_null($arr);
265+
266+
// sanitize output
267+
$args = array_intersect_key($validations, $arr);
268+
return filter_var_array($arr, $args);
269+
}
270+
271+
/**
272+
* Sanitize JSON
253273
*
254274
* Takes options for filtering/correcting inputs for use in JavaScript
255275
*
@@ -259,12 +279,7 @@ function remove_empty_string ($var) {
259279
*/
260280
public function json_sanitize($arr, $args)
261281
{
262-
// remove nulls
263-
$arr = $this->filter_null($arr);
264-
265-
// sanitize output
266-
$args = array_intersect_key($args, $arr);
267-
$arr = filter_var_array($arr, $args);
282+
$arr = $this->sanitize_exclusive($arr, $args);
268283

269284
$output = json_encode($arr);
270285

@@ -288,7 +303,7 @@ public function json_sanitize($arr, $args)
288303
public function get_style_json($atts)
289304
{
290305
if ($atts) {
291-
extract($atts);
306+
extract($atts, EXTR_SKIP);
292307
}
293308

294309
// from http://leafletjs.com/reference-1.0.3.html#path
@@ -343,7 +358,8 @@ public function get_style_json($atts)
343358
public function add_popup_to_shape($atts, $content, $shape)
344359
{
345360
if (!empty($atts)) {
346-
extract($atts);
361+
// don't overwrite existing variables
362+
extract($atts, EXTR_SKIP);
347363
}
348364

349365
$message = empty($message) ?

class.plugin-settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/**
33
* Class for getting and setting db/default values
44
*
5-
* PHP Version 5.5
6-
*
75
* @category Admin
86
* @author Benjamin J DeLong <[email protected]>
97
*/
@@ -15,6 +13,8 @@
1513

1614
require_once LEAFLET_MAP__PLUGIN_DIR . 'class.plugin-option.php';
1715

16+
// TODO: add option to reset just a single field
17+
1818
/**
1919
* Used to get and set values
2020
*

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
MYSQL_ROOT_PASSWORD: rootpass
1111

1212
cli:
13-
image: bozdoz/wordpress-initialize:2.4.0-20201102
13+
image: bozdoz/wordpress-initialize:2.5.0
1414
depends_on:
1515
- mysql
1616
volumes:
@@ -33,7 +33,7 @@ services:
3333
WP_THEME: twentynineteen
3434

3535
wordpress:
36-
image: wordpress:5.5.3-php7.4
36+
image: wordpress:5.7.2-php7.4
3737
depends_on:
3838
- cli
3939
volumes:

leaflet-map.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author URI: https://bozdoz.com/
99
* Text Domain: leaflet-map
1010
* Domain Path: /languages/
11-
* Version: 2.23.3
11+
* Version: 3.0.0
1212
* License: GPL2
1313
* Leaflet Map is free software: you can redistribute it and/or modify
1414
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@
2929
exit;
3030
}
3131

32-
define('LEAFLET_MAP__PLUGIN_VERSION', '2.23.3');
32+
define('LEAFLET_MAP__PLUGIN_VERSION', '3.0.0');
3333
define('LEAFLET_MAP__PLUGIN_FILE', __FILE__);
3434
define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__));
3535

0 commit comments

Comments
 (0)