How secure is client-side HTML sanitization?


PW Kad

Lately I've been looking at Pagedown.js for the charm of using mark-down on pages instead of ugly read-only textareas.

I'm very cautious as it seems easy to trick a converted converter. I've seen some discussions about Angular.js and its html bindings, and heard a bit about html bindings being previously unsafe when Knockout.js 3.0 came out.

Seems like all one needs to do to disable sanitizers in Pagedown.js like -

var safeConverter = new Markdown.Converter();
// safeConverter is open to script injection

safeConverter = Markdown.getSanitizingConverter();
// safeConverter is now safe

// Override the getSanitizingConverter pseudo-code
Markdown.getSanitizingConverter = function () {
    return Markdown.Converter;
};

They can open a site for script injection. isn't that true

edit

So why would such a library package a sanitizer to use the client? Of course they say don't render unsanitized html, but the next line says to use Markdown.Sanitizer.

How does Angular not use the sanitizer service, or is this just a farce?

Galpak

I believe there is some misunderstanding of the purpose and nature of this "sanitizer".

The purpose of a cleaner (eg Angular's ngSanitize) is not to prevent "bad" data from being sent to the server side. Instead, here's another way: there's a sanitizer out there to protect non-malicious users from malicious data (due to security holes on the server side (yes, no setup is perfect) or obtained from other sources) (those beyond your control)).

Of course, as a client function, the sanitizer can be bypassed, but (since there are sanitizers that protect the user (not the server)), bypassing it just leaves the bypasser unprotected (you can't do anything about it) , you shouldn't care either - it's their choice).

Additionally, sanitizers can play another (possibly more important) role: sanitizers are tools that help developers better organize their code, making it easier to test certain types of vulnerabilities, such as XSS attacks ), and even help with actual code reviews for such security holes.

In my opinion, the Angular documentation summarizes the concept pretty well:

Strict Context Escape (SCE) is a pattern in which AngularJS requires binding in some context to produce a value that is marked as safe to use in that context.
[...]
SCE helps write code by: (a) being secure by default, and (b) enabling auditing for security vulnerabilities such as XSS, clickjacking, etc.becomes much easier .

[…]
In a more realistic example, one could render user comments, blog posts, etc. via bindings. (HTML is just one example of a context where rendering user-controlled input creates a security hole.)

For HTML, you can use a library on the client or server side to sanitize unsafe HTML before binding it to the value and rendering it in the document.

How do you ensure that every place you use these types of bindings is bound to a value that has been sanitized by the library (or returned to a value that is safe to render to the server)? How do you make sure you don't accidentally delete a sanitized value, or rename some property/field and forget to update the binding to the sanitized value?

To be on the safe side , by default you want to ensure that any such binding is disallowed, unless you can be sure that it is safe to bind with a value in that context . You can then audit your code (just do a simple grep) to make sure you only do this for those safe values ​​that you can easily tell - because those are received from the server, cleaned up by the library ,and many more. You can organize your own codebase to help with this - perhaps only allowing files in a specific directory to do so. Ensuring that the internal API exposed by this code doesn't mark arbitrary values ​​as safe becomes a more manageable task .

Note 1: The emphasis is mine.
Note 2: Sorry for the lengthy quote, but I think this is a very tricky thing (albeit sensitive) and is often misunderstood.

Related


How secure is client-side HTML sanitization?

PW Kad I've been looking at Pagedown.js lately in hopes of using mark-down on pages instead of ugly read-only textareas. I'm very cautious as it seems easy to trick a converted converter. I've seen some discussions about Angular.js and its html bindings, and h

How secure is client-side HTML sanitization?

PW Kad Lately I've been looking at Pagedown.js for the charm of using mark-down on pages instead of ugly read-only textareas. I'm very cautious as it seems easy to trick a converted converter. I've seen some discussions about Angular.js and its html bindings,

How secure is Firebase Cloud Messaging on the client side?

Natesh Butter It is true that firebase provides client side sdk and server side admin sdk to use Firebase Cloud Messaging. What confuses me is: We include client-side initialization code in public javascript files or script tags. Does anyone not see this initi

How secure is Firebase Cloud Messaging on the client side?

Natesh Butter It is true that firebase provides client side sdk and server side admin sdk to use Firebase Cloud Messaging. What confuses me is: We include client-side initialization code in public javascript files or script tags. Does anyone not see this initi

How secure is Firebase Cloud Messaging on the client side?

Natesh Butter It is true that firebase provides client side sdk and server side admin sdk to use Firebase Cloud Messaging. What confuses me is: We include client-side initialization code in public javascript files or script tags. Does anyone not see this initi

Client-side vs. server-side filename sanitization

Jacob When uploading files from many separate webpages and controllers, my C# backend breaks when files with HTML entities in their names are uploaded: An exception of type 'System.Web.HttpRequestValidationException' occurred in System.Web.Mvc.dll but was not

Client-side vs. server-side filename sanitization

Jacob When uploading files from many separate webpages and controllers, my C# backend breaks when files with HTML entities in their names are uploaded: An exception of type 'System.Web.HttpRequestValidationException' occurred in System.Web.Mvc.dll but was not

Client-side vs. server-side filename sanitization

Jacob When uploading files from many separate webpages and controllers, my C# backend breaks when files with HTML entities in their names are uploaded: An exception of type 'System.Web.HttpRequestValidationException' occurred in System.Web.Mvc.dll but was not

Client-side vs. server-side filename sanitization

Jacob When uploading files from many separate webpages and controllers, my C# backend breaks when files with HTML entities in their names are uploaded: An exception of type 'System.Web.HttpRequestValidationException' occurred in System.Web.Mvc.dll but was not

How secure are client-side SSL certificates in mobile apps?

Jacob Marble I want to have secure communication between my Android/iOS app and my internet access backend service, so I'm looking into HTTPS/SSL. If I create a self-signed certificate, then put the client certificate into the application, and have the backend

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How secure are client-side SSL certificates in mobile apps?

Jacob Marble I want to have secure communication between my Android/iOS app and my internet access backend service, so I'm looking into HTTPS/SSL. If I create a self-signed certificate, then put the client certificate into the application, and have the backend

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure a REST API when using Adobe AIR on the client side

Jingshan I have created a simple REST API in PHP. The client is a mobile application written in Adobe Air. Whenever I develop an API, I use HTTPS and some basic headers like X-Api-Secret, which is a mutually agreed secret. However, Adobe Air cannot send custom

How secure are client-side SSL certificates in mobile apps?

Jacob Marble I want to have secure communication between my Android/iOS app and my internet access backend service, so I'm looking into HTTPS/SSL. If I create a self-signed certificate, then put the client certificate into the application, and have the backend

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure client side of React + Redux + reactRouter app?

Andrey Rusev I am building a react + redux + reactRouter app. I have an api that sends me a token after login, so I can secure my api, but I have frontend routes (like dashboards) that should be secured. I have a login form that dispatches a login action. .../

How to secure a REST API when using Adobe AIR on the client side

Jingshan I have created a simple REST API in PHP. The client is a mobile application written in Adobe Air. Whenever I develop an API, I use HTTPS and some basic headers like X-Api-Secret, which is a mutually agreed secret. However, Adobe Air cannot send custom

How to get the html of another website on the client side?

Arturek I'm trying to write a JavaScript script that will scrape the HTML source code of another website (eg www.google.pl). I have found some solutions but none of them work. I am trying to run the following code: var url = "http://google.com/"; $.ajax({ url

How to get the html of another website on the client side?

Arturek I'm trying to write a JavaScript script that will scrape the HTML source code of another website (eg www.google.pl). I have found some solutions but none of them work. I am trying to run the following code: var url = "http://google.com/"; $.ajax({ url