Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nextcloud mail - PostGuard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Kolijn
Nextcloud mail - PostGuard
Commits
d78bfc0b
Commit
d78bfc0b
authored
9 years ago
by
Steffen Lindner
Browse files
Options
Downloads
Plain Diff
Merge pull request #1011 from owncloud/image-blocking
Image blocking
parents
a88f6b61
5a988485
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/service/html.php
+4
-1
4 additions, 1 deletion
lib/service/html.php
lib/service/htmlpurify/transformimagesrc.php
+32
-3
32 additions, 3 deletions
lib/service/htmlpurify/transformimagesrc.php
with
36 additions
and
4 deletions
lib/service/html.php
+
4
−
1
View file @
d78bfc0b
...
...
@@ -23,6 +23,7 @@ use OCA\Mail\Service\HtmlPurify\TransformImageSrc;
use
OCA\Mail\Service\HtmlPurify\TransformNoReferrer
;
use
OCA\Mail\Service\HtmlPurify\TransformURLScheme
;
use
OCP\IURLGenerator
;
use
OCP\Util
;
class
Html
{
...
...
@@ -48,6 +49,7 @@ class Html {
// allow cid, http and ftp
$config
->
set
(
'URI.AllowedSchemes'
,
[
'http'
=>
true
,
'https'
=>
true
,
'ftp'
=>
true
,
'mailto'
=>
true
]);
$config
->
set
(
'URI.Host'
,
Util
::
getServerHostName
());
// Disable the cache since ownCloud has no really appcache
// TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed
...
...
@@ -90,6 +92,7 @@ class Html {
// allow cid, http and ftp
$config
->
set
(
'URI.AllowedSchemes'
,
[
'cid'
=>
true
,
'http'
=>
true
,
'https'
=>
true
,
'ftp'
=>
true
,
'mailto'
=>
true
]);
$config
->
set
(
'URI.Host'
,
Util
::
getServerHostName
());
// Disable the cache since ownCloud has no really appcache
// TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed
...
...
@@ -97,7 +100,7 @@ class Html {
// Rewrite URL for redirection and proxying of content
$html
=
$config
->
getDefinition
(
'HTML'
);
$html
->
info_attr_transform_post
[
'imagesrc'
]
=
new
TransformImageSrc
();
$html
->
info_attr_transform_post
[
'imagesrc'
]
=
new
TransformImageSrc
(
$this
->
urlGenerator
);
$uri
=
$config
->
getDefinition
(
'URI'
);
$uri
->
addFilter
(
new
TransformURLScheme
(
$messageParameters
,
$mapCidToAttachmentId
,
$this
->
urlGenerator
),
$config
);
...
...
This diff is collapsed.
Click to expand it.
lib/service/htmlpurify/transformimagesrc.php
100644 → 100755
+
32
−
3
View file @
d78bfc0b
...
...
@@ -4,12 +4,29 @@ namespace OCA\Mail\Service\HtmlPurify;
use
HTMLPurifier_AttrTransform
;
use
HTMLPurifier_Config
;
use
HTMLPurifier_Context
;
use
HTMLPurifier_URI
;
use
HTMLPurifier_URIFilter
;
use
HTMLPurifier_URIParser
;
use
OCP\IURLGenerator
;
use
OCP\Util
;
/**
* Adds copies src to data-src on all img tags.
*/
class
TransformImageSrc
extends
HTMLPurifier_AttrTransform
{
/**
* @type HTMLPurifier_URIParser
*/
private
$parser
;
/** @var IURLGenerator */
private
$urlGenerator
;
public
function
__construct
(
IURLGenerator
$urlGenerator
)
{
$this
->
parser
=
new
HTMLPurifier_URIParser
();
$this
->
urlGenerator
=
$urlGenerator
;
}
/**
* @param array $attr
* @param HTMLPurifier_Config $config
...
...
@@ -17,13 +34,25 @@ class TransformImageSrc extends HTMLPurifier_AttrTransform {
* @return array
*/
public
function
transform
(
$attr
,
$config
,
$context
)
{
if
(
$context
->
get
(
'CurrentToken'
)
->
name
!==
'img'
||
if
(
$context
->
get
(
'CurrentToken'
)
->
name
!==
'img'
||
!
isset
(
$attr
[
'src'
]))
{
return
$attr
;
}
$attr
[
'data-original-src'
]
=
$attr
[
'src'
];
$attr
[
'src'
]
=
Util
::
imagePath
(
'mail'
,
'blocked-image.png'
);
// Block tracking pixels
if
(
isset
(
$attr
[
'width'
])
&&
isset
(
$attr
[
'height'
])
&&
(
int
)
$attr
[
'width'
]
<
5
&&
(
int
)
$attr
[
'height'
]
<
5
){
// Replace with a transparent png in case it's important for the layout
$attr
[
'src'
]
=
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABmJLR0QA/wD/AP+gvaeTAAAADUlEQVQI12NgYGBgAAAABQABXvMqOgAAAABJRU5ErkJggg=='
;
return
$attr
;
}
// Do not block images attached to the email
$url
=
$this
->
parser
->
parse
(
$attr
[
'src'
]);
if
(
$url
->
host
===
Util
::
getServerHostName
()
&&
$url
->
path
===
$this
->
urlGenerator
->
linkToRoute
(
'mail.proxy.proxy'
))
{
$attr
[
'data-original-src'
]
=
$attr
[
'src'
];
$attr
[
'src'
]
=
Util
::
imagePath
(
'mail'
,
'blocked-image.png'
);
}
return
$attr
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment