<buttonid="sidebar-toggle"class="icon-button"type="button"title="Toggle Table of Contents"aria-label="Toggle Table of Contents"aria-controls="sidebar">
<ahref="https://github.com/matrix-org/synapse/edit/develop/docs/consent_tracking.md"title="Suggest an edit"aria-label="Suggest an edit">
<iid="git-edit-button"class="fa fa-edit"></i>
</a>
</div>
</div>
<divid="search-wrapper"class="hidden">
<formid="searchbar-outer"class="searchbar-outer">
<inputtype="search"id="searchbar"name="searchbar"placeholder="Search this book ..."aria-controls="searchresults-outer"aria-describedby="searchresults-header">
<h1id="support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions"><aclass="header"href="#support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions">Support in Synapse for tracking agreement to server terms and conditions</a></h1>
<p>Synapse 0.30 introduces support for tracking whether users have agreed to the
terms and conditions set by the administrator of a server - and blocking access
to the server until they have.</p>
<p>There are several parts to this functionality; each requires some specific
configuration in <code>homeserver.yaml</code> to be enabled.</p>
<p>Note that various parts of the configuation and this document refer to the
"privacy policy": agreement with a privacy policy is one particular use of this
feature, but of course adminstrators can specify other terms and conditions
unrelated to "privacy" per se.</p>
<h2id="collecting-policy-agreement-from-a-user"><aclass="header"href="#collecting-policy-agreement-from-a-user">Collecting policy agreement from a user</a></h2>
<p>Synapse can be configured to serve the user a simple policy form with an
"accept" button. Clicking "Accept" records the user's acceptance in the
database and shows a success page.</p>
<p>To enable this, first create templates for the policy and success pages.
These should be stored on the local filesystem.</p>
<p>These templates use the <ahref="http://jinja.pocoo.org">Jinja2</a> templating language,
and <ahref="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
gives examples of the sort of thing that can be done.</p>
<p>Note that the templates must be stored under a name giving the language of the
template - currently this must always be <code>en</code> (for "English");
internationalisation support is intended for the future.</p>
<p>The template for the policy itself should be versioned and named according to
the version: for example <code>1.0.html</code>. The version of the policy which the user
has agreed to is stored in the database.</p>
<p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
<ol>
<li>
<p>Add a <code>user_consent</code> section, which should look like:</p>
<pre><codeclass="language-yaml">user_consent:
template_dir: privacy_policy_templates
version: 1.0
</code></pre>
<p><code>template_dir</code> points to the directory containing the policy
templates. <code>version</code> defines the version of the policy which will be served
to the user. In the example above, Synapse will serve
<p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
generate suitable secrets).</p>
<p>More on what this is used for below.</p>
</li>
<li>
<p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
<code>listeners</code> configuration. For example:</p>
<pre><codeclass="language-yaml">listeners:
- port: 8008
resources:
- names:
- client
- consent
</code></pre>
</li>
</ol>
<p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
<p>Once this is complete, and the server has been restarted, try visiting
<code>https://<server>/_matrix/consent</code>. If correctly configured, this should give
an error "Missing string query parameter 'u'". It is now possible to manually
construct URIs where users can give their consent.</p>
<h3id="enabling-consent-tracking-at-registration"><aclass="header"href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
<ol>
<li>
<p>Add the following to your configuration:</p>
<pre><codeclass="language-yaml">user_consent:
require_at_registration: true
policy_name: "Privacy Policy" # or whatever you'd like to call the policy
</code></pre>
</li>
<li>
<p>In your consent templates, make use of the <code>public_version</code> variable to
see if an unauthenticated user is viewing the page. This is typically
wrapped around the form that would be used to actually agree to the document:</p>
<pre><code>{% if not public_version %}
<!-- The variables used here are only provided when the 'u' param is given to the homeserver -->
<p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
the document from an unauthenticated perspective, such as prior to registration.
Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
<h2id="sending-users-a-server-notice-asking-them-to-agree-to-the-policy"><aclass="header"href="#sending-users-a-server-notice-asking-them-to-agree-to-the-policy">Sending users a server notice asking them to agree to the policy</a></h2>
<p>It is possible to configure Synapse to send a <ahref="server_notices.html">server
notice</a> to anybody who has not yet agreed to the current
version of the policy. To do so:</p>
<ul>
<li>
<p>ensure that the consent resource is configured, as in the previous section</p>
<p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
example:</p>
<pre><codeclass="language-yaml">user_consent:
server_notice_content:
msgtype: m.text
body: >-
Please give your consent to the privacy policy at %(consent_uri)s.
</code></pre>
<p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
consent uri for that user.</p>
</li>
<li>
<p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
URI that clients use to connect to the server. (It is used to construct
<code>consent_uri</code> in the server notice.)</p>
</li>
</ul>
<h2id="blocking-users-from-using-the-server-until-they-agree-to-the-policy"><aclass="header"href="#blocking-users-from-using-the-server-until-they-agree-to-the-policy">Blocking users from using the server until they agree to the policy</a></h2>
<p>Synapse can be configured to block any attempts to join rooms or send messages
until the user has given their agreement to the policy. (Joining the server
notices room is exempted from this).</p>
<p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
<pre><codeclass="language-yaml">user_consent:
block_events_error: >-
You can't send any messages until you consent to the privacy policy at
%(consent_uri)s.
</code></pre>
<p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
consent uri for that user.</p>
<p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
URI that clients use to connect to the server. (It is used to construct