You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

713 lines
18 KiB

4 years ago
  1. Metadata-Version: 2.1
  2. Name: bleach
  3. Version: 3.0.2
  4. Summary: An easy safelist-based HTML-sanitizing tool.
  5. Home-page: https://github.com/mozilla/bleach
  6. Maintainer: Will Kahn-Greene
  7. Maintainer-email: willkg@mozilla.com
  8. License: Apache Software License
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Environment :: Web Environment
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 2
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3
  19. Classifier: Programming Language :: Python :: 3.4
  20. Classifier: Programming Language :: Python :: 3.5
  21. Classifier: Programming Language :: Python :: 3.6
  22. Classifier: Programming Language :: Python :: 3.7
  23. Classifier: Programming Language :: Python :: Implementation :: CPython
  24. Classifier: Programming Language :: Python :: Implementation :: PyPy
  25. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  26. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  27. Requires-Dist: six
  28. Requires-Dist: webencodings
  29. ======
  30. Bleach
  31. ======
  32. .. image:: https://travis-ci.org/mozilla/bleach.svg?branch=master
  33. :target: https://travis-ci.org/mozilla/bleach
  34. .. image:: https://badge.fury.io/py/bleach.svg
  35. :target: http://badge.fury.io/py/bleach
  36. Bleach is an allowed-list-based HTML sanitizing library that escapes or strips
  37. markup and attributes.
  38. Bleach can also linkify text safely, applying filters that Django's ``urlize``
  39. filter cannot, and optionally setting ``rel`` attributes, even on links already
  40. in the text.
  41. Bleach is intended for sanitizing text from *untrusted* sources. If you find
  42. yourself jumping through hoops to allow your site administrators to do lots of
  43. things, you're probably outside the use cases. Either trust those users, or
  44. don't.
  45. Because it relies on html5lib_, Bleach is as good as modern browsers at dealing
  46. with weird, quirky HTML fragments. And *any* of Bleach's methods will fix
  47. unbalanced or mis-nested tags.
  48. The version on GitHub_ is the most up-to-date and contains the latest bug
  49. fixes. You can find full documentation on `ReadTheDocs`_.
  50. :Code: https://github.com/mozilla/bleach
  51. :Documentation: https://bleach.readthedocs.io/
  52. :Issue tracker: https://github.com/mozilla/bleach/issues
  53. :IRC: ``#bleach`` on irc.mozilla.org
  54. :License: Apache License v2; see LICENSE file
  55. Reporting Bugs
  56. ==============
  57. For regular bugs, please report them `in our issue tracker
  58. <https://github.com/mozilla/bleach/issues>`_.
  59. If you believe that you've found a security vulnerability, please `file a secure
  60. bug report in our bug tracker
  61. <https://bugzilla.mozilla.org/enter_bug.cgi?assigned_to=nobody%40mozilla.org&product=Webtools&component=Bleach-security&groups=webtools-security>`_
  62. or send an email to *security AT mozilla DOT org*.
  63. For more information on security-related bug disclosure and the PGP key to use
  64. for sending encrypted mail or to verify responses received from that address,
  65. please read our wiki page at
  66. `<https://www.mozilla.org/en-US/security/#For_Developers>`_.
  67. Security
  68. ========
  69. Bleach is a security-focused library.
  70. We have a responsible security vulnerability reporting process. Please use
  71. that if you're reporting a security issue.
  72. Security issues are fixed in private. After we land such a fix, we'll do a
  73. release.
  74. For every release, we mark security issues we've fixed in the ``CHANGES`` in
  75. the **Security issues** section. We include any relevant CVE links.
  76. Installing Bleach
  77. =================
  78. Bleach is available on PyPI_, so you can install it with ``pip``::
  79. $ pip install bleach
  80. Upgrading Bleach
  81. ================
  82. .. warning::
  83. Before doing any upgrades, read through `Bleach Changes
  84. <https://bleach.readthedocs.io/en/latest/changes.html>`_ for backwards
  85. incompatible changes, newer versions, etc.
  86. Basic use
  87. =========
  88. The simplest way to use Bleach is:
  89. .. code-block:: python
  90. >>> import bleach
  91. >>> bleach.clean('an <script>evil()</script> example')
  92. u'an &lt;script&gt;evil()&lt;/script&gt; example'
  93. >>> bleach.linkify('an http://example.com url')
  94. u'an <a href="http://example.com" rel="nofollow">http://example.com</a> url
  95. Code of conduct
  96. ===============
  97. This project and repository is governed by Mozilla's code of conduct and
  98. etiquette guidelines. For more details please see the `Mozilla Community
  99. Participation Guidelines
  100. <https://www.mozilla.org/about/governance/policies/participation/>`_ and
  101. `Developer Etiquette Guidelines
  102. <https://bugzilla.mozilla.org/page.cgi?id=etiquette.html>`_.
  103. .. _html5lib: https://github.com/html5lib/html5lib-python
  104. .. _GitHub: https://github.com/mozilla/bleach
  105. .. _ReadTheDocs: https://bleach.readthedocs.io/
  106. .. _PyPI: http://pypi.python.org/pypi/bleach
  107. Bleach changes
  108. ==============
  109. Version 3.0.2 (October 11th, 2018)
  110. ----------------------------------
  111. **Security fixes**
  112. None
  113. **Backwards incompatible changes**
  114. None
  115. **Features**
  116. None
  117. **Bug fixes**
  118. * Merge ``Characters`` tokens after sanitizing them. This fixes issues in the
  119. ``LinkifyFilter`` where it was only linkifying parts of urls. (#374)
  120. Version 3.0.1 (October 9th, 2018)
  121. ---------------------------------
  122. **Security fixes**
  123. None
  124. **Backwards incompatible changes**
  125. None
  126. **Features**
  127. * Support Python 3.7. It supported Python 3.7 just fine, but we added 3.7 to
  128. the list of Python environments we test so this is now officially supported.
  129. (#377)
  130. **Bug fixes**
  131. * Fix ``list`` object has no attribute ``lower`` in ``clean``. (#398)
  132. * Fix ``abbr`` getting escaped in ``linkify``. (#400)
  133. Version 3.0.0 (October 3rd, 2018)
  134. ---------------------------------
  135. **Security fixes**
  136. None
  137. **Backwards incompatible changes**
  138. * A bunch of functions were moved from one module to another.
  139. These were moved from ``bleach.sanitizer`` to ``bleach.html5lib_shim``:
  140. * ``convert_entity``
  141. * ``convert_entities``
  142. * ``match_entity``
  143. * ``next_possible_entity``
  144. * ``BleachHTMLSerializer``
  145. * ``BleachHTMLTokenizer``
  146. * ``BleachHTMLParser``
  147. These functions and classes weren't documented and aren't part of the
  148. public API, but people read code and might be using them so we're
  149. considering it an incompatible API change.
  150. If you're using them, you'll need to update your code.
  151. **Features**
  152. * Bleach no longer depends on html5lib. html5lib==1.0.1 is now vendored into
  153. Bleach. You can remove it from your requirements file if none of your other
  154. requirements require html5lib.
  155. This means Bleach will now work fine with other libraries that depend on
  156. html5lib regardless of what version of html5lib they require. (#386)
  157. **Bug fixes**
  158. * Fixed tags getting added when using clean or linkify. This was a
  159. long-standing regression from the Bleach 2.0 rewrite. (#280, #392)
  160. * Fixed ``<isindex>`` getting replaced with a string. Now it gets escaped or
  161. stripped depending on whether it's in the allowed tags or not. (#279)
  162. Version 2.1.4 (August 16th, 2018)
  163. ---------------------------------
  164. **Security fixes**
  165. None
  166. **Backwards incompatible changes**
  167. * Dropped support for Python 3.3. (#328)
  168. **Features**
  169. None
  170. **Bug fixes**
  171. * Handle ambiguous ampersands in correctly. (#359)
  172. Version 2.1.3 (March 5th, 2018)
  173. -------------------------------
  174. **Security fixes**
  175. * Attributes that have URI values weren't properly sanitized if the
  176. values contained character entities. Using character entities, it
  177. was possible to construct a URI value with a scheme that was not
  178. allowed that would slide through unsanitized.
  179. This security issue was introduced in Bleach 2.1. Anyone using
  180. Bleach 2.1 is highly encouraged to upgrade.
  181. https://bugzilla.mozilla.org/show_bug.cgi?id=1442745
  182. **Backwards incompatible changes**
  183. None
  184. **Features**
  185. None
  186. **Bug fixes**
  187. * Fixed some other edge cases for attribute URI value sanitizing and
  188. improved testing of this code.
  189. Version 2.1.2 (December 7th, 2017)
  190. ----------------------------------
  191. **Security fixes**
  192. None
  193. **Backwards incompatible changes**
  194. None
  195. **Features**
  196. None
  197. **Bug fixes**
  198. * Support html5lib-python 1.0.1. (#337)
  199. * Add deprecation warning for supporting html5lib-python < 1.0.
  200. * Switch to semver.
  201. Version 2.1.1 (October 2nd, 2017)
  202. ---------------------------------
  203. **Security fixes**
  204. None
  205. **Backwards incompatible changes**
  206. None
  207. **Features**
  208. None
  209. **Bug fixes**
  210. * Fix ``setup.py`` opening files when ``LANG=``. (#324)
  211. Version 2.1 (September 28th, 2017)
  212. ----------------------------------
  213. **Security fixes**
  214. * Convert control characters (backspace particularly) to "?" preventing
  215. malicious copy-and-paste situations. (#298)
  216. See `<https://github.com/mozilla/bleach/issues/298>`_ for more details.
  217. This affects all previous versions of Bleach. Check the comments on that
  218. issue for ways to alleviate the issue if you can't upgrade to Bleach 2.1.
  219. **Backwards incompatible changes**
  220. * Redid versioning. ``bleach.VERSION`` is no longer available. Use the string
  221. version at ``bleach.__version__`` and parse it with
  222. ``pkg_resources.parse_version``. (#307)
  223. * clean, linkify: linkify and clean should only accept text types; thank you,
  224. Janusz! (#292)
  225. * clean, linkify: accept only unicode or utf-8-encoded str (#176)
  226. **Features**
  227. **Bug fixes**
  228. * ``bleach.clean()`` no longer unescapes entities including ones that are missing
  229. a ``;`` at the end which can happen in urls and other places. (#143)
  230. * linkify: fix http links inside of mailto links; thank you, sedrubal! (#300)
  231. * clarify security policy in docs (#303)
  232. * fix dependency specification for html5lib 1.0b8, 1.0b9, and 1.0b10; thank you,
  233. Zoltán! (#268)
  234. * add Bleach vs. html5lib comparison to README; thank you, Stu Cox! (#278)
  235. * fix KeyError exceptions on tags without href attr; thank you, Alex Defsen!
  236. (#273)
  237. * add test website and scripts to test ``bleach.clean()`` output in browser;
  238. thank you, Greg Guthe!
  239. Version 2.0 (March 8th, 2017)
  240. -----------------------------
  241. **Security fixes**
  242. * None
  243. **Backwards incompatible changes**
  244. * Removed support for Python 2.6. #206
  245. * Removed support for Python 3.2. #224
  246. * Bleach no longer supports html5lib < 0.99999999 (8 9s).
  247. This version is a rewrite to use the new sanitizing API since the old
  248. one was dropped in html5lib 0.99999999 (8 9s).
  249. If you're using 0.9999999 (7 9s) upgrade to 0.99999999 (8 9s) or higher.
  250. If you're using 1.0b8 (equivalent to 0.9999999 (7 9s)), upgrade to 1.0b9
  251. (equivalent to 0.99999999 (8 9s)) or higher.
  252. * ``bleach.clean`` and friends were rewritten
  253. ``clean`` was reimplemented as an html5lib filter and happens at a different
  254. step in the HTML parsing -> traversing -> serializing process. Because of
  255. that, there are some differences in clean's output as compared with previous
  256. versions.
  257. Amongst other things, this version will add end tags even if the tag in
  258. question is to be escaped.
  259. * ``bleach.clean`` and friends attribute callables now take three arguments:
  260. tag, attribute name and attribute value. Previously they only took attribute
  261. name and attribute value.
  262. All attribute callables will need to be updated.
  263. * ``bleach.linkify`` was rewritten
  264. ``linkify`` was reimplemented as an html5lib Filter. As such, it no longer
  265. accepts a ``tokenizer`` argument.
  266. The callback functions for adjusting link attributes now takes a namespaced
  267. attribute.
  268. Previously you'd do something like this::
  269. def check_protocol(attrs, is_new):
  270. if not attrs.get('href', '').startswith('http:', 'https:')):
  271. return None
  272. return attrs
  273. Now it's more like this::
  274. def check_protocol(attrs, is_new):
  275. if not attrs.get((None, u'href'), u'').startswith(('http:', 'https:')):
  276. # ^^^^^^^^^^^^^^^
  277. return None
  278. return attrs
  279. Further, you need to make sure you're always using unicode values. If you
  280. don't then html5lib will raise an assertion error that the value is not
  281. unicode.
  282. All linkify filters will need to be updated.
  283. * ``bleach.linkify`` and friends had a ``skip_pre`` argument--that's been
  284. replaced with a more general ``skip_tags`` argument.
  285. Before, you might do::
  286. bleach.linkify(some_text, skip_pre=True)
  287. The equivalent with Bleach 2.0 is::
  288. bleach.linkify(some_text, skip_tags=['pre'])
  289. You can skip other tags, too, like ``style`` or ``script`` or other places
  290. where you don't want linkification happening.
  291. All uses of linkify that use ``skip_pre`` will need to be updated.
  292. **Changes**
  293. * Supports Python 3.6.
  294. * Supports html5lib >= 0.99999999 (8 9s).
  295. * There's a ``bleach.sanitizer.Cleaner`` class that you can instantiate with your
  296. favorite clean settings for easy reuse.
  297. * There's a ``bleach.linkifier.Linker`` class that you can instantiate with your
  298. favorite linkify settings for easy reuse.
  299. * There's a ``bleach.linkifier.LinkifyFilter`` which is an htm5lib filter that
  300. you can pass as a filter to ``bleach.sanitizer.Cleaner`` allowing you to clean
  301. and linkify in one pass.
  302. * ``bleach.clean`` and friends can now take a callable as an attributes arg value.
  303. * Tons of bug fixes.
  304. * Cleaned up tests.
  305. * Documentation fixes.
  306. Version 1.5 (November 4th, 2016)
  307. --------------------------------
  308. **Security fixes**
  309. * None
  310. **Backwards incompatible changes**
  311. * clean: The list of ``ALLOWED_PROTOCOLS`` now defaults to http, https and
  312. mailto.
  313. Previously it was a long list of protocols something like ed2k, ftp, http,
  314. https, irc, mailto, news, gopher, nntp, telnet, webcal, xmpp, callto, feed,
  315. urn, aim, rsync, tag, ssh, sftp, rtsp, afs, data. #149
  316. **Changes**
  317. * clean: Added ``protocols`` to arguments list to let you override the list of
  318. allowed protocols. Thank you, Andreas Malecki! #149
  319. * linkify: Fix a bug involving periods at the end of an email address. Thank you,
  320. Lorenz Schori! #219
  321. * linkify: Fix linkification of non-ascii ports. Thank you Alexandre, Macabies!
  322. #207
  323. * linkify: Fix linkify inappropriately removing node tails when dropping nodes.
  324. #132
  325. * Fixed a test that failed periodically. #161
  326. * Switched from nose to py.test. #204
  327. * Add test matrix for all supported Python and html5lib versions. #230
  328. * Limit to html5lib ``>=0.999,!=0.9999,!=0.99999,<0.99999999`` because 0.9999
  329. and 0.99999 are busted.
  330. * Add support for ``python setup.py test``. #97
  331. Version 1.4.3 (May 23rd, 2016)
  332. ------------------------------
  333. **Security fixes**
  334. * None
  335. **Changes**
  336. * Limit to html5lib ``>=0.999,<0.99999999`` because of impending change to
  337. sanitizer api. #195
  338. Version 1.4.2 (September 11, 2015)
  339. ----------------------------------
  340. **Changes**
  341. * linkify: Fix hang in linkify with ``parse_email=True``. #124
  342. * linkify: Fix crash in linkify when removing a link that is a first-child. #136
  343. * Updated TLDs.
  344. * linkify: Don't remove exterior brackets when linkifying. #146
  345. Version 1.4.1 (December 15, 2014)
  346. ---------------------------------
  347. **Changes**
  348. * Consistent order of attributes in output.
  349. * Python 3.4 support.
  350. Version 1.4 (January 12, 2014)
  351. ------------------------------
  352. **Changes**
  353. * linkify: Update linkify to use etree type Treewalker instead of simpletree.
  354. * Updated html5lib to version ``>=0.999``.
  355. * Update all code to be compatible with Python 3 and 2 using six.
  356. * Switch to Apache License.
  357. Version 1.3
  358. -----------
  359. * Used by Python 3-only fork.
  360. Version 1.2.2 (May 18, 2013)
  361. ----------------------------
  362. * Pin html5lib to version 0.95 for now due to major API break.
  363. Version 1.2.1 (February 19, 2013)
  364. ---------------------------------
  365. * ``clean()`` no longer considers ``feed:`` an acceptable protocol due to
  366. inconsistencies in browser behavior.
  367. Version 1.2 (January 28, 2013)
  368. ------------------------------
  369. * ``linkify()`` has changed considerably. Many keyword arguments have been
  370. replaced with a single callbacks list. Please see the documentation for more
  371. information.
  372. * Bleach will no longer consider unacceptable protocols when linkifying.
  373. * ``linkify()`` now takes a tokenizer argument that allows it to skip
  374. sanitization.
  375. * ``delinkify()`` is gone.
  376. * Removed exception handling from ``_render``. ``clean()`` and ``linkify()`` may
  377. now throw.
  378. * ``linkify()`` correctly ignores case for protocols and domain names.
  379. * ``linkify()`` correctly handles markup within an <a> tag.
  380. Version 1.1.5
  381. -------------
  382. Version 1.1.4
  383. -------------
  384. Version 1.1.3 (July 10, 2012)
  385. -----------------------------
  386. * Fix parsing bare URLs when parse_email=True.
  387. Version 1.1.2 (June 1, 2012)
  388. ----------------------------
  389. * Fix hang in style attribute sanitizer. (#61)
  390. * Allow ``/`` in style attribute values.
  391. Version 1.1.1 (February 17, 2012)
  392. ---------------------------------
  393. * Fix tokenizer for html5lib 0.9.5.
  394. Version 1.1.0 (October 24, 2011)
  395. --------------------------------
  396. * ``linkify()`` now understands port numbers. (#38)
  397. * Documented character encoding behavior. (#41)
  398. * Add an optional target argument to ``linkify()``.
  399. * Add ``delinkify()`` method. (#45)
  400. * Support subdomain whitelist for ``delinkify()``. (#47, #48)
  401. Version 1.0.4 (September 2, 2011)
  402. ---------------------------------
  403. * Switch to SemVer git tags.
  404. * Make ``linkify()`` smarter about trailing punctuation. (#30)
  405. * Pass ``exc_info`` to logger during rendering issues.
  406. * Add wildcard key for attributes. (#19)
  407. * Make ``linkify()`` use the ``HTMLSanitizer`` tokenizer. (#36)
  408. * Fix URLs wrapped in parentheses. (#23)
  409. * Make ``linkify()`` UTF-8 safe. (#33)
  410. Version 1.0.3 (June 14, 2011)
  411. -----------------------------
  412. * ``linkify()`` works with 3rd level domains. (#24)
  413. * ``clean()`` supports vendor prefixes in style values. (#31, #32)
  414. * Fix ``linkify()`` email escaping.
  415. Version 1.0.2 (June 6, 2011)
  416. ----------------------------
  417. * ``linkify()`` supports email addresses.
  418. * ``clean()`` supports callables in attributes filter.
  419. Version 1.0.1 (April 12, 2011)
  420. ------------------------------
  421. * ``linkify()`` doesn't drop trailing slashes. (#21)
  422. * ``linkify()`` won't linkify 'libgl.so.1'. (#22)