Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5852: Created a new layout for error pages to prevent leak data #2106

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bundle/Resources/encore/ez.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ if (fs.existsSync(fieldTypesPath)) {

module.exports = (Encore) => {
Encore.addEntry('ezplatform-admin-ui-layout-js', layout)
.addEntry('ezplatform-admin-ui-error-page-js', [
path.resolve(__dirname, '../public/js/scripts/admin.error.page.js'),
])
.addEntry('ezplatform-admin-ui-bookmark-list-js', [
path.resolve(__dirname, '../public/js/scripts/button.state.toggle.js'),
path.resolve(__dirname, '../public/js/scripts/button.content.edit.js'),
Expand Down
35 changes: 35 additions & 0 deletions src/bundle/Resources/public/js/scripts/admin.error.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function(doc) {
const notificationsContainer = doc.querySelector('.ez-notifications-container');
const notifications = JSON.parse(notificationsContainer.dataset.notifications);
const template = notificationsContainer.dataset.template;

const escapeHTML = (string) => {
const stringTempNode = doc.createElement('div');

stringTempNode.appendChild(doc.createTextNode(string));

return stringTempNode.innerHTML;
};

const addNotification = ({ detail }) => {
const { label, message } = detail;
const templateLabel = label === 'error' ? 'danger' : label;
const container = doc.createElement('div');
let finalMessage = escapeHTML(message);

const notification = template
.replace('{{ label }}', templateLabel)
.replace('{{ message }}', finalMessage)
.replace('{{ badge }}', label);

container.insertAdjacentHTML('beforeend', notification);

const notificationNode = container.querySelector('.alert');

notificationsContainer.append(notificationNode);
};

Object.entries(notifications).forEach(([label, messages]) => {
messages.forEach((message) => addNotification({ detail: { label, message } }));
});
})(window.document);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends '@ezdesign/ui/layout.html.twig' %}

{% block navigation %}{% endblock %}
{% extends '@ezdesign/ui/layout_error.html.twig' %}

{% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{% extends '@ezdesign/ui/layout.html.twig' %}

{% block navigation %}
{% if ez_admin_ui_config.user.user is not empty %}
{{ parent() }}
{% endif %}
{% endblock %}
{% extends '@ezdesign/ui/layout_error.html.twig' %}

{% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends '@ezdesign/ui/layout.html.twig' %}

{% block navigation %}{% endblock %}
{% extends '@ezdesign/ui/layout_error.html.twig' %}

{% block body_class %}ez-has-no-sidebars ez-error-site{% endblock %}

Expand Down
47 changes: 47 additions & 0 deletions src/bundle/Resources/views/themes/admin/ui/layout_error.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="{{ app.request.locale }}">
<head>
<meta charset="UTF-8" />
{% block meta %}
{% endblock %}
{% if app.request.locale == 'ach_UG' %}
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', 'ezplatform']);
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT COMMIT, just an example

Suggested change
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
<script type="text/javascript" src="//cdn.crowdin.com/version-x.y.z/jipt/jipt.js" integrity="sha384-ye83f7h4...etc"></script>

So this alert is not from this PR, but I'm trying to resolve it anyway. The subresource integrity check makes sense here. Making the hash is easy. But we need to lock it to a specific version of the JS code, so it doesn't break on the next update. I haven't yet found how crowdin would specify the version.
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#tools_for_generating_sri_hashes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: This should not hold up this PR - but please look into it as a follow-up, if merged without a fix for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glye I asked Crowdin about this and here is an answer:

"The team told me that we don’t have versions of jipt.js. Bug fixes or new features may be introduced to the file"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That's unfortunate. The only way to secure it is to bundle it, then, and ensure we update it during release cycles.

Anyway, this problem should not block this PR since it's pre-existing.

{% endif %}
<title>{% block title %}Ibexa DXP{% endblock %}</title>
{{ encore_entry_link_tags('ezplatform-admin-ui-layout-css', null, 'ezplatform') }}
<script src="{{ asset('bundles/ezplatformadminuiassets/vendors/jquery/dist/jquery.min.js') }}"></script>
<script src="{{ asset('bundles/ezplatformadminuiassets/vendors/bootstrap/dist/js/bootstrap.min.js') }}"></script>

{% block stylesheets %}{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('bundles/ezplatformadminui/img/favicon.ico') }}" />
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('bundles/ezplatformadminui/img/favicon-16x16.png') }}" />
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('bundles/ezplatformadminui/img/favicon-32x32.png') }}" />

</head>
<body class="{% block body_class %}{% endblock %}">
<div class="container-fluid ez-main-container">
{% block content %}
{% endblock content %}
</div>

{% block footer %}
{% include '@ezdesign/ui/footer.html.twig' %}
{% endblock %}

<div
class="ez-notifications-container"
data-notifications="{{ app.flashes|json_encode() }}"
data-template="{{ include('@ezdesign/ui/notification.html.twig', {
label: '{{ label }}',
message: '{{ message }}',
badge: '{{ badge }}'
})|e('html_attr') }}"></div>

{{ encore_entry_script_tags('ezplatform-admin-ui-error-page-js', null, 'ezplatform') }}
{{ ez_render_component_group('stylesheet-body') }}
</body>
</html>