Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-compile HAR schema for validation #270

Open
captn3m0 opened this issue May 30, 2022 · 1 comment
Open

Pre-compile HAR schema for validation #270

captn3m0 opened this issue May 30, 2022 · 1 comment

Comments

@captn3m0
Copy link

Ajv is currently used in httpsnippet for validating the HAR schema passed. Using complete Ajv dependency makes httpsnippet require 'unsafe-eval in the CSP policy, which is a security concern. (https://github.com/ajv-validator/ajv/blob/c3e203c2696e42ec107fe6a5a659fca54b2e4993/docs/security.md#content-security-policy).

As a workaround, since the schema for HAR is known (and already included), it can be pre-compiled into a validation function as part of the build. The Ajv Docs have details on the same.

This would move Ajv from a runtime dependency to a optional developer-dependency (as Ajv-cli) - only needed when har-schema is updated. This would bring a lot more benefits, including performance and bundle size improvements.

This request comes via the Stoplight Elements project, which uses httpsnippet internally. Since httpsnippet doesn't offer a way to pre-compile schemas, this ends up breaking Elements in configurations which limit unsafe-eval via CSP.

@jonluca
Copy link

jonluca commented Aug 9, 2022

I did exactly this and published the library to https://npmjs.com/package/har-validator-compiled, should help out with a few of the places that use har-scheme validation.

I just put up a diff to move over to this validator. #297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants