defra_ruby_map 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/defra-ruby-map/map_init.js +7 -14
  3. data/app/controllers/defra_ruby_map/proxy_controller.rb +13 -2
  4. data/lib/defra_ruby_map/version.rb +1 -1
  5. data/vendor/assets/javascripts/defra-interactive-map/im-core.js +1 -1
  6. data/vendor/assets/javascripts/defra-interactive-map/im-core.js.LICENSE.txt +0 -30
  7. data/vendor/assets/javascripts/defra-interactive-map/index.js +1 -1
  8. data/vendor/assets/javascripts/defra-interactive-map/index.js.LICENSE.txt +0 -20
  9. data/vendor/assets/javascripts/interact-plugin/im-interact-plugin.js +1 -1
  10. data/vendor/assets/javascripts/interact-plugin/index.js +1 -1
  11. data/vendor/assets/javascripts/map-styles-plugin/im-map-styles-plugin.js +1 -1
  12. data/vendor/assets/javascripts/map-styles-plugin/index.js +1 -1
  13. data/vendor/assets/javascripts/maplibre-provider/im-maplibre-framework.js +1 -1
  14. data/vendor/assets/javascripts/maplibre-provider/im-maplibre-framework.js.LICENSE.txt +3 -3
  15. data/vendor/assets/javascripts/maplibre-provider/im-maplibre-provider.js +1 -1
  16. data/vendor/assets/javascripts/maplibre-provider/im-maplibre-worker.js +2 -0
  17. data/vendor/assets/javascripts/maplibre-provider/im-maplibre-worker.js.LICENSE.txt +4 -0
  18. data/vendor/assets/javascripts/maplibre-provider/index.js +1 -1
  19. data/vendor/assets/javascripts/proj4js/proj4.js +1 -1
  20. data/vendor/assets/javascripts/scale-bar-plugin/im-scale-bar-plugin.js +1 -1
  21. data/vendor/assets/javascripts/scale-bar-plugin/index.js +1 -1
  22. data/vendor/assets/javascripts/search-plugin/im-search-plugin.js +1 -1
  23. data/vendor/assets/javascripts/search-plugin/index.js +1 -1
  24. data/vendor/assets/stylesheets/defra-interactive-map/interactive-map.css +1 -1
  25. data/vendor/assets/stylesheets/defra-interactive-map/map-styles-plugin.css +1 -1
  26. data/vendor/assets/stylesheets/defra-interactive-map/scale-bar-plugin.css +1 -31
  27. data/vendor/assets/stylesheets/defra-interactive-map/search-plugin.css +1 -1
  28. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a2f98d96f22c559bf065e71a385e2e6c44e15a3f88849472894991d97bc8d84
4
- data.tar.gz: 2c06e945bfc6341124f8a3d1de8660059a2e152bba0272322edea1af245e23ad
3
+ metadata.gz: e8d9078473375bc26c9e8ed1dc672681d0cc2480beebe95d7b57416062bf8864
4
+ data.tar.gz: fe3aa53459ade42a9a4140fa3e0263431e24c6b91065fa8ec108315abb7204e5
5
5
  SHA512:
6
- metadata.gz: fc3cac76f70d43922c65dac966120e095b198040cd5902f6c60a2329c2efc74a49aba372ccf2f0e1dc6e90eb869771585d6542e57e8b8fbec88ac112a2768997
7
- data.tar.gz: 2e4089710844a5774c5b9c9ffc892c0cdfb347bf791bd4aa3418985f283623a6dae61cd883671b38a942691e1d8e1f3b8b58ea939b29c1dc1b6bfc4ab1845254
6
+ metadata.gz: 57b7d95465988b03bd267528fa0750649c63757fe03ed872517f0e2d09137d353a516c20ac9347d7d099c14c7877907c5e5490d57a15ab8a516e07115378e188
7
+ data.tar.gz: b5640a889bde939f5fd0fc45b72abf6ff7ebbbf123a4c22e0561b35252a167d2201656bb462161265f0d0d2a9d231a4a622e6e08c86d9700b705b67992696357
@@ -30,30 +30,23 @@
30
30
  backgroundColor: "#f5f5f0"
31
31
  };
32
32
 
33
- const HTML_ENTITIES = { "&": "&amp;", "<": "&lt;", ">": "&gt;", "\"": "&quot;", "'": "&#39;" };
34
- function escapeHtml(str) {
35
- return String(str).replace(/[&<>"']/g, function (c) { return HTML_ENTITIES[c]; });
36
- }
37
-
38
- // Maps OS Places API results to the search plugin's suggestion shape. The
39
- // plugin renders `marked` via dangerouslySetInnerHTML, so the address text
40
- // is HTML-escaped before the matched query is wrapped in <mark> — otherwise
41
- // HTML in an OS address would execute (stored XSS).
33
+ // Maps OS Places API results to the search plugin's suggestion shape. Since
34
+ // v0.0.56 the plugin renders `marked` as text (only bare <mark> tags become
35
+ // elements), so the address must not be HTML-escaped or entities would show.
42
36
  function parseOsPlacesResults(data, query) {
43
37
  if (!data?.results) { return []; }
44
- const safeQuery = escapeHtml(query || "").replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
45
- const matcher = safeQuery ? new RegExp(`(${safeQuery})`, "gi") : null;
38
+ const queryPattern = (query || "").replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
39
+ const matcher = queryPattern ? new RegExp(`(${queryPattern})`, "gi") : null;
46
40
  return data.results.map(function (item) {
47
41
  const record = item.DPA || item.LPI;
48
42
  if (!record) { return null; }
49
43
  const text = record.ADDRESS || "";
50
- const safeText = escapeHtml(text);
51
44
  const lng = record.LNG || 0;
52
45
  const lat = record.LAT || 0;
53
46
  return {
54
47
  id: String(record.UPRN),
55
48
  text: text,
56
- marked: matcher ? safeText.replace(matcher, "<mark>$1</mark>") : safeText,
49
+ marked: matcher ? text.replace(matcher, "<mark>$1</mark>") : text,
57
50
  point: [lng, lat],
58
51
  bounds: [
59
52
  lng - SUGGESTION_BOUNDS_PADDING,
@@ -270,6 +263,6 @@
270
263
 
271
264
  window.DefraMap = {
272
265
  init: initMap,
273
- _internal: { escapeHtml: escapeHtml, parseOsPlacesResults: parseOsPlacesResults }
266
+ _internal: { parseOsPlacesResults: parseOsPlacesResults }
274
267
  };
275
268
  })();
@@ -77,16 +77,27 @@ module DefraRubyMap
77
77
  headers["ETag"] = response["ETag"] if response["ETag"]
78
78
  headers["Expires"] = response["Expires"] if response["Expires"]
79
79
  end
80
- render body: response.body, status: status_code,
80
+ render body: scrub_api_key(response.body), status: status_code,
81
81
  content_type: response["Content-Type"] || "application/octet-stream"
82
82
  end
83
83
 
84
+ # OS echoes the key back in relayed bodies (e.g. the VTS "tiles" URLs and the style's
85
+ # sprite/glyphs/source URLs). Drop the key param so the browser never sees it
86
+ def scrub_api_key(body)
87
+ return body if body.blank? || body.exclude?(os_maps_api_key)
88
+
89
+ escaped_key = Regexp.escape(os_maps_api_key)
90
+ body.gsub(/(\?|&|\\u0026)key=#{escaped_key}((?:&|\\u0026)?)/) do
91
+ Regexp.last_match(2).empty? ? "" : Regexp.last_match(1)
92
+ end.gsub(os_maps_api_key, "")
93
+ end
94
+
84
95
  def proxy_get(base_url, params)
85
96
  uri = URI(base_url)
86
97
  uri.query = URI.encode_www_form(params)
87
98
 
88
99
  response = fetch_upstream(uri)
89
- render(json: response.body, status: response.code.to_i)
100
+ render(json: scrub_api_key(response.body), status: response.code.to_i)
90
101
  rescue StandardError => e
91
102
  Rails.logger.error("[DefraRubyMap] #{action_name} upstream error: #{e.class}: #{e.message}")
92
103
  render(json: { error: "upstream service unavailable" }, status: :bad_gateway)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMap
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end