Code Monkey home page Code Monkey logo

koa-csp's Introduction

Hey, I'm Guo Zhihao

A bit about Myself, a full-stack developer from China. My passion for software lies in bringing my whimsical ideas to life.

favorite languages and tools:

My GitHub Stat Trophies

koa-csp's People

Contributors

github-actions[bot] avatar hasancanugurlu avatar luzat avatar val-istar-guo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

koa-csp's Issues

Should this be an async middleware?

Hi there,

Looking at adding a CSP header to my Koa project, and looking at the source here:

koa-csp/src/index.js

Lines 34 to 42 in d59f9d6

return async (ctx, next) => {
if (enableWarn) validatePolicy(policy);
const policyStr = formatPolicy(policy)
.map(directive => directive.join(' '))
.join(';')
ctx.set('Content-Security-Policy', policyStr);
await next();

Can't help but think the async is redundant if await next(); is changed to return next(); as I've seen for other Koa middleware.

So instead:

return (ctx, next) => { 
   if (enableWarn) validatePolicy(policy); 
  
   const policyStr = formatPolicy(policy) 
     .map(directive => directive.join(' ')) 
     .join(';') 
  
   ctx.set('Content-Security-Policy', policyStr); 
   return next();
};

I would happily implement this & open a PR, however after quickly looking through tests it would fundamentally change all tests!

rewrite it by typescript

Is your feature request related to a problem? Please describe.
Many people have started to use this library, it is valuable to use Typescript to rewrite.

Entry point jsnext:main does not exist

package.json contains a "jsnext:main": "src/csp.js" entry, but csp.js does not exist. It's likely that it should ...

  1. refer to src/index.js
  2. be replaced by module: "src/index.js" (see e.g. this rollup issue)

In practice the wrong jsnext:main entry leads to eslint-plugin-import returning an import/no-unresolved error and a linting failure, but using either module or jsnext:main with src/index.js works.

Bug: [kpa-csp warn] Invalid Policy Name: form-action, report-uri

Describe the bug
Getting [kpa-csp warn] Invalid Policy Name: form-action, report-uri on the logs.

To Reproduce
add form-action and report-uri policies.

Additional context
form-action and report-uri are valid policies for CSP. Please add them in the package. Also is kpa-csp a typo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.