<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>VN DEV PRO</title>
    <description>Chia sẻ và cập nhật về Software Development</description>
    <link>http://vndevpro.github.io</link>
    <atom:link href="http://vndevpro.github.io/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Ngăn chặn XSS trong ASP.NET</title>
        <description>&lt;p&gt;Làm thế nào để ngăn chặn XSS attack trong ứng dụng trên nền tảng ASP.NET ?
ASP.NET cung cấp sẵn những khả năng này và chúng ta có thể tùy biến nó theo yêu cầu của ứng dụng.
Bài viết này giới thiệu các steps đảm bảo input từ người dùng là an toàn cho ứng dụng.&lt;/p&gt;

&lt;h2 id=&quot;giao-diện-nhập-cơ-bản&quot;&gt;Giao diện nhập cơ bản&lt;/h2&gt;

&lt;p&gt;Trong form này có 2 trường cơ bản, một trường &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt; cho phép nhập freetext, và một trường số.
Khi &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt; không chứa mã HTML, form như sau:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/normal-input.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;nhập-message-có-mã-html&quot;&gt;Nhập Message có mã HTML&lt;/h2&gt;

&lt;p&gt;Giả sử yêu cầu của ứng dụng là cho phép user nhập “rich text”, ví dụ:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/html-input-allowhtml.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;ASP.NET kiểm tra dữ nhiệu submit lên server và blocks request&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/html-submit-exception.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;tùy-biến-để-cho-phép-server-chấp-nhận-rich-text-html&quot;&gt;Tùy biến để cho phép server chấp nhận rich text HTML&lt;/h2&gt;

&lt;p&gt;Có 2 lựa chọn cho phép làm việc này: sử dụng attribute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowHtml&lt;/code&gt; hoặc &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ValidationInput&lt;/code&gt;,
nhưng lựa chọn #2 sẽ turn-off validation trên server. Vì vậy nên lựa chọn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowHtml&lt;/code&gt; trong nhiều trường hợp có hiệu quả hơn.
&lt;a href=&quot;https://github.com/vndevpro/mvc-xss/commit/fa82bf31ddcc8c9fd4d12d7d026177f6a1fe759e&quot;&gt;(xem thay đổi)&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[AllowHtml]
public string Message { get; set; }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Kết quả sẽ là&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/html-input-allowhtml.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;khả-năng-bị-tấn-công-xss&quot;&gt;Khả năng bị tấn công XSS&lt;/h2&gt;

&lt;p&gt;Việc cho phép mã JavaScript được nhập vào ứng dụng có nguy cơ bị tấn công XSS.&lt;/p&gt;

&lt;p&gt;Trên Chrome V45, trình duyệt hiểu và ngăn chặn được nguy cơ này.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/chrome(version45)-protect-us.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Nhưng trên các trình duyệt khác thì không. Hơn nữa ứng dụng phía server cần xử lý được rủi ro này&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/firefox-doesnt-protect-us.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;xử-lý-trên-server&quot;&gt;Xử lý trên server&lt;/h2&gt;

&lt;h3 id=&quot;solution-1&quot;&gt;Solution 1&lt;/h3&gt;

&lt;p&gt;Việc xử lý thực hiện trên từng trường dữ liệu có nguy cơ bị XSS&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Cài Package &lt;a href=&quot;https://www.nuget.org/packages/AntiXss/&quot;&gt;AntiXSS&lt;/a&gt; vào ứng dụng&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Gọi function xử lý trường nhập dữ liệu chứa mã HTML, các thẻ HTML không an toàn sẽ bị loại bỏ. &lt;a href=&quot;https://github.com/vndevpro/mvc-xss/commit/170d81324b46e47ca3d67852060d40396716ebf0?diff=unified&quot;&gt;(xem thay đổi)&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var safeHtml = Sanitizer.GetSafeHtmlFragment(item.Message);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/xss/safe-html.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;solution-2&quot;&gt;Solution 2&lt;/h3&gt;

&lt;p&gt;Xử lý một cách tự động thông qua một ModelBinder&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Cài package &lt;a href=&quot;https://www.nuget.org/packages/RabbitWebMvc/&quot;&gt;RabbitWebMvc&lt;/a&gt; vào ứng dụng&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Sử dụng &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DefaultBinder&lt;/code&gt; là &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SafeHtmlModelBinder&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ModelBinders.Binders.DefaultBinder = new SafeHtmlModelBinder();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://lockmedown.com/preventing-xss-in-asp-net-made-easy/&quot;&gt;Preventing XSS in ASP.NET Made Easy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project_.NET&quot;&gt;OWASP AntiSamy Project .NET&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Mon, 19 Oct 2015 00:00:00 +0000</pubDate>
        <link>http://vndevpro.github.io/Prevent-xss-aspnet/</link>
        <guid isPermaLink="true">http://vndevpro.github.io/Prevent-xss-aspnet/</guid>
      </item>
    
      <item>
        <title>Domain Driven Design - resources?</title>
        <description>&lt;p&gt;Bài viết này sẽ chia sẻ thông tin các bài viết về DDD, các bạn nên xem phản hồi của cá nhân mình
để tham khảo lựa chọn nên đọc bài viết / sách nào trước.&lt;/p&gt;

&lt;p&gt;##1. &lt;a href=&quot;https://vaughnvernon.co/?p=879&quot;&gt;Modeling Aggregates with DDD and Entity Framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bài viết có chứa nhiều links khác nêu chi tiết về mỗi định nghĩa, quy tắc khi thiết kế theo DDD.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
</description>
        <pubDate>Thu, 13 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://vndevpro.github.io/DDD-resources/</link>
        <guid isPermaLink="true">http://vndevpro.github.io/DDD-resources/</guid>
      </item>
    
      <item>
        <title>Tại sao nên sử dụng CDN?</title>
        <description>&lt;p&gt;Tăng tốc độ load của page, giảm tải &amp;amp; băng thông cho server, giảm số concurrent reuqests đến server
là một số benifits của việc dùng CDN cho script, css, image…&lt;/p&gt;

&lt;p&gt;##Lợi ích khi sử dụng CDN&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tăng tốc độ load của page, vì CDN được sử dụng bởi nhiều website nên có thể browser đã cache file
và không phải tải lại.&lt;/li&gt;
  &lt;li&gt;Giảm tải &amp;amp; băng thông cho server của ứng dụng.&lt;/li&gt;
  &lt;li&gt;Giảm số concurrent reuqests đến server, trình duyệt giới hạn số kết nối đồng thời đến một hostname
là 6 hoặc 7, request khác được xử lý nhanh hơn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;##Coding với ASP.NET MVC&lt;/p&gt;

&lt;p&gt;Khi add thêm một bundle, thêm url của CDN và ASP.NET Bundle sẽ sử dụng url này để reference khi
website được config sang chế độ production (&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/cdn-code-01.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/cdn-code-02.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;http://www.asp.net/ajax/cdn&lt;/li&gt;
  &lt;li&gt;http://www.dotnetjalps.com/2014/07/cdn-in-aspnet-mvc-bundling.html&lt;/li&gt;
  &lt;li&gt;http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Thu, 06 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://vndevpro.github.io/Using-cdn/</link>
        <guid isPermaLink="true">http://vndevpro.github.io/Using-cdn/</guid>
      </item>
    
      <item>
        <title>Xóa files / folders trên windows một cách nhanh nhất</title>
        <description>&lt;p&gt;Trong trường hợp cần xóa nhiều folder theo một pattern nào đó, với cấu trúc folder phức tạp,
có thể dùng cách sau để xóa nhanh.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;D:\Build&amp;gt;for /d /r . %d in (bin\release) do @if exist &quot;%d&quot; rd /s/q &quot;%d&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Tham số &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bin\release&lt;/code&gt; : pattern của thư mục cần xóa.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Dấu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&lt;/code&gt; sau &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/d /r&lt;/code&gt; : thư mục hiện tại.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;references&quot;&gt;&lt;em&gt;References&lt;/em&gt;&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/521382/command-line-tool-to-delete-folder-with-a-specified-name-recursively-in-windows&quot;&gt;A question on SO&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Mon, 03 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://vndevpro.github.io/Cleanup-commands/</link>
        <guid isPermaLink="true">http://vndevpro.github.io/Cleanup-commands/</guid>
      </item>
    
      <item>
        <title>Cú pháp Markdown / HTML &amp; ví dụ</title>
        <description>&lt;p&gt;Một số cú pháp cơ bản của markdown: tạo list, format chữ, chèn ảnh…&lt;/p&gt;

&lt;h1 id=&quot;hiển-thị-một-danh-sách&quot;&gt;Hiển thị một danh sách&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/markdown-list.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;format-chữ&quot;&gt;Format chữ&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/markdown-formatting.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;tạo-hyperlink&quot;&gt;Tạo hyperlink&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/markdown-link.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;tạo-blockquote&quot;&gt;Tạo blockquote&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/markdown-highlight.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For detail, &lt;a href=&quot;https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet&quot;&gt;go there&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;tạo-ảnh--link&quot;&gt;Tạo ảnh &amp;amp; link&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/images/posts/markdown-img-link.png&quot; alt=&quot;_config.yml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Hiển thị sẽ là:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://manage.digistar.vn/aff.php?aff=432&quot;&gt;&lt;img src=&quot;https://www.digistar.vn/wp-content/uploads/2015/03/CLOUD-HOSTING-320x50.png?e631d1&quot; alt=&quot;* Cloud hosting&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.cloudrino.net/?ref=4840&quot;&gt;&lt;img src=&quot;https://raw.githubusercontent.com/netvietdev/aspnetmvc4-minimal/master/images/free-cloud-server.jpg&quot; alt=&quot;* Free Cloud Server&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;http://meta.stackexchange.com/questions/2133/whats-the-recommended-syntax-for-an-image-with-a-link&quot;&gt;What’s the recommended syntax for an image with a link?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://guides.github.com/features/mastering-markdown/&quot;&gt;Mastering Markdown&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
        <pubDate>Thu, 30 Jul 2015 00:00:00 +0000</pubDate>
        <link>http://vndevpro.github.io/How-to-use-Markdown/</link>
        <guid isPermaLink="true">http://vndevpro.github.io/How-to-use-Markdown/</guid>
      </item>
    
  </channel>
</rss>