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

SRI + XHTML #5742

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

SRI + XHTML #5742

wants to merge 4 commits into from

Conversation

corrideat
Copy link

@corrideat corrideat commented Apr 29, 2017

I've written a patch that does the following:

  1. Impment support for subresource requrest integrity (off by default)
  2. Fixes some of the regexes used for matching tag attributes (the current expression would match src="a'; now, it enforces that the same quotation style be used)
  3. Fixed the missing "/" at the end of tags that aren't closed, useful for XHTML compliance
  4. Added the xhtml-html5 doctype to support xhtml5


list($file) = explode('?', $path, 2);
if (!empty($file) && is_readable($file)) {
$content = @file_get_contents($this->assets_dir . $file);
Copy link
Member

Choose a reason for hiding this comment

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

Here you use assets_dir, but one line above you don't.

Copy link
Author

Choose a reason for hiding this comment

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

Fair point. I missed that.

if (!empty($file) && is_readable($file)) {
$content = @file_get_contents($this->assets_dir . $file);
if ($content !== false) {
return 'sha384-'.base64_encode(hash('sha384', $content, true));
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to check if 'hash' function exists, e.g. when you set $this->assets_sri.

Copy link
Author

Choose a reason for hiding this comment

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

Fair point.

protected function include_assets_sri($output)
{
return preg_replace_callback(
'!(src|href|background)=(["\']?)([a-z0-9/_.?=-]+)\2([\s>])?!i',
Copy link
Member

Choose a reason for hiding this comment

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

W3C specification talks only about link and script tags. Do we really want to handle all others, e.g. img?

Copy link
Author

Choose a reason for hiding this comment

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

I went this route because it was easier to implement for everything and because future browsers may support SRI in other tags. I concur that for performance reasons this might not be the best approach.

Copy link
Author

Choose a reason for hiding this comment

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

A slightly off-topic comment: the current way of implementing these features using templates (i.e., generate a document, then use regexes) seems error-prone and inefficient. I think a DOM-based (or similar) document generation approach could be more reliable and flexible (even though it's hard to say what the effect on performance may be.) Have you considered changing this?

@alecpl
Copy link
Member

alecpl commented Jun 4, 2017

Would be also add a note to defaults.inc.php about the new option and performance implications.

@corrideat
Copy link
Author

Can't seem to be able to reply to your last comment, but I added a commit that documents the option in defaults.inc.php.

if (!empty($file) && is_readable($this->assets_dir . $file)) {
$content = @file_get_contents($this->assets_dir . $file);
if ($content !== false) {
return 'sha384-'.base64_encode(hash('sha384', $content, true));
Copy link
Member

Choose a reason for hiding this comment

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

I propose to use hash_file() instead of hash() and file_get_contents().

@@ -84,6 +85,7 @@ public function __construct($task = null, $framed = false)
$this->set_env('skin', $skin);

$this->set_assets_path($this->config->get('assets_path'), $this->config->get('assets_dir'));
$this->assets_sri = $this->config->get('assets_sri') && in_array('sha384', hash_algos(), true);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to check hash_algos(), but I would check if function_exists('hash_file').

@dereks
Copy link

dereks commented Aug 20, 2020

Thank you for submitting a Pull Request (PR) to the Roundcube GitHub project.

You are receiving this message because your PR has conflicts which need to be resolved. We are trying to catch up on our backlog of old PRs and get them merged in (where appropriate). Therefor, we request the following:

Step 1. Rebase from the latest Roundcube branch master into your PR.

git fetch upstream
git checkout your_feature_branch_name
git rebase upstream/master
git push -f origin your_feature_branch_name

Step 2. Re-test to make sure your new code still works as expected

Step 3. Comment back here once it has been tested and will merge cleanly.

Once this has been done we will treat it like a new Pull Request and consider it for acceptance.

Apologies for the inconvenience. Thank you for contributing to Roundcube!

@Neustradamus
Copy link

@corrideat: Have you progressed on your PR?

@corrideat
Copy link
Author

@corrideat: Have you progressed on your PR?

@Neustradamus This is a pretty old PR that I didn't update. At the moment, I'm no longer running RC but I'll see whether I can update it or close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants