Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Pass the originsAllowed through the system, and treat all origins in …
Browse files Browse the repository at this point in the history
…the permission.allowsOrigin method (#26)
  • Loading branch information
kjetilk committed Aug 30, 2018
1 parent 8e49494 commit 7d94ffa
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/permission-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class PermissionSet {
* @param [options.host] {String} Actual request uri
* @param [options.origin] {String} Origin URI to enforce, relevant
* if strictOrigin is set to true
* @param [options.originsAllowed] {String|Statement|Array<String>|Array<Statement>} An array of allowed origins, relevant
* if strictOrigin is set to true
* @param [options.webClient] {SolidWebClient} Used for save() and clear()
* @param [options.isAcl] {Function}
* @param [options.aclUrlFor] {Function}
Expand Down Expand Up @@ -141,6 +143,13 @@ class PermissionSet {
* @type {String}
*/
this.origin = options.origin
/**
* An array of origins that are always allowed
* (used only if `strictOrigin` parameter is set to true)
* @property originsAllowed
* @type {String|Statement|Array<String>|Array<Statement>}
*/
this.originsAllowed = options.originsAllowed
/**
* Solid REST client (optionally injected), used by save() and clear().
* @type {SolidWebClient}
Expand Down Expand Up @@ -213,6 +222,7 @@ class PermissionSet {
}
perm.addMode(accessModes)
perm.addOrigin(origins)
perm.addOrigin(this.originsAllowed)
mailTos.forEach(mailTo => {
perm.addMailTo(mailTo)
})
Expand Down Expand Up @@ -251,6 +261,7 @@ class PermissionSet {
var perm = new Permission(this.resourceUrl, this.isPermInherited())
perm.setGroup(webId)
perm.addMode(accessMode)
perm.addOrigin(this.originsAllowed)
this.addSinglePermission(perm)
return this
}
Expand All @@ -276,9 +287,8 @@ class PermissionSet {
var perm = new Permission(this.resourceUrl, this.isPermInherited())
perm.setAgent(webId)
perm.addMode(accessMode)
if (origin) {
perm.addOrigin(origin)
}
perm.addOrigin(origin)
perm.addOrigin(this.originsAllowed)
this.addSinglePermission(perm)
return this
}
Expand Down Expand Up @@ -468,8 +478,7 @@ class PermissionSet {
*/
checkOrigin (permission) {
if (!this.strictOrigin || // Enforcement turned off in server config
!this.origin || // No origin - not a script, do not enforce origin
this.origin === this.host) { // same origin is trusted
!this.origin) { // No origin - not a script, do not enforce origin
return true
}
// If not same origin, check that the origin is in the explicit ACL list
Expand Down

0 comments on commit 7d94ffa

Please sign in to comment.