Code Monkey home page Code Monkey logo

hexo-csp's People

Contributors

bhaskarmelkani avatar dependabot[bot] avatar xbc5 avatar

hexo-csp's Issues

Paths are not properly applied

Paths with generated slugs to not fulfil the selection process -- for example: "2022/02/01/foo.html". Find a way to apply the CSP to related paths (e.g. archives, tags etc).

Move prod/dev env keys into policies

This means:

^path$:
  prod:
    directives: ...
  dev:
    directives: ...

Instead of:

yml
prod:
  ^path$:
    directives: ...
dev:
  ^path$:
    directives: ...

This avoids duplication of patterns. It still allows the user to apply patterns to one environment but not the other.

Improve validation

  • exclude mode from prod base policies, since this has no meaning;
  • logger: validate host against URL; possibly the path too;

Beautify snapshots

Apply beautification only during testing. The snapshots are hard to read.

do service test for logger

Test that it logs to console.

This will require an HTTP client, and a sandbox for the Hexo dist/public files.

Set defaults via Joi

Defaults to use:

  • mode: "merge" => combineEnvs() expects this to be set;

Joi returns an object like so: { value, error }. value will always contain something, for example if you misspell a key, it will include both correct and incorrect spellings, but defaulting the correct.

Do something like:

const validated = Joi.validate(foo);
if (!validated.error) {
  doSomething(validated.value)
}

Validate everywhere that savePolicy is used. Typically in the primary index file, or applyCSP.

Halt rendering on error?

Should this be done? It seems like not halting the build on a security violation would be bad for CI.

Find a way to do this properly.

Issues:

  1. the after_render filter fires for each path, throwing within that means throwing hundreds of errors;
  2. throwing within the root index means throwing for the CLI too, since it also loads plugins -- it makes no sense to do this;
  3. the hexo testing utils hates exceptions, and causes unhandled rejection error;

In short: can't throw on load, during rendering, or during testing.

hexo generate --csp-dev does not apply

This is untested, and results in production policies being applied 100% of the time. Ignoring dev logger and dev policies.

You may be able to remove this feature (and tests) if #38 is implemented.

Use RegExp to match paths

This means you will also have to test the scenario where two expressions match a single document -- ensure that they merge/replace correctly.

Use the default path

Right now the default directive does nothing, apply it to paths that don't match -- i.e. return it as a default for Config.directives(path).

Refactor Policies

Make this store policy objects internally, and contain all policy behaviours.

Compute hashes

First ensure that style tags etc are in their final form (minified), then compute their hashes.

Refactor: use POJO for policies

Right now, all policies need rebuilding for every after_render:html due to them being Policy instances. Implement a way that is more efficient. You will only need to refactor Config.#buildPolicies(); mergePolicies().

You WILL need to validate (#2) the config separately; set defaults separately. Perhaps use a pipeline.

Use a runtime schema validator for the config object.

validate config

Besides typical validation, ensure that the directive keys are valid. Instead of throwing, just warn. This means modern directives wont immediately cause issues.

Parse all directives, and merge/replace them

This relates to #6.

The default is merge -- always.

Front-matter takes precedence, then URI specific directives, then the default directives.

First, merge/replace the production environment, then merge/replace with development environment. These respect the env mode and individual frontmatter/URI modes.

csp:
  mode:
    env: merge
  prod:
    directives:
      foo/index.html
      mode: replace

This is frontmatter, it replaces the layer below it.

---
csp:
  mode: replace
---

Examples:

If front-matter specifies replace, then that is the final form. If that's then merged with development environment, then it's a mix of the two.

If front-matter is merge and URI is replace, then the final form is front matter + URI (replacing default).

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.