-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
feat: expose available functions to custom functions #925
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function(targetVal, opts, paths, otherValues) { | ||
return 'bar' in targetVal ? this.functions.schema(targetVal.bar, opts, paths, otherValues) : void 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
import { alphabetical } from './alphabetical'; | ||
import { casing } from './casing'; | ||
import { enumeration } from './enumeration'; | ||
import { falsy } from './falsy'; | ||
import { length } from './length'; | ||
import { pattern } from './pattern'; | ||
import { schema } from './schema'; | ||
import { schemaPath } from './schema-path'; | ||
import { truthy } from './truthy'; | ||
import { typedEnum } from './typedEnum'; | ||
import { undefined } from './undefined'; | ||
import { unreferencedReusableObject } from './unreferencedReusableObject'; | ||
import { xor } from './xor'; | ||
|
||
export const functions = { | ||
alphabetical: require('./alphabetical').alphabetical, | ||
casing: require('./casing').casing, | ||
enumeration: require('./enumeration').enumeration, | ||
length: require('./length').length, | ||
pattern: require('./pattern').pattern, | ||
falsy: require('./falsy').falsy, | ||
schema: require('./schema').schema, | ||
schemaPath: require('./schema-path').schemaPath, | ||
truthy: require('./truthy').truthy, | ||
undefined: require('./undefined').undefined, | ||
xor: require('./xor').xor, | ||
unreferencedReusableObject: require('./unreferencedReusableObject').unreferencedReusableObject, | ||
typedEnum: require('./typedEnum').typedEnum, | ||
alphabetical, | ||
casing, | ||
enumeration, | ||
length, | ||
pattern, | ||
falsy, | ||
schema, | ||
schemaPath, | ||
truthy, | ||
undefined, | ||
xor, | ||
unreferencedReusableObject, | ||
typedEnum, | ||
}; | ||
|
||
export type CoreFunctions = typeof functions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip From a user standpoint, what would be the potential risks? It might be interesting to list some of the most critical ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were planning to run that code in a sandboxed env, but that's not ready yet.
The risk depends on the environment Spectral is executed in.
We use
vm
for Node, but it's not supposed to run untrusted code.It basically spins up a separate V8 isolate, but that's pretty much it.
In case of a browser... you have access to indexedb, local storage, so for instance auth info could be leaked if you use JWT and similar methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip Thanks for the detailed explanation. This doco update is interesting but may be a bit scary to the reader in its current form as it's a bit vague and not really actionable.
How would you feel about adding a couple of sentences about what could happen (eg. data/creds exfiltration, potential data tampering...), what kind of external rulesets they should be careful about (eg. those leveraging custom functions which aren't part of Spectral Core, ...), and what kind of actions should be taken (eg. reviewing the code of the functions to ensure nothing weirdo is being done, no shady obfuscated remote code is being "required" (cf. https://stackoverflow.com/a/23569631/335418), maybe considering "vendoring" external rulesets to protect against potential future evil changes...).
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll update it in a bit.
It's a similar case as with npm dependencies. You kind of trust them for the most of the time, but you should be careful during updates, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some! what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip very clear and straightforward. I like this very much! <3