Skip to content

Commit

Permalink
allow speficying the separator when using xorigins macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alxgomz committed Oct 16, 2023
1 parent f96645f commit 5bc2be5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion roles/repository/molecule/default/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ def test_share_CSRF_config(host):
referer = share_xml.findall('{}/referer'.format(xmlpath))
origin = share_xml.findall('{}/origin'.format(xmlpath))
assert_that(referer[0].text == 'http://localhost:8080/share/.*|https://someotherapp/.*')
assert_that(origin[0].text == 'http://localhost:8080,https://someotherapp')
assert_that(origin[0].text == 'http://localhost:8080|https://someotherapp')
6 changes: 3 additions & 3 deletions roles/repository/templates/alfresco-global.properties.j2
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ dsync.service.uris={% if use_ssl | bool %}https{% else %}http{% endif %}://{% if
{% import 'xorigins_macros.j2' as _xorigins_protection %}
csrf.filter.enabled={% if csrf.enabled | bool %}true
{% if csrf.urls -%}
csrf.filter.referer={{ _xorigins_protection.compute(inventory_hostname, 'referer', csrf.urls) }}
csrf.filter.origin={{ _xorigins_protection.compute(inventory_hostname, 'origin', csrf.urls) }}
csrf.filter.referer={{ _xorigins_protection.compute(inventory_hostname, 'referer', csrf.urls, '|') }}
csrf.filter.origin={{ _xorigins_protection.compute(inventory_hostname, 'origin', csrf.urls, ',') }}
{% endif %}
csrf.filter.referer.always={{ 'true' if 'origin' in csrf.force_headers | lower else 'false' }}
csrf.filter.origin.always={{ 'true' if 'referer' in csrf.force_headers | lower else 'false' }}
Expand All @@ -72,7 +72,7 @@ csrf.filter.origin.always={{ 'true' if 'referer' in csrf.force_headers | lower e
# CORS filter overrides
cors.enabled={% if cors.enabled | bool %}true
{% if cors.urls -%}
cors.allowed.origins={{ _xorigins_protection.compute(inventory_hostname, 'origin', cors.urls) }}
cors.allowed.origins={{ _xorigins_protection.compute(inventory_hostname, 'origin', cors.urls, ',') }}
{% endif %}
cors.allowed.methods={{ cors.allowed_methods | default([]) | join(',') }}
cors.allowed.headers={{ cors.allowed_headers | default([]) | join(',') }}
Expand Down
4 changes: 2 additions & 2 deletions roles/repository/templates/share-config-custom.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@

{# Compute referers & origins -#}
{% import 'xorigins_macros.j2' as _xorigins_protection %}
<referer>{{ _xorigins_protection.compute(inventory_hostname, 'referer', csrf.urls)}}</referer>
<referer>{{ _xorigins_protection.compute(inventory_hostname, 'referer', csrf.urls, '|')}}</referer>

<!--
Override and set this property with a regexp that if you have placed Share behind a proxy that
does not rewrite the Origin header.
-->
<origin>{{ _xorigins_protection.compute(inventory_hostname, 'origin', csrf.urls)}}</origin>
<origin>{{ _xorigins_protection.compute(inventory_hostname, 'origin', csrf.urls, '|')}}</origin>
</properties>

<!--
Expand Down
6 changes: 3 additions & 3 deletions roles/repository/templates/xorigins_macros.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro compute(host, type, urls) -%}
{% macro compute(host, type, urls, separator) -%}
{% set Urlns = namespace() -%}
{% set Origins = namespace(list=[]) -%}
{% for url in urls -%}
Expand All @@ -12,8 +12,8 @@
{{ urls.append('https?://localhost') -}}
{% endif -%}
{% if type == 'origin' -%}
{{ Origins.list | unique | select() | join(',') -}}
{{ Origins.list | unique | select() | join(separator) -}}
{% elif type == 'referer' -%}
{{ urls | unique | map('trim', '/') | product(['/.*']) | map('join') | select() | join('|') -}}
{{ urls | unique | map('trim', '/') | product(['/.*']) | map('join') | select() | join(separator) -}}
{% endif -%}
{% endmacro %}

0 comments on commit 5bc2be5

Please sign in to comment.