# rest-protector

> Rest standard protection using validations, header controls and other things at a middleware format

Latest version **0.0.1** (published 2015-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install rest-protector
pnpm add rest-protector
yarn add rest-protector
bun add rest-protector
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-08-11 |
| First published | 2015-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marvin Frachet |
| Maintainers | skahrz |
| Keywords | rest, api, security, protection |

## Links

- npm: https://www.npmjs.com/package/rest-protector
- Repository: https://github.com/Skahrz/rest-protector
- Issues: https://github.com/Skahrz/rest-protector/issues
- npm.io page: https://npm.io/package/rest-protector

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2015-08-11

## README

Actually in development, some of the middlewares have been added and can be used as it.
Some tests will be added later.


# Securing REST API from common exploits using Express 4.x middleware

According to : [Owasp](https://www.owasp.org/index.php/REST_Security_Cheat_Sheet#Protect_against_cross-site_request_forgery)

# Authentication

Use statelessness as possible and use protocol like OAuth2.0 through [passport](http://passportjs.org/) and [oauth2orize](https://github.com/jaredhanson/oauth2orize) or neither [node-oauth2-server](https://github.com/thomseddon/node-oauth2-server).

# Whitelist allowable methods

REST API allows users to make many HTTP request with many verbs. [Here's a list of all the HTTP verbs](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html). This library allows you to restrict in a first time the global verbs allowed using this middleware :

```javascript
app.use(rp.whiteListVerbs(['get','post','put','delete']));
```

# Validate incoming content-types

"When POSTing or PUTting new data, the client will specify the Content-Type (e.g. application/xml or application/json) of the incoming data. The server should never assume the Content-Type; it should always check that the Content-Type header and the content are the same type. A lack of Content-Type header or an unexpected Content-Type header should result in the server rejecting the content with a 406 Not Acceptable response."

```javascript
app.use(rp.allowRequestContentType(['application/json']));
```
# Validate response types

"It is common for REST services to allow multiple response types (e.g. application/xml or application/json, and the client specifies the preferred order of response types by the Accept header in the request. Do NOT simply copy the Accept header to the Content-type header of the response. Reject the request (ideally with a 406 Not Acceptable response) if the Accept header does not specifically contain one of the allowable types.

Because there are many MIME types for the typical response types, it's important to document for clients specifically which MIME types should be used."

```javascript
app.use(rp.allowResponseType(['text/html']));
```


#Send security headers

"To make sure the content of a given resources is interpreted correctly by the browser, the server should always send the Content-Type header with the correct Content-Type, and preferably the Content-Type header should include a charset. The server should also send an X-Content-Type-Options: nosniff to make sure the browser does not try to detect a different Content-Type than what is actually sent (can lead to XSS).

Additionally the client should send an X-Frame-Options: deny to protect against drag'n drop clickjacking attacks in older browsers."

```javascript
app.use(rp.applyNoSniff());
```

```javascript
app.use(rp.controlXFrameOptionDenied());
```

---
_Source: https://npm.io/package/rest-protector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
