Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches: [master]
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: ['20', '22', '24']
name: node ${{ matrix.node-version }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

# node-rss has no runtime or dev dependencies, so this only verifies
# that the lockfile and package.json agree.
- run: npm ci

- run: npm test

audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '24'

- run: npm audit --audit-level=low
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
npm-debug.log
*.swp
*.tgz
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2012-2026 EJ Bensing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
77 changes: 61 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ None of the other node.js RSS modules that I could find supported the flexibilit

npm install node-rss

## Dependencies
## Requirements

Update (6/18/2015): This step should no longer be necessary.

node-rss uses the libxmljs library to construct the actual feed.
Unfortunately, some of the features of the library that are needed are only available in the current master branch. You will need to download the libxmljs source, compile, and install it yourself. Fortunately, this is fairly straight forward. https://github.com/polotek/libxmljs/

You will also need to have the libxml2 AND libxml2-dev packages installed on your system.
Node.js 20 or newer. node-rss has **no dependencies** - it builds the feed XML
directly, so there is no native module to compile and nothing to install beyond
the package itself.

## Usage
```javascript
// this exposes two methods: createNewFeed and getFeedXML
var rss = require('node-rss');
const rss = require('node-rss');
// ESM works too: import { createNewFeed, getFeedXML } from 'node-rss';

// first we create a "feed" object that will define your feed
// method signature: function createNewFeed(title, link, desc, author, feedLink, options)
Expand All @@ -32,7 +30,7 @@ You will also need to have the libxml2 AND libxml2-dev packages installed on you
// author : author of the feed
// feedLink : link to the feed
// options : additional options, explained below
var feed = rss.createNewFeed('Blog Most Recent', 'http://someurl.com/',
const feed = rss.createNewFeed('Blog Most Recent', 'http://someurl.com/',
'Most recent blog entries from blog',
'EJ Bensing',
'http://someurl.com/rss/MostRecent.xml',
Expand All @@ -46,7 +44,7 @@ You will also need to have the libxml2 AND libxml2-dev packages installed on you

//next, we need to add some items to the feed
// create some dummy data to loop over...
var blogs = [
const blogs = [
{title: 'blog post 1', url : 'http://someurl.com/blog1', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 2', url : 'http://someurl.com/blog2', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 3', url : 'http://someurl.com/blog3', pubDate : new Date(), description: 'this is a description' },
Expand All @@ -65,32 +63,79 @@ You will also need to have the libxml2 AND libxml2-dev packages installed on you
// description : description of item
// fields : functions exactly like the "options" parameter of createNewFeed,
// allows the user to add arbitrary tags to an item
blogs.forEach(function (blog) {
for (const blog of blogs) {
feed.addNewItem(blog.title, blog.url, blog.pubDate, blog.description, {});
});
}

// now to get the XML simply call the getFeedXML function
var xmlString = rss.getFeedXML(feed);
const xmlString = rss.getFeedXML(feed);
```
## Other

The "feed" object has a defaults property. Inside this is a dictionary of default values.

cdata : a list of tag names whose content should be "escaped" in CDATA tags

## tests
`pubDate` and `lastBuildDate` accept a `Date` and are written as RFC-1123
strings, which is the format RSS readers expect.

## Escaping and validation

node-rss escapes everything it writes, so feed content taken from user input
cannot break out of the document:

- text is XML-escaped, and CDATA-wrapped content has any `]]>` sequence split
so it cannot terminate the section early
- attribute values additionally escape quotes and literal newlines
- characters that XML 1.0 cannot represent (most control characters, unpaired
surrogates) are stripped
- tag names come from your option/field keys, and an element name cannot be
escaped - so a key that is not a valid XML name is rejected with an error,
as are keys that would overwrite the feed API (`items`, `defaults`,
`feedLink`, `addNewItem`) or the prototype chain (`__proto__`, `constructor`,
`prototype`)

In the process of building these...
## Tests

npm test

The suite runs on the built-in `node:test` runner, so there is nothing to install.

## TODO

- add tests
- add support for attributes on custom tags
- add some express.js middleware
- ?? give me suggestions

## License

MIT - see [LICENSE](LICENSE).

## Change log

Version 2.0.0

**Breaking:** requires Node.js 20 or newer.

- Removed the libxmljs dependency. It carried unpatched critical
advisories (GHSA-773h-w45w-f2f9, GHSA-mg49-jqgw-gcj6,
GHSA-6433-x5p4-8jc7, GHSA-jv72-59wq-8rxm) with no fixed version
available, and it requires a node-gyp/libxml2 native build against a
release pinned to the Node 4 era. The feed XML is now built directly,
so node-rss has zero dependencies.
- Fixed a CDATA injection: a `]]>` sequence in a title or description
could terminate the CDATA section early and inject arbitrary XML.
- Custom tag names are now validated as XML names instead of being
written verbatim, and keys that would clobber the feed API or the
prototype chain are rejected.
- Characters that XML cannot represent are stripped instead of producing
a malformed document.
- `Date` values are written as RFC-1123 (matching `lastBuildDate`) rather
than JavaScript's default date string, which is not valid in RSS.
- Added a test suite and CI across Node 20, 22 and 24.
- Relicensed under MIT and added the missing LICENSE file. Previous
releases declared a bare "BSD" with no license text included.

Version 1.0.5
- Updated libxml version to 0.15.x to support node.js 4.x (Thanks @dhendo)

Expand Down
10 changes: 5 additions & 5 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var rss = require('./../lib/node-rss.js');
const rss = require('../lib/node-rss.js');


// create the feed object
Expand All @@ -8,13 +8,13 @@ var rss = require('./../lib/node-rss.js');
// arg[3] : Author
// arg[4] : Link to Feed
// arg[5] : Options
var feed = rss.createNewFeed('Blog Most Recent', 'http://someurl.com/',
const feed = rss.createNewFeed('Blog Most Recent', 'http://someurl.com/',
'Most recent blog entries from blog',
'EJ Bensing',
'http://someurl.com/rss/MostRecent.xml', {'CustomTag' : 'This is a custom tag under the channel tag!' });

// create some dummy data to loop over...
var blogs = [
const blogs = [
{title: 'blog post 1', url : 'http://someurl.com/blog1', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 2', url : 'http://someurl.com/blog2', pubDate : new Date(), description: 'this is a description' },
{title: 'blog post 3', url : 'http://someurl.com/blog3', pubDate : new Date(), description: 'this is a description' },
Expand All @@ -24,9 +24,9 @@ var blogs = [
];

// add some items to the feed
blogs.forEach(function (blog) {
for (const blog of blogs) {
feed.addNewItem(blog.title, blog.url, blog.pubDate, blog.description, {});
});
}

// get the actual XML for the feed
console.log("RSS Content: %s", rss.getFeedXML(feed));
Loading
Loading