GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nodebestpractices/sections/security/safemoduleloading.md at master · liustones/nodebestpractices

Expand file tree

/

safemoduleloading.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
15 lines (10 loc) · 606 Bytes
/

safemoduleloading.md

Copy path

File metadata and controls

15 lines (10 loc) · 606 Bytes
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Avoid module loading using a variable

One Paragraph Explainer

Avoid requiring/importing another file with a path that was given as parameter due to the concern that it could have originated from user input. This rule can be extended for accessing files in general (i.e. fs.readFile()) or other sensitive resources with dynamic variables originating from user input.

Code example

// insecure, as helperPath variable may have been modified by user input
const uploadHelpers = require(helperPath);

// secure
const uploadHelpers = require('./helpers/upload');
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.