-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,044 additions
and
100 deletions.
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 |
---|---|---|
@@ -1,25 +1,4 @@ | ||
|
||
This code of conduct applies to all spaces provided by the OpenSource project including in code, documentation, issue trackers, mailing lists, chat channels, wikis, blogs, social media and any other communication channels used by the project. | ||
|
||
|
||
**Our open source communities endeavor to:** | ||
|
||
* Be Inclusive: We are committed to being a community where everyone can join and contribute. This means using inclusive and welcoming language. | ||
* Be Welcoming: We are committed to maintaining a safe space for everyone to be able to contribute. | ||
* Be Respectful: We are committed to encouraging differing viewpoints, accepting constructive criticism and work collaboratively towards decisions that help the project grow. Disrespectful and unacceptable behavior will not be tolerated. | ||
* Be Collaborative: We are committed to supporting what is best for our community and users. When we build anything for the benefit of the project, we should document the work we do and communicate to others on how this affects their work. | ||
|
||
|
||
**Our Responsibility. As contributors, members, or bystanders we each individually have the responsibility to behave professionally and respectfully at all times. Disrespectful and unacceptable behaviors include, but are not limited to:** | ||
|
||
* The use of violent threats, abusive, discriminatory, or derogatory language; | ||
* Offensive comments related to gender, gender identity and expression, sexual orientation, disability, mental illness, race, political or religious affiliation; | ||
* Posting of sexually explicit or violent content; | ||
* The use of sexualized language and unwelcome sexual attention or advances; | ||
* Public or private harassment of any kind; | ||
* Publishing private information, such as physical or electronic address, without permission; | ||
* Other conduct which could reasonably be considered inappropriate in a professional setting; | ||
* Advocating for or encouraging any of the above behaviors. | ||
* Enforcement and Reporting Code of Conduct Issues: | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported. [Contact us](mailto:opensource-codeofconduct@amazon.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. | ||
## Code of Conduct | ||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). | ||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact | ||
opensource-codeofconduct@amazon.com with any additional questions or comments. |
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
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
packages/osd-std/src/__snapshots__/validate_object.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { validateObject } from './validate_object'; | ||
|
||
test(`fails on circular references`, () => { | ||
const foo: Record<string, any> = {}; | ||
foo.myself = foo; | ||
|
||
expect(() => | ||
validateObject({ | ||
payload: foo, | ||
}) | ||
).toThrowErrorMatchingInlineSnapshot(`"circular reference detected"`); | ||
}); | ||
|
||
[ | ||
{ | ||
foo: true, | ||
bar: '__proto__', | ||
baz: 1.1, | ||
qux: undefined, | ||
quux: () => null, | ||
quuz: Object.create(null), | ||
}, | ||
{ | ||
foo: { | ||
foo: true, | ||
bar: '__proto__', | ||
baz: 1.1, | ||
qux: undefined, | ||
quux: () => null, | ||
quuz: Object.create(null), | ||
}, | ||
}, | ||
{ constructor: { foo: { prototype: null } } }, | ||
{ prototype: { foo: { constructor: null } } }, | ||
].forEach((value) => { | ||
['headers', 'payload', 'query', 'params'].forEach((property) => { | ||
const obj = { | ||
[property]: value, | ||
}; | ||
test(`can submit ${JSON.stringify(obj)}`, () => { | ||
expect(() => validateObject(obj)).not.toThrowError(); | ||
}); | ||
}); | ||
}); | ||
|
||
// if we use the object literal syntax to create the following values, we end up | ||
// actually reassigning the __proto__ which makes it be a non-enumerable not-own property | ||
// which isn't what we want to test here | ||
[ | ||
JSON.parse(`{ "__proto__": null }`), | ||
JSON.parse(`{ "foo": { "__proto__": true } }`), | ||
JSON.parse(`{ "foo": { "bar": { "__proto__": {} } } }`), | ||
JSON.parse(`{ "constructor": { "prototype" : null } }`), | ||
JSON.parse(`{ "foo": { "constructor": { "prototype" : null } } }`), | ||
JSON.parse(`{ "foo": { "bar": { "constructor": { "prototype" : null } } } }`), | ||
].forEach((value) => { | ||
test(`can't submit ${JSON.stringify(value)}`, () => { | ||
expect(() => validateObject(value)).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
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,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
interface StackItem { | ||
value: any; | ||
previousKey: string | null; | ||
} | ||
|
||
// we have to do Object.prototype.hasOwnProperty because when you create an object using | ||
// Object.create(null), and I assume other methods, you get an object without a prototype, | ||
// so you can't use current.hasOwnProperty | ||
const hasOwnProperty = (obj: any, property: string) => | ||
Object.prototype.hasOwnProperty.call(obj, property); | ||
|
||
const isObject = (obj: any) => typeof obj === 'object' && obj !== null; | ||
|
||
// we're using a stack instead of recursion so we aren't limited by the call stack | ||
export function validateObject(obj: any) { | ||
if (!isObject(obj)) { | ||
return; | ||
} | ||
|
||
const stack: StackItem[] = [ | ||
{ | ||
value: obj, | ||
previousKey: null, | ||
}, | ||
]; | ||
const seen = new WeakSet([obj]); | ||
|
||
while (stack.length > 0) { | ||
const { value, previousKey } = stack.pop()!; | ||
|
||
if (!isObject(value)) { | ||
continue; | ||
} | ||
|
||
if (hasOwnProperty(value, '__proto__')) { | ||
throw new Error(`'__proto__' is an invalid key`); | ||
} | ||
|
||
if (hasOwnProperty(value, 'prototype') && previousKey === 'constructor') { | ||
throw new Error(`'constructor.prototype' is an invalid key`); | ||
} | ||
|
||
// iterating backwards through an array is reportedly more performant | ||
const entries = Object.entries(value); | ||
for (let i = entries.length - 1; i >= 0; --i) { | ||
const [key, childValue] = entries[i]; | ||
if (isObject(childValue)) { | ||
if (seen.has(childValue)) { | ||
throw new Error('circular reference detected'); | ||
} | ||
|
||
seen.add(childValue); | ||
} | ||
|
||
stack.push({ | ||
value: childValue, | ||
previousKey: key, | ||
}); | ||
} | ||
} | ||
} |
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,3 +1,6 @@ | ||
@import "@elastic/eui/src/global_styling/variables/header"; | ||
|
||
$osdHeaderOffset: $euiHeaderHeightCompensation; | ||
$osdHeaderBreadcrumbBlueBackground: #b9d9eb; | ||
$osdHeaderBreadcrumbGrayBackground: #d9e1e2; | ||
$osdHeaderBreadcrumbCollapsedLink: #002a3a; |
Oops, something went wrong.