-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add warning regarding subscription and mutation redaction of relation…
…al fields (#7768) * add warning regarding subscription and mutation redaction of relational fields * replace authn with authz in warning * chore(api): Callout for field redaction on Swift Android relational models * Update src/pages/gen1/[platform]/build-a-backend/graphqlapi/relational-models/index.mdx * add feature flag to warning for gen 1 * Fix heading order in fragments affecting this page * add protected redaction message components * Add tests for redaction message Gen 1 and Gen 2 components * add snapshots for redaction Gen 1 and Gen 2 component tests * Adds ProtectedRedactionMessage components for Gen 1 and Gen2 * Render ProtectedRedactionGen1Message component on Gen 1 realtime page * Render ProtectedRedactionGen1Message component on Gen 2 data modeling page * Render ProtectedRedactionGen2Message component on Gen 2 realtime page * Render ProtectedRedactionGen1Message component on Gen 1 data modeling page * Render ProtectedRedactionGen1Message component on Gen 1 V5 realtime page * add subscriptionsInheritPrimaryAuth as a feature flag * correct version for subscriptionsInheritPrimaryAuth * remove commented code * fix heading order --------- Co-authored-by: Michael Law <1365977+lawmicha@users.noreply.github.com> Co-authored-by: Heather <hbuchel@gmail.com> Co-authored-by: katiegoines <katiegoines@gmail.com>
- Loading branch information
1 parent
a640904
commit 9e79e97
Showing
10 changed files
with
380 additions
and
4 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
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
81 changes: 81 additions & 0 deletions
81
src/protected/ProtectedRedactionMessage/__tests__/ProtectedRedactionMessage.test.tsx
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,81 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { | ||
ProtectedRedactionGen1Message, | ||
ProtectedRedactionGen2Message | ||
} from '../index'; | ||
import fs from 'fs'; | ||
|
||
// REALTIME DATA | ||
const GEN1_V5_REALTIME_DATA_PAGE_PATH = | ||
'src/pages/gen1/[platform]/prev/build-a-backend/graphqlapi/subscribe-data/index.mdx'; | ||
|
||
const GEN1_V6_REALTIME_DATA_PAGE_PATH = | ||
'src/pages/gen1/[platform]/build-a-backend/graphqlapi/subscribe-data/index.mdx'; | ||
|
||
const GEN2_REALTIME_DATA_PAGE_PATH = | ||
'src/pages/[platform]/build-a-backend/data/subscribe-data/index.mdx'; | ||
|
||
// DATA MODELING | ||
|
||
const GEN1_V6_DATA_MODELING_PAGE_PATH = | ||
'src/pages/gen1/[platform]/build-a-backend/graphqlapi/data-modeling/index.mdx'; | ||
|
||
const GEN2_DATA_MODELING_PAGE_PATH = | ||
'src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx'; | ||
|
||
describe('Protected Redaction Messages', () => { | ||
/* | ||
This test is to ensure that the ProtectedRedactionGen1Message component appears on the Gen 1 realtime data pages and cannot be removed or modified without approval. | ||
*/ | ||
it('should render ProtectedRedactionGen1Message component on the Gen 1 V5 realtime data page', async () => { | ||
const pageData = fs.readFileSync(GEN1_V5_REALTIME_DATA_PAGE_PATH, { | ||
encoding: 'utf8' | ||
}); | ||
expect(pageData).toMatch(/<ProtectedRedactionGen1Message \/>/); | ||
}); | ||
|
||
it('should render ProtectedRedactionGen1Message component on the Gen 1 V6 realtime data page', async () => { | ||
const pageData = fs.readFileSync(GEN1_V6_REALTIME_DATA_PAGE_PATH, { | ||
encoding: 'utf8' | ||
}); | ||
expect(pageData).toMatch(/<ProtectedRedactionGen1Message \/>/); | ||
}); | ||
|
||
it('should render ProtectedRedactionGen1Message component on the Gen 2 realtime data page', async () => { | ||
const pageData = fs.readFileSync(GEN2_REALTIME_DATA_PAGE_PATH, { | ||
encoding: 'utf8' | ||
}); | ||
expect(pageData).toMatch(/<ProtectedRedactionGen2Message \/>/); | ||
}); | ||
|
||
it('should render ProtectedRedactionGen1Message component on the Gen 1 V6 data modeling page', async () => { | ||
const pageData = fs.readFileSync(GEN1_V6_DATA_MODELING_PAGE_PATH, { | ||
encoding: 'utf8' | ||
}); | ||
expect(pageData).toMatch(/<ProtectedRedactionGen1Message \/>/); | ||
}); | ||
|
||
it('should render ProtectedRedactionGen1Message component on the Gen 2 data modeling page', async () => { | ||
const pageData = fs.readFileSync(GEN2_DATA_MODELING_PAGE_PATH, { | ||
encoding: 'utf8' | ||
}); | ||
expect(pageData).toMatch(/<ProtectedRedactionGen2Message \/>/); | ||
}); | ||
|
||
/* | ||
This test is to ensure that the messaging on the ProtectedRedactionGen1Message component does not change | ||
and cannot be removed or modified without approval. | ||
*/ | ||
it('should render the protected redaction message for Gen 1', async () => { | ||
const { container } = render(<ProtectedRedactionGen1Message />); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render the protected redaction message for Gen 2', async () => { | ||
const { container } = render(<ProtectedRedactionGen2Message />); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
137 changes: 137 additions & 0 deletions
137
...ProtectedRedactionMessage/__tests__/__snapshots__/ProtectedRedactionMessage.test.tsx.snap
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,137 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Protected Redaction Messages should render the protected redaction message for Gen 1 1`] = ` | ||
<div | ||
class="amplify-flex amplify-message amplify-message--filled amplify-message--warning" | ||
> | ||
<div | ||
aria-hidden="true" | ||
class="amplify-message__icon" | ||
> | ||
<span | ||
class="amplify-icon" | ||
style="width: 1em; height: 1em;" | ||
> | ||
<svg | ||
fill="none" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M1 21H23L12 2L1 21ZM13 18H11V16H13V18ZM13 14H11V10H13V14Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</div> | ||
<div | ||
class="amplify-flex amplify-message__content" | ||
> | ||
<div> | ||
<p> | ||
With versions of Amplify CLI | ||
<code> | ||
@aws-amplify/cli@12.12.2 | ||
</code> | ||
and API Category | ||
<code> | ||
@aws-amplify/amplify-category-api@5.11.5 | ||
</code> | ||
, an improvement was made to how relational field data is handled in subscriptions when different authorization rules apply to related models in a schema. The improvement redacts the values for the relational fields, displaying them as null or empty, to prevent unauthorized access to relational data. This redaction occurs whenever it cannot be determined that the child model will be protected by the same permissions as the parent model. | ||
</p> | ||
<p> | ||
Because subscriptions are tied to mutations and the selection set provided in the result of a mutation is then passed through to the subscription, relational fields in the result of mutations must be redacted. | ||
</p> | ||
<p> | ||
If an authorized end-user needs access to the redacted relational field they should perform a query to read the relational data. | ||
</p> | ||
<p> | ||
Additionally, subscriptions will inherit related authorization when relational fields are set as required. To better protect relational data, consider modifying the schema to use optional relational fields. | ||
</p> | ||
<p> | ||
Based on the security posture of your application, you can choose to revert to the subscription behavior before this improvement was made. | ||
</p> | ||
<p> | ||
To do so, use the | ||
<code> | ||
subscriptionsInheritPrimaryAuth | ||
</code> | ||
feature flag under | ||
<code> | ||
graphqltransformer | ||
</code> | ||
in the | ||
<code> | ||
amplify/backend/cli.json | ||
</code> | ||
file. | ||
</p> | ||
<ul> | ||
<li> | ||
If enabled, subscriptions will inherit the primary model authorization rules for the relational fields. | ||
</li> | ||
<li> | ||
If disabled, relational fields will be redacted in mutation response when there is a difference between auth rules between primary and related models. | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`Protected Redaction Messages should render the protected redaction message for Gen 2 1`] = ` | ||
<div | ||
class="amplify-flex amplify-message amplify-message--filled amplify-message--warning" | ||
> | ||
<div | ||
aria-hidden="true" | ||
class="amplify-message__icon" | ||
> | ||
<span | ||
class="amplify-icon" | ||
style="width: 1em; height: 1em;" | ||
> | ||
<svg | ||
fill="none" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M1 21H23L12 2L1 21ZM13 18H11V16H13V18ZM13 14H11V10H13V14Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
</span> | ||
</div> | ||
<div | ||
class="amplify-flex amplify-message__content" | ||
> | ||
<div> | ||
<p> | ||
With Amplify Data Construct | ||
<code> | ||
@aws-amplify/data-construct@1.8.4 | ||
</code> | ||
, an improvement was made to how relational field data is handled in subscriptions when different authorization rules apply to related models in a schema. The improvement redacts the values for the relational fields, displaying them as null or empty, to prevent unauthorized access to relational data. | ||
</p> | ||
<p> | ||
This redaction occurs whenever it cannot be determined that the child model will be protected by the same permissions as the parent model. | ||
</p> | ||
<p> | ||
Because subscriptions are tied to mutations and the selection set provided in the result of a mutation is then passed through to the subscription, relational fields in the result of mutations must be redacted. | ||
</p> | ||
<p> | ||
If an authorized end-user needs access to the redacted relational fields, they should perform a query to read the relational data. | ||
</p> | ||
<p> | ||
Additionally, subscriptions will inherit related authorization when relational fields are set as required. To better protect relational data, consider modifying the schema to use optional relational fields. | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.