ckeditor5 1.16.0 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e91fe2d11179c703901756efa978fcedcd3030d0381c4e550ab8c9c15ef73a19
4
- data.tar.gz: 4119948cdae51969b3d1e77801f20faecd81cfbf2755388fc444421e7da8bdb9
3
+ metadata.gz: 95f068ef75561d88a26a68c5aafa6e6f86b55405984e83bf35909085f288f9ba
4
+ data.tar.gz: d72e733641c5ac8c4f9d1e20731d54ffd2c0e4d88bc3b82618eb62b8c2820049
5
5
  SHA512:
6
- metadata.gz: d4f236d5bc883344daa8fa9bc0b7d55e3898360dd8fabfd48265bbd1eedf3c654e8ba6baf5b0a1ba5ffa215c6b2c14a60c02f7182b81885a875b0a4902f67746
7
- data.tar.gz: 593de9199583c1f22a38b9858967eca63b9c98eef8b7a6a1e5a06ccfa1df759424dab96ed88c1719614744b26c8a32920722156875ba748e66c80272eeb0fd78
6
+ metadata.gz: 31fb63fa1ac20061e1c28150178b7b8f92ca54e99073f2e180a7823d7f76f58c75a9f55e70b9a6f729d9715389b1a349305027e6d6c0c56bb2f7539d1a6bc0ad
7
+ data.tar.gz: 4019ffcc8e326be64930092815d5ff68436e4c242a67853adf735b4667aa7bec624df66fe9614d0f7e4bb00c67c2c0cf0e1195c43647d397b9f99ab8a0637479
@@ -12,12 +12,7 @@ class CKEditorContextComponent extends HTMLElement {
12
12
  /** @type {Set<CKEditorComponent>} */
13
13
  #connectedEditors = new Set();
14
14
 
15
- /** @type {String} Attributes checksum hash */
16
- #integrity = '';
17
-
18
15
  async connectedCallback() {
19
- this.#integrity = this.getAttribute('integrity');
20
-
21
16
  try {
22
17
  execIfDOMReady(() => this.#initializeContext());
23
18
  } catch (error) {
@@ -57,22 +52,6 @@ class CKEditorContextComponent extends HTMLElement {
57
52
  this.#connectedEditors.delete(editor);
58
53
  }
59
54
 
60
- /**
61
- * Validates editor configuration integrity hash to prevent attacks.
62
- */
63
- async #validateIntegrity() {
64
- const integrity = await calculateChecksum({
65
- plugins: this.getAttribute('plugins'),
66
- });
67
-
68
- if (integrity !== this.#integrity) {
69
- throw new Error(
70
- 'Configuration integrity check failed. It means that #integrity attributes mismatch from attributes passed to webcomponent. ' +
71
- 'This could be a security issue. Please check if you are passing correct attributes to the webcomponent.'
72
- );
73
- }
74
- }
75
-
76
55
  /**
77
56
  * Initialize CKEditor context with shared configuration
78
57
  *
@@ -87,8 +66,6 @@ class CKEditorContextComponent extends HTMLElement {
87
66
  this.instance = null;
88
67
  }
89
68
 
90
- await this.#validateIntegrity();
91
-
92
69
  const { Context, ContextWatchdog } = await import('ckeditor5');
93
70
  const plugins = await this.#getPlugins();
94
71
  const config = this.#getConfig();
@@ -40,9 +40,6 @@ class CKEditorComponent extends HTMLElement {
40
40
  /** @type {String} ID of editor within context */
41
41
  #contextEditorId = null;
42
42
 
43
- /** @type {String} Attributes checksum hash */
44
- #integrity = '';
45
-
46
43
  /** @type {(event: CustomEvent) => void} Event handler for editor change */
47
44
  get oneditorchange() {
48
45
  return this.#getEventHandler('editorchange');
@@ -109,11 +106,9 @@ class CKEditorComponent extends HTMLElement {
109
106
  /**
110
107
  * Lifecycle callback when element is connected to DOM
111
108
  * Initializes the editor when DOM is ready
112
- *
113
109
  * @protected
114
110
  */
115
111
  connectedCallback() {
116
- this.#integrity = this.getAttribute('integrity');
117
112
  this.#context = this.closest('ckeditor-context-component');
118
113
  this.#initialHTML = this.innerHTML;
119
114
 
@@ -233,23 +228,6 @@ class CKEditorComponent extends HTMLElement {
233
228
  return resolveElementReferences(config);
234
229
  }
235
230
 
236
- /**
237
- * Validates editor configuration integrity hash to prevent attacks.
238
- */
239
- async #validateIntegrity() {
240
- const integrity = await calculateChecksum({
241
- translations: this.getAttribute('translations'),
242
- plugins: this.getAttribute('plugins'),
243
- });
244
-
245
- if (integrity !== this.#integrity) {
246
- throw new Error(
247
- 'Configuration integrity check failed. It means that #integrity attributes mismatch from attributes passed to webcomponent. ' +
248
- 'This could be a security issue. Please check if you are passing correct attributes to the webcomponent.'
249
- );
250
- }
251
- }
252
-
253
231
  /**
254
232
  * Creates a new CKEditor instance
255
233
  *
@@ -259,8 +237,6 @@ class CKEditorComponent extends HTMLElement {
259
237
  * @throws {Error} When initialization fails
260
238
  */
261
239
  async #initializeEditor(editablesOrContent) {
262
- await this.#validateIntegrity();
263
-
264
240
  const Editor = await this.#getEditorConstructor();
265
241
  const [plugins, translations] = await Promise.all([
266
242
  this.#getPlugins(),
@@ -66,18 +66,16 @@ function loadAsyncImports(imports = []) {
66
66
  return imported;
67
67
  };
68
68
 
69
- return Promise.all(
70
- imports.map(async (item) => {
71
- switch(item.type) {
72
- case 'inline':
73
- return loadInlinePlugin(item);
74
-
75
- case 'external':
76
- default:
77
- return loadExternalPlugin(item);
78
- }
79
- })
80
- );
69
+ return Promise.all(imports.map(item => {
70
+ switch(item.type) {
71
+ case 'inline':
72
+ return loadInlinePlugin(item);
73
+
74
+ case 'external':
75
+ default:
76
+ return loadExternalPlugin(item);
77
+ }
78
+ }));
81
79
  }
82
80
 
83
81
  /**
@@ -155,24 +153,3 @@ function resolveElementReferences(obj) {
155
153
  function uid() {
156
154
  return Math.random().toString(36).substring(2);
157
155
  }
158
-
159
- /**
160
- * Calculates checksum for an object.
161
- */
162
- async function calculateChecksum(obj) {
163
- const objCopy = { ...obj, checksum: undefined };
164
-
165
- return sha256(JSON.stringify(objCopy));
166
- }
167
-
168
- /**
169
- * Calculates SHA-256 hash for a string
170
- */
171
- async function sha256(str) {
172
- const buffer = new TextEncoder().encode(str);
173
- const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
174
-
175
- return Array.from(new Uint8Array(hashBuffer))
176
- .map(b => b.toString(16).padStart(2, '0'))
177
- .join('');
178
- }
@@ -3,16 +3,14 @@
3
3
  module CKEditor5::Rails
4
4
  module Context
5
5
  class Props
6
- include CKEditor5::Rails::Concerns::Checksum
7
-
8
6
  def initialize(config)
9
7
  @config = config
10
8
  end
11
9
 
12
10
  def to_attributes
13
11
  {
14
- **serialized_attributes,
15
- integrity: integrity_checksum
12
+ plugins: serialize_plugins,
13
+ config: serialize_config
16
14
  }
17
15
  end
18
16
 
@@ -20,19 +18,6 @@ module CKEditor5::Rails
20
18
 
21
19
  attr_reader :config
22
20
 
23
- def integrity_checksum
24
- unsafe_attributes = serialized_attributes.slice(:plugins)
25
-
26
- calculate_object_checksum(unsafe_attributes)
27
- end
28
-
29
- def serialized_attributes
30
- @serialized_attributes ||= {
31
- plugins: serialize_plugins,
32
- config: serialize_config
33
- }
34
- end
35
-
36
21
  def serialize_plugins
37
22
  (config[:plugins] || []).map { |plugin| Editor::PropsPlugin.normalize(plugin).to_h }.to_json
38
23
  end
@@ -5,8 +5,6 @@ require_relative 'editable_height_normalizer'
5
5
 
6
6
  module CKEditor5::Rails::Editor
7
7
  class Props
8
- include CKEditor5::Rails::Concerns::Checksum
9
-
10
8
  EDITOR_TYPES = {
11
9
  classic: 'ClassicEditor',
12
10
  inline: 'InlineEditor',
@@ -27,9 +25,8 @@ module CKEditor5::Rails::Editor
27
25
 
28
26
  def to_attributes
29
27
  {
30
- **serialized_attributes,
31
28
  type: EDITOR_TYPES[@type],
32
- integrity: integrity_checksum
29
+ **serialized_attributes
33
30
  }
34
31
  end
35
32
 
@@ -41,24 +38,14 @@ module CKEditor5::Rails::Editor
41
38
 
42
39
  attr_reader :controller_context, :watchdog, :type, :config, :editable_height
43
40
 
44
- def integrity_checksum
45
- unsafe_attributes = serialized_attributes.slice(:translations, :plugins)
46
-
47
- calculate_object_checksum(unsafe_attributes)
48
- end
49
-
50
41
  def serialized_attributes
51
- return @serialized_attributes if defined?(@serialized_attributes)
52
-
53
- attributes = {
42
+ {
54
43
  translations: serialize_translations,
55
44
  plugins: serialize_plugins,
56
45
  config: serialize_config,
57
46
  watchdog: watchdog
58
47
  }
59
-
60
- attributes.merge!(editable_height ? { 'editable-height' => editable_height } : {})
61
- @serialized_attributes = attributes
48
+ .merge(editable_height ? { 'editable-height' => editable_height } : {})
62
49
  end
63
50
 
64
51
  def serialize_translations
@@ -1,14 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'props_base_plugin'
4
-
5
3
  module CKEditor5::Rails::Editor
6
- class PropsInlinePlugin < PropsBasePlugin
7
- attr_reader :code
4
+ class PropsInlinePlugin
5
+ attr_reader :name, :code
8
6
 
9
7
  def initialize(name, code)
10
- super(name)
11
-
8
+ @name = name
12
9
  @code = code
13
10
  validate_code!
14
11
  end
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'props_base_plugin'
4
-
5
3
  module CKEditor5::Rails::Editor
6
- class PropsPlugin < PropsBasePlugin
7
- attr_reader :js_import_meta
4
+ class PropsPlugin
5
+ attr_reader :name, :js_import_meta
8
6
 
9
- def initialize(name, premium: false, **js_import_meta)
10
- super(name)
7
+ delegate :to_h, to: :import_meta
11
8
 
9
+ def initialize(name, premium: false, **js_import_meta)
12
10
  @name = name
13
11
  @js_import_meta = if js_import_meta.empty?
14
12
  { import_name: premium ? 'ckeditor5-premium-features' : 'ckeditor5' }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.16.0'
5
+ VERSION = '1.16.1'
6
6
 
7
7
  DEFAULT_CKEDITOR_VERSION = '43.3.1'
8
8
  end
@@ -5,7 +5,6 @@ module CKEditor5
5
5
  require_relative 'rails/version'
6
6
  require_relative 'rails/version_detector'
7
7
  require_relative 'rails/semver'
8
- require_relative 'rails/concerns/checksum'
9
8
  require_relative 'rails/assets/assets_bundle'
10
9
  require_relative 'rails/assets/assets_bundle_html_serializer'
11
10
  require_relative 'rails/helpers'
@@ -25,15 +25,9 @@ RSpec.describe CKEditor5::Rails::Context::Props do
25
25
  describe '#to_attributes' do
26
26
  subject(:attributes) { props.to_attributes }
27
27
 
28
- it 'returns integrity property' do
29
- expect(attributes[:integrity]).to eq(
30
- '24e46c3ee19f6764930b38ecdf62c0ac824a0acbe6616b46199d892afb211acb'
31
- )
32
- end
33
-
34
28
  it 'returns a hash with plugins and config keys' do
35
29
  expect(attributes).to be_a(Hash)
36
- expect(attributes.keys).to match_array(%i[plugins integrity config])
30
+ expect(attributes.keys).to match_array(%i[plugins config])
37
31
  end
38
32
 
39
33
  describe ':plugins key' do
@@ -28,13 +28,11 @@ RSpec.describe CKEditor5::Rails::Editor::Props do
28
28
 
29
29
  it 'includes required attributes' do
30
30
  attributes = props.to_attributes
31
-
32
31
  expect(attributes).to include(
33
32
  type: 'ClassicEditor',
34
33
  translations: String,
35
34
  plugins: String,
36
35
  config: String,
37
- integrity: '358d88b83d041f208d94ac957b2fd68135f1caab5c0d101d33cf04d5d39d81ef',
38
36
  watchdog: true
39
37
  )
40
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ckeditor5
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński
@@ -55,7 +55,6 @@ files:
55
55
  - lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
56
56
  - lib/ckeditor5/rails/cdn/helpers.rb
57
57
  - lib/ckeditor5/rails/cdn/url_generator.rb
58
- - lib/ckeditor5/rails/concerns/checksum.rb
59
58
  - lib/ckeditor5/rails/context/helpers.rb
60
59
  - lib/ckeditor5/rails/context/props.rb
61
60
  - lib/ckeditor5/rails/editor/editable_height_normalizer.rb
@@ -63,7 +62,6 @@ files:
63
62
  - lib/ckeditor5/rails/editor/helpers/config_helpers.rb
64
63
  - lib/ckeditor5/rails/editor/helpers/editor_helpers.rb
65
64
  - lib/ckeditor5/rails/editor/props.rb
66
- - lib/ckeditor5/rails/editor/props_base_plugin.rb
67
65
  - lib/ckeditor5/rails/editor/props_inline_plugin.rb
68
66
  - lib/ckeditor5/rails/editor/props_plugin.rb
69
67
  - lib/ckeditor5/rails/engine.rb
@@ -89,13 +87,11 @@ files:
89
87
  - spec/lib/ckeditor5/rails/cdn/ckeditor_bundle_spec.rb
90
88
  - spec/lib/ckeditor5/rails/cdn/helpers_spec.rb
91
89
  - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
92
- - spec/lib/ckeditor5/rails/concerns/checksum_spec.rb
93
90
  - spec/lib/ckeditor5/rails/context/helpers_spec.rb
94
91
  - spec/lib/ckeditor5/rails/context/props_spec.rb
95
92
  - spec/lib/ckeditor5/rails/editor/editable_height_normalizer_spec.rb
96
93
  - spec/lib/ckeditor5/rails/editor/helpers/config_helpers_spec.rb
97
94
  - spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb
98
- - spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
99
95
  - spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
100
96
  - spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
101
97
  - spec/lib/ckeditor5/rails/editor/props_spec.rb
@@ -146,13 +142,11 @@ test_files:
146
142
  - spec/lib/ckeditor5/rails/cdn/ckeditor_bundle_spec.rb
147
143
  - spec/lib/ckeditor5/rails/cdn/helpers_spec.rb
148
144
  - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
149
- - spec/lib/ckeditor5/rails/concerns/checksum_spec.rb
150
145
  - spec/lib/ckeditor5/rails/context/helpers_spec.rb
151
146
  - spec/lib/ckeditor5/rails/context/props_spec.rb
152
147
  - spec/lib/ckeditor5/rails/editor/editable_height_normalizer_spec.rb
153
148
  - spec/lib/ckeditor5/rails/editor/helpers/config_helpers_spec.rb
154
149
  - spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb
155
- - spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
156
150
  - spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
157
151
  - spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
158
152
  - spec/lib/ckeditor5/rails/editor/props_spec.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
- require 'json'
5
-
6
- module CKEditor5::Rails::Concerns
7
- module Checksum
8
- private
9
-
10
- def calculate_object_checksum(obj)
11
- json = JSON.generate(obj)
12
- Digest::SHA256.hexdigest(json)
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CKEditor5::Rails
4
- module Editor
5
- class PropsBasePlugin
6
- include Concerns::Checksum
7
-
8
- attr_reader :name
9
-
10
- def initialize(name)
11
- @name = name
12
- end
13
-
14
- def to_h
15
- raise NotImplementedError, 'This method must be implemented in a subclass'
16
- end
17
- end
18
- end
19
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe CKEditor5::Rails::Concerns::Checksum do
6
- let(:dummy_class) do
7
- Class.new do
8
- include CKEditor5::Rails::Concerns::Checksum
9
-
10
- public :calculate_object_checksum
11
- end
12
- end
13
-
14
- subject(:instance) { dummy_class.new }
15
-
16
- describe '#calculate_object_checksum' do
17
- it 'returns a 16-character string' do
18
- result = instance.calculate_object_checksum({ test: 'value' })
19
- expect(result).to eq(
20
- 'f98be16ebfa861cb39a61faff9e52b33f5bcc16bb6ae72e728d226dc07093932'
21
- )
22
- end
23
-
24
- it 'returns consistent checksums for the same input' do
25
- input = { name: 'test', value: 123 }
26
- first_result = instance.calculate_object_checksum(input)
27
- second_result = instance.calculate_object_checksum(input)
28
- expect(first_result).to eq(second_result)
29
- end
30
-
31
- it 'returns different checksums for different inputs' do
32
- result1 = instance.calculate_object_checksum({ a: 1 })
33
- result2 = instance.calculate_object_checksum({ a: 2 })
34
- expect(result1).not_to eq(result2)
35
- end
36
-
37
- it 'handles arrays' do
38
- result = instance.calculate_object_checksum([1, 2, 3])
39
- expect(result).to eq(
40
- 'a615eeaee21de5179de080de8c3052c8da901138406ba71c38c032845f7d54f4'
41
- )
42
- end
43
-
44
- it 'is order dependent for hashes' do
45
- result1 = instance.calculate_object_checksum({ a: 1, b: 2 })
46
- result2 = instance.calculate_object_checksum({ b: 2, a: 1 })
47
- expect(result1).not_to eq(result2)
48
- end
49
- end
50
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe CKEditor5::Rails::Editor::PropsBasePlugin do
6
- let(:concrete_class) do
7
- Class.new(described_class) do
8
- def to_unsafe_h
9
- { type: :test, name: name }
10
- end
11
- end
12
- end
13
-
14
- let(:instance) { concrete_class.new(:TestPlugin) }
15
-
16
- describe '#initialize' do
17
- it 'sets the name attribute' do
18
- expect(instance.name).to eq(:TestPlugin)
19
- end
20
- end
21
-
22
- describe '#to_h' do
23
- it 'raises NotImplementedError' do
24
- expect { instance.to_h }.to raise_error(NotImplementedError)
25
- end
26
- end
27
- end