/sgso

Primary LanguageJavaScript

SG Spots

At a time of unprecedented distancing, this web application aims to connect users by promoting famous SG spots all around Singapore. Favorite stargazing spots? You got it! Famous carpool routes? You got it too!

Table of Contents (To be updated)


API-Design

The project has adopted the REST architectural style.

Read this if you are unclear what exactly is a REST API

A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.

Source: https://www.redhat.com/en/topics/api/what-is-a-rest-api

In general, the API is expected to follow the following guidelines:

  1. The API should be separated into logical resources.

    • Tours, Reviews, Users etc.
  2. Exposed structured, resource-based URLs.

    • {API_URL}/api/v1/users/:id/address/:address
  3. Data transfer via HTTP Methods

    • GET, POST, PATCH, DELETE
  4. Send data is JSON Format

  5. Be stateless

    • All state is handled on the client. This means that each request should contain all the information necessary in order to process a certain request. The API should have to remember previous requests.
    • implemented within application: LoggedIn, Paginate

Security_Best_Practices

  1. Compromised Database

    • Strongly encrypt passwords with salt and hash (bcrypt)
    • Strongly encrypt password reset tokens
  2. Brute force Attacks

    • Use bcrypt to make login requests slow
    • Implemented rate limiting
  3. Cross-site scripting attacks

    • Store JWT in HTTPOnly cookies
    • Sanitize user input data
    • Set special HTTP headers (helmet package)
  4. Denial of Service Attack

    • Implemented rate limiting
    • Limit body payload
    • Avoid evil regular expressions
  5. NoSQL Query Injection

    • Use mongoose for MongoDB (because of SchemaTypes)
    • Sanitize user input data
  6. OTHER BEST PRACTICES

    • Always use HTTPS
    • Create random password reset tokens with expiry dates
    • Deny access to JWT after password change
    • Don’t commit sensitive config data to Git
    • Don’t send error details to clients
    • Prevent parameter pollution causing Uncaught Exception

Future-Features

  1. Currently exploring application integration with Stripe for payment services.
  2. Plans to build frontend with HTML and SASS, and convert it into a Pug template.
  3. Implement advanced authentication features: confirm user email, keep users logged in with refresh tokens, 2FA etc.
  • Security Suggestions:
    • Prevent Cross-Site Request Forgery (csurf package)
    • Require re-authentication before a high-value action
    • Implement a blacklist of untrusted JWT
    • Confirm user email address after first creating account
    • Keep user logged in with refresh tokens
    • Implement two-factor authentication
    • Implement maximum login attempts

EnvironmentConfig

Environment Configuration for the project.

NODE_ENV=development
PORT=3000

DATABASE_PASSWORD=
DATABASE=
DATABASE_LOCAL=

JWT_SECRET=
JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90

EMAIL_USERNAME=
EMAIL_PASSWORD=
EMAIL_HOST=
EMAIL_PORT=

EMAIL_FROM=zxun2000@gmail.com

SENDGRID_USERNAME=apikey
SENDGRID_PASSWORD=

STRIPE_SECRET_KEY=

Dependencies

Dependencies for the project are stated below:

"dependencies"{
 "@babel/polyfill": "^7.12.1",
 "axios": "^0.21.1",
 "bcryptjs": "^2.4.3",
 "cookie-parser": "^1.4.5",
 "core-js": "^3.6.4",
 "dotenv": "^10.0.0",
 "express": "^4.17.1",
 "express-csp": "^0.1.3",
 "express-mongo-sanitize": "^2.1.0",
 "express-rate-limit": "^5.3.0",
 "helmet": "^4.6.0",
 "hpp": "^0.2.3",
 "html-to-text": "^8.0.0",
 "jsonwebtoken": "^8.5.1",
 "mapbox-gl": "^2.4.0",
 "mongoose": "^5.13.3",
 "morgan": "^1.10.0",
 "multer": "^1.4.2",
 "nodemailer": "^6.6.3",
 "pug": "^3.0.2",
 "regenerator-runtime": "^0.13.7",
 "sharp": "^0.28.3",
 "slugify": "^1.6.0",
 "stripe": "^8.168.0",
 "validator": "^13.6.0",
 "xss-clean": "^0.1.1"
 },

Slugify

A URL slug is a part that comes at the very end of a URL and is the exact address of a specific page on your website. For example - in https://slugify.online/campaign-url-builder URL, "campaign-url-builder" is a slug. Composing a short but descriptive slug for a URL of the web page can positively affect your page's SEO. For more information

Validators

A library of string validators and sanitizers.

For more information

Bcrypt

A library to help you hash passwords.

You can read about bcrypt in Wikipedia as well as in the following article: How To Safely Store A Password

For more information

Crypto

JavaScript library of crypto standards.

For more information

Nodemailer

Send e-mails from Node.js – easy as cake! 🍰✉️

For more information

HTMLtoText

Advanced converter that parses HTML and returns beautiful text.

For more information

Pug

Full documentation is at pugjs.org

Pug is a high performance template engine heavily influenced by Haml and implemented with JavaScript for Node.js and browsers. For bug reports, feature requests and questions, open an issue. For discussion join the chat room.

You can test drive Pug online here.

Express

Fast, unopinionated, minimalist web framework for node.

For more information

Morgan

HTTP request logger middleware for node.js

For more information

Express-rate-limit

Basic rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.

Plays nice with express-slow-down.

For more information

Helmet

Helmet helps you secure your Express apps by setting various HTTP headers. It's not a silver bullet, but it can help!

For more information

Express-Mongo-Sanitize

Express 4.x middleware which sanitizes user-supplied data to prevent MongoDB Operator Injection.

For more information

Hyperparameters-pollution

Express middleware to protect against HTTP Parameter Pollution attacks

For more information

XSS

Node.js Connect middleware to sanitize user input coming from POST body, GET queries, and url params. Works with Express, Restify, or any other Connect app.

For more information

Path

The path module provides utilities for working with file and directory paths. Documentation

Cookie-parser

Parse Cookie header and populate req.cookies with an object keyed by the cookie names. Optionally you may enable signed cookie support by passing a secret string, which assigns req.secret so it may be used by other middleware.

For more information

Dotenv

Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.

For more information

JsonWebToken

An implementation of JSON Web Tokens.

This was developed against draft-ietf-oauth-json-web-token-08. It makes use of node-jws

For more information

Util

This implements the Node.js util module for environments that do not have it, like browsers.

For more information

Stripe

The Stripe Node library provides convenient access to the Stripe API from applications written in server-side JavaScript.

For collecting customer and payment information in the browser, use Stripe.js.

See the stripe-node API docs for Node.js.

See video demonstrations covering how to use the library.

Multer

Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency.

NOTE: Multer will not process any form which is not multipart (multipart/form-data).

For more information

Sharp

The typical use case for this high speed Node.js module is to convert large images in common formats to smaller, web-friendly JPEG, PNG, WebP and AVIF images of varying dimensions.

Resizing an image is typically 4x-5x faster than using the quickest ImageMagick and GraphicsMagick settings due to its use of libvips.

Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly. Lanczos resampling ensures quality is not sacrificed for speed.

As well as image resizing, operations such as rotation, extraction, compositing and gamma correction are available.

Most modern macOS, Windows and Linux systems running Node.js v10+ do not require any additional install or runtime dependencies.

Visit sharp.pixelplumbing.com for complete installation instructions, API documentation, benchmark tests and changelog.

Axios

Promise based HTTP client for the browser and node.js

For more information

Mapbox

A node.js and browser JavaScript client to Mapbox services.

For more information