Skip to content

Commit dfa9c42

Browse files
authoredMar 15, 2022
Merge pull request #18 from mozilla-conduit/1623361
2 parents 5e61368 + 2ec77c8 commit dfa9c42

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed
 

‎Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ FROM php:7.4.19-fpm-alpine AS base
22

33
LABEL maintainer="dkl@mozilla.com"
44

5+
# From https://github.com/marco-c/risk-analysis-addon/releases
6+
ENV RISK_ANALYSIS_VERSION v0.6.0
7+
58
# These are unlikely to change from version to version of the container
69
EXPOSE 9000
710
EXPOSE 9003
@@ -125,6 +128,15 @@ COPY --chown=app nginx/ nginx/
125128
RUN chmod +x /app/update_version_json.py /app/entrypoint.sh /app/wait-for-mysql.php \
126129
&& /app/update_version_json.py
127130

131+
RUN { \
132+
echo '/**'; \
133+
echo '* @provides moz-risk-analysis-js'; \
134+
echo '* @do-not-minify'; \
135+
echo '*/'; \
136+
} | tee /app/phabricator/webroot/rsrc/js/MozillaRiskAnalysis.js
137+
RUN curl -fsSL https://raw.githubusercontent.com/marco-c/risk-analysis-addon/${RISK_ANALYSIS_VERSION}/risk_analysis.js \
138+
>> /app/phabricator/webroot/rsrc/js/MozillaRiskAnalysis.js
139+
128140
FROM base AS production
129141

130142
USER root

‎moz-extensions.conf.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
'events.listeners' => array(
88
'LandoLinkEventListener',
99
'NewChangesLinkEventListener',
10+
'RiskAnalyzerEventListener',
1011
)
1112
);

‎moz-extensions/src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'FeedQueryIDConduitAPIMethod' => 'conduit/FeedQueryIDConduitAPIMethod.php',
5858
'GroupPhabricatorReviewer' => 'email/adapter/GroupPhabricatorReviewer.php',
5959
'LandoLinkEventListener' => 'lando/events/LandoLinkEventListener.php',
60+
'RiskAnalyzerEventListener' => 'differential/events/RiskAnalyzerEventListener.php',
6061
'MinimalEmailContext' => 'email/model/MinimalEmailContext.php',
6162
'MinimalEmailRevision' => 'email/model/MinimalEmailRevision.php',
6263
'MozLogger' => 'logging/MozLogger.php',
@@ -146,6 +147,7 @@
146147
'FeedQueryIDConduitAPIMethod' => 'FeedQueryConduitAPIMethod',
147148
'GroupPhabricatorReviewer' => 'PhabricatorReviewer',
148149
'LandoLinkEventListener' => 'PhabricatorEventListener',
150+
'RiskAnalyzerEventListener' => 'PhabricatorEventListener',
149151
'MozLogger' => 'Phobject',
150152
'MozillaExtraReviewerDataSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
151153
'MozillaMOTD' => 'Phobject',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this
4+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
/**
7+
* Adds the "risk analyzer plugin" JS to the differential view
8+
*/
9+
10+
final class RiskAnalyzerEventListener extends PhabricatorEventListener {
11+
12+
public function register() {
13+
if (PhabricatorEnv::getEnvConfig('bugzilla.url') != "http://bmo.test") {
14+
// Only enable this event listener if we're not running in the local development environment
15+
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES);
16+
}
17+
}
18+
19+
public function handleEvent(PhutilEvent $event) {
20+
if ($event->getType() == PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES) {
21+
$response = CelerityAPI::getStaticResourceResponse();
22+
$response->requireResource('moz-risk-analysis-js', 'phabricator');
23+
$response->addContentSecurityPolicyURI('connect-src', 'https://community-tc.services.mozilla.com');
24+
}
25+
}
26+
}

‎nginx/site.conf

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
server {
77
server_name phabricator.test;
88
root /app/phabricator/webroot;
9-
9+
1010
location = /contribute.json {
1111
root /app;
1212
default_type application/json;
@@ -30,14 +30,14 @@ server {
3030

3131
location / {
3232
add_header X-XSS-Protection "1; mode=block";
33-
add_header Content-Security-Policy "default-src 'self' https://*.cloudfront.net data: 'unsafe-inline'; script-src 'self' https://*.cloudfront.net 'unsafe-inline'; object-src 'self'";
33+
add_header Content-Security-Policy "default-src 'self' https://*.cloudfront.net data: 'unsafe-inline'; script-src 'self' https://*.cloudfront.net 'unsafe-inline'; object-src 'self'; connect-src 'self' https://community-tc.services.mozilla.com";
3434
index index.php;
3535
rewrite ^/(.*)$ /index.php?__path__=/$1 last;
3636
}
3737

3838
location ~ \.php$ {
3939
add_header X-XSS-Protection "1; mode=block";
40-
add_header Content-Security-Policy "default-src 'self' https://*.cloudfront.net data: 'unsafe-inline'; script-src 'self' https://*.cloudfront.net 'unsafe-inline'; object-src 'self'";
40+
add_header Content-Security-Policy "default-src 'self' https://*.cloudfront.net data: 'unsafe-inline'; script-src 'self' https://*.cloudfront.net 'unsafe-inline'; object-src 'self'; connect-src 'self' https://community-tc.services.mozilla.com";
4141
include fastcgi_params;
4242
fastcgi_pass phabricator:9000;
4343
fastcgi_index index.php;

0 commit comments

Comments
 (0)
Failed to load comments.