@kalisio/kdk 2.6.1 → 2.6.2

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.
@@ -13,17 +13,31 @@ const verifyHooks = authManagement.hooks
13
13
  const debug = makeDebug('kdk:core:users:hooks')
14
14
 
15
15
  // Helper functions to be used in iff hooks
16
- export function disallowRegistration (hook) {
17
- return _.get(hook.app.get('authentication'), 'disallowRegistration')
16
+ export function disallowRegistration (context) {
17
+ return _.get(context.app.get('authentication'), 'disallowRegistration')
18
18
  }
19
- export function allowLocalAuthentication (hook) {
20
- return _.get(hook.app.get('authentication'), 'authStrategies', []).includes('local')
19
+
20
+ export function allowLocalAuthentication (context) {
21
+ return _.get(context.app.get('authentication'), 'authStrategies', []).includes('local')
21
22
  }
22
- export function isNotMe (hook) {
23
- const userId = _.get(hook.params, 'user._id', '')
24
- const item = getItems(hook)
25
- const targetId = _.get(item, '_id', '')
26
- return userId.toString() !== targetId.toString()
23
+
24
+ export function isNotMe (context) {
25
+ const userId = _.toString(_.get(context.params, 'user._id'))
26
+ if (_.isEmpty(userId)) throw new Forbidden('Not authenticated')
27
+ // Before hook
28
+ if (context.type === 'before') {
29
+ if (context.method === 'find') {
30
+ context.params.query = {
31
+ ...context.params.query,
32
+ _id: userId
33
+ }
34
+ return context
35
+ }
36
+ return _.toString(context.id) !== userId
37
+ }
38
+ // After hook
39
+ const item = getItems(context)
40
+ return _.toString(item._id) !== userId
27
41
  }
28
42
 
29
43
  export function enforcePasswordPolicy (options = {}) {
@@ -47,6 +47,7 @@
47
47
  <script>
48
48
  import _ from 'lodash'
49
49
  import { baseField } from '../../mixins'
50
+ import { Document } from '../../document.js'
50
51
  import KTextArea from '../KTextArea.vue'
51
52
 
52
53
  export default {
@@ -112,6 +113,11 @@ export default {
112
113
  methods: {
113
114
  emptyModel () {
114
115
  return ''
116
+ },
117
+ fill (value) {
118
+ // Sanitize data, this prevent XSS if the content is directly edited through the API or in DB
119
+ this.model = Document.sanitizeHtml(value)
120
+ this.error = ''
115
121
  }
116
122
  }
117
123
  }
@@ -12,14 +12,14 @@ export function useErrors () {
12
12
  const Route = useRoute()
13
13
 
14
14
  // Functions
15
- function showError (error) {
15
+ function showError (error, options = { html: true }) {
16
16
  // Check if this error is a quiet one or not
17
17
  if (error.ignore) {
18
18
  // In this case simply log
19
19
  logger.error(error)
20
20
  return
21
21
  }
22
- const notification = { type: 'negative', message: error.message || error.error_message || error.error, html: true }
22
+ const notification = { type: 'negative', message: error.message || error.error_message || error.error, html: options.html }
23
23
  // Check if user can retry to avoid this error
24
24
  if (error.retryHandler) {
25
25
  notification.actions = [{
@@ -34,12 +34,14 @@ export function useErrors () {
34
34
  function showRouteError (route) {
35
35
  // We handle error on any page with query string
36
36
  if (route.query && (route.query.error_message || route.query.error)) {
37
- showError(route.query)
37
+ // Avoid XSS in this case as a user can use the query paramter
38
+ showError(route.query, { html: false })
38
39
  }
39
40
  // OAuth login is using token set as route param like 'access_token=jwt'.
40
41
  // However in case of error it will be like 'error=message' instead.
41
42
  else if (route.params && route.params.token && route.params.token.startsWith('error=')) {
42
- showError({ message: route.params.token.split('=')[1] })
43
+ // Avoid XSS in this case as a user can use the query paramter
44
+ showError({ message: route.params.token.split('=')[1] }, { html: false })
43
45
  }
44
46
  }
45
47
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kalisio/kdk",
3
3
  "description": "Kalisio Development Kit",
4
- "version": "2.6.1",
4
+ "version": "2.6.2",
5
5
  "homepage": "https://github.com/kalisio/kdk",
6
6
  "type": "module",
7
7
  "keywords": [