Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
I love Markdown. I love syntax highlighting. I love oEmbed. And last but not least, I love whitelist-based HTML sanitizing. Slodown rolls all of these into one, and then some.
Here's what Slodown does by default:
Slodown is an extraction from sloblog.io. It is very easy to extend or modify, as it's just a plain old Ruby class you can inherit from.
Slodown, out of the box, implements my preferred way of handling user input, which looks like this:
This allows users to still add their own HTML, if required. In fact, I typically encourage users to make use of kramdown's inline attributes, leaving it up the sanitizer to make sure they don't go crazy.
If this is not what you want, you will most likely be able to bend Slodown to your will -- it's pretty flexible.
For every piece of user input that needs to be rendered, create an instance of Slodown::Formatter
with the source text and use it to perform some or all transformations on it. Finally, call #to_s
to get the rendered output.
# let's create an instance to work with
formatter = Slodown::Formatter.new(text)
# just extract metadata
formatter.extract_metadata.to_s
# just render Markdown to HTML
formatter.markdown.to_s
# just auto-link contained URLs
formatter.autolink.to_s
# just sanitize HTML tags
formatter.sanitize.to_s
# you can chain multiple operations
formatter.markdown.sanitize.to_s
# this is the whole deal:
formatter.extract_metadata.markdown.autolink.sanitize.to_s
# which is the same as:
formatter.complete.to_s
If you want to customize Slodown's default behavior, simply create a new class that inherits from Slodown::Formatter
and override methods like #kramdown_options
, or add your own behaviors.
Just add CodeRay or Rouge to your project to have code blocks in your Markdown syntax-highlighted. Slodown will try to detect which library you're using, but to be sure, change your kramdown_options
accordingly. For example:
class Formatter < Slodown::Formatter
def kramdown_options
{
syntax_highlighter: 'coderay',
syntax_highlighter_opts: { css: :class }
}
end
end
oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.
Slodown extends the Markdown image syntax to support oEmbed-based embeds. Anything supported by the great oEmbed gem will work. Just supply the URL:
![youtube video](https://www.youtube.com/watch?v=oHg5SJYRHA0)
Note on IFRAMEs: Some oEmbed providers will return IFRAME-based embeds. If you want to control
which hosts are allowed to have IFRAMEs on your site, override the Formatter#allowed_iframe_hosts
method to return a regular expression that will be matched against the IFRAME source URL's host. Please note that this will also apply to
IFRAME HTML tags added by the user directly.
Note on Twitter: Twitter's oEmbed endpoint will return a simple bit of markup that works okay out of the box, but can be expanded into a full tweet view client-side. For this to work, you'll want to add Twitter's widget.js to your application. Please refer to the Twitter documentation for full instructions.
Slodown allows metadata, such as the creation date, to be defined in the text to be processed:
#+title: Slodown
#+created_at: 2014-03-01 13:51:12 CET
# Installation
Add this line to your application's Gemfile:
gem 'slodown'
...
Metadata can be accessed with Slodown::Formatter#metadata
:
formatter.metadata[:title] # => "Slodown"
#complete
method, just subclass Slodown::Formatter
and go wild. :-)Slodown::Formatter
and override its #sanitize_config
method. Regarding the contents of the hash this method returns, please refer to the sanitize documentation.Just like with my other gems, I am trying to keep Slodown as sane (and small) as possible. If you want to contribute code, please talk to me before writing a patch or submitting a pull request! I'm serious about keeping things focused and would hate to cause unnecessary disappointment. Thank you.
If you're still set on submitting a pull request, please consider the following:
<figure>
structure (with optional <figcaption>
.)<figure>
, <figcaption>
, <cite>
, <mark>
, <del>
and <ins>
tags by default.Formatter#allowed_iframe_hosts
to return a regular expression that will match against the embed URL's host.Slodown::Formatter#kramdown_options
, returning a hash of kramdown configuration options. Overload this in order to customize the formatter's behavior.FAQs
Unknown package
We found that slodown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.