diff options
-rw-r--r-- | Bugzilla/CGI/Mojo.pm | 17 | ||||
-rwxr-xr-x | new.psgi | 22 | ||||
-rw-r--r-- | template/en/default/global/header.html.tmpl | 4 |
3 files changed, 42 insertions, 1 deletions
diff --git a/Bugzilla/CGI/Mojo.pm b/Bugzilla/CGI/Mojo.pm index e3adf1133..2d4f40d3e 100644 --- a/Bugzilla/CGI/Mojo.pm +++ b/Bugzilla/CGI/Mojo.pm @@ -14,6 +14,23 @@ has 'controller' => ( handles => [qw(param cookie)], ); +has 'content_security_policy' => ( + is => 'lazy', +); + +sub _build_content_security_policy { + my ($self) = @_; + my $csp = $self->controller->stash->{content_security_policy} // { Bugzilla::CGI::DEFAULT_CSP() }; + return Bugzilla::CGI::ContentSecurityPolicy->new( $csp ); +} + +sub csp_nonce { + my ($self) = @_; + + my $csp = $self->content_security_policy; + return $csp->has_nonce ? $csp->nonce : ''; +} + sub script_name { my ($self) = @_; @@ -19,6 +19,25 @@ use Try::Tiny; plugin 'PODRenderer'; +app->renderer->add_handler( + 'bugzilla' => sub { + my ( $renderer, $c, $output, $options ) = @_; + my %params; + + # Helpers + foreach my $method ( grep {m/^\w+\z/} keys %{ $renderer->helpers } ) { + my $sub = $renderer->helpers->{$method}; + $params{$method} = sub { $c->$sub(@_) }; + } + + # Stash values + $params{$_} = $c->stash->{$_} for grep {m/^\w+\z/} keys %{ $c->stash }; + $params{self} = $params{c} = $c; + Bugzilla->template->process( $options->{template}, \%params, $output ) + or die Bugzilla->template->error; + } +); + app->hook( around_dispatch => sub { my ($next, $c) = @_; @@ -36,7 +55,8 @@ app->hook( get '/' => sub { my $c = shift; my $user = Bugzilla->login(LOGIN_OPTIONAL); - $c->render( template => 'index', user => $user ); + $c->stash->{use_login_page} = 1; + $c->render( template => 'index.html.tmpl', handler => 'bugzilla', user => $user ); }; app->start; diff --git a/template/en/default/global/header.html.tmpl b/template/en/default/global/header.html.tmpl index 153137394..b286830fc 100644 --- a/template/en/default/global/header.html.tmpl +++ b/template/en/default/global/header.html.tmpl @@ -97,6 +97,10 @@ [% IF Param('utf8') %] <meta charset="UTF-8"> [% END %] + [% USE Bugzilla %] + [% IF Bugzilla.usage_mode == constants.USAGE_MODE_MOJO %] + <base href="[% urlbase FILTER html %]"> + [% END %] [% IF Bugzilla.cgi.should_block_referrer %] <meta name="referrer" content="origin"> |