-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(client): show wildcard frame-ancestors value as allow-everywhere in embed settings #42013
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
Draft
wyattwalter
wants to merge
7
commits into
release
Choose a base branch
from
fm/embed-wildcard-ui-f1
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7725ae
fix(client): show bare "*" frame-ancestors value as allow-everywhere
wyattwalter 3c829d0
fix(client): reject bare "*" pasted as a single frame-ancestors chip
wyattwalter 499cf3e
fix(client): strip stale bare "*" from limited frame-ancestors on save
wyattwalter 37c2e1b
fix(client): normalize disable sentinel out of limited frame-ancestors
wyattwalter 716ef74
fix(client): guard cold-load crash and quote self/none in embed settings
wyattwalter 1befe84
fix(client): never persist 'none' alongside allow-list frame-ancestors
wyattwalter 19fb2b1
fix(client): canonicalize quoted uppercase self/none frame-ancestors …
wyattwalter 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
app/client/src/ce/pages/AdminSettings/config/configuration.test.tsx
This file contains hidden or 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,102 @@ | ||
| import { render } from "test/testUtils"; | ||
| import React from "react"; | ||
| import Radio from "pages/AdminSettings/FormGroup/Radio"; | ||
| import { SETTINGS_FORM_NAME } from "ee/constants/forms"; | ||
| import { reduxForm } from "redux-form"; | ||
| import { AppsmithFrameAncestorsSetting } from "pages/Applications/EmbedSnippet/Constants/constants"; | ||
| import { APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING } from "./configuration"; | ||
|
|
||
| // Render the real frame-ancestors radio setting with the given form value. | ||
| // Passing `undefined` simulates a cold bootstrap of /settings/configuration, | ||
| // where the admin-settings store is not yet hydrated and redux-form calls the | ||
| // field's format() with undefined. | ||
| function renderFrameAncestorsRadio(value: string | undefined) { | ||
| function FrameAncestorsRadio() { | ||
| return <Radio setting={APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING} />; | ||
| } | ||
|
|
||
| // TODO: Fix this the next time the file is edited | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const Parent = reduxForm<any, any>({ | ||
| validate: () => ({}), | ||
| form: SETTINGS_FORM_NAME, | ||
| touchOnBlur: true, | ||
| })(FrameAncestorsRadio); | ||
|
|
||
| return render(<Parent />, { | ||
| initialState: { | ||
| form: { | ||
| [SETTINGS_FORM_NAME]: { | ||
| values: | ||
| value === undefined | ||
| ? {} | ||
| : { [APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING.id]: value }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| describe("APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING radio", () => { | ||
| it("renders without crashing when the setting is not yet hydrated (cold bootstrap)", () => { | ||
| // Regression: on a hard refresh of /settings/configuration the value is | ||
| // undefined, so format() must tolerate it instead of throwing and taking the | ||
| // whole settings page to the error boundary. | ||
| expect(() => renderFrameAncestorsRadio(undefined)).not.toThrow(); | ||
| expect(document.querySelectorAll("input[type=radio]").length).toBe(3); | ||
| }); | ||
|
|
||
| it("selects Allow embedding everywhere for a value containing a bare *", () => { | ||
| renderFrameAncestorsRadio("'self' *"); | ||
|
|
||
| const radios = | ||
| document.querySelectorAll<HTMLInputElement>("input[type=radio]"); | ||
|
|
||
| // Options render in config order: allow / limit / disable. | ||
| expect(radios[0].value).toBe( | ||
| AppsmithFrameAncestorsSetting.ALLOW_EMBEDDING_EVERYWHERE, | ||
| ); | ||
| expect(radios[0].checked).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING parse (stored value)", () => { | ||
| // The parse step is what actually writes the env value on save. | ||
| const parse = APPSMITH_ALLOWED_FRAME_ANCESTORS_SETTING.parse as (v: { | ||
| value: string; | ||
| additionalData?: string; | ||
| }) => string; | ||
|
|
||
| it("quotes a bare self typed in the limit list so it is never persisted raw", () => { | ||
| expect( | ||
| parse({ | ||
| value: AppsmithFrameAncestorsSetting.LIMIT_EMBEDDING, | ||
| additionalData: "self,https://a.com", | ||
| }), | ||
| ).toBe("'self' https://a.com"); | ||
| }); | ||
|
|
||
| it("never combines 'none' with allow-list sources when saving", () => { | ||
| // "'none'" is exclusive in CSP; persisting "'none' https://a.com" would | ||
| // silently disable embedding despite the "limit" selection. | ||
| expect( | ||
| parse({ | ||
| value: AppsmithFrameAncestorsSetting.LIMIT_EMBEDDING, | ||
| additionalData: "none,https://a.com", | ||
| }), | ||
| ).toBe("https://a.com"); | ||
| }); | ||
|
|
||
| it("stores the quoted keywords for the allow/disable options", () => { | ||
| expect( | ||
| parse({ | ||
| value: AppsmithFrameAncestorsSetting.ALLOW_EMBEDDING_EVERYWHERE, | ||
| }), | ||
| ).toBe("*"); | ||
| expect( | ||
| parse({ | ||
| value: AppsmithFrameAncestorsSetting.DISABLE_EMBEDDING_EVERYWHERE, | ||
| }), | ||
| ).toBe("'none'"); | ||
| }); | ||
| }); |
This file contains hidden or 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
98 changes: 98 additions & 0 deletions
98
app/client/src/pages/Applications/EmbedSnippet/FrameAncestorsTagInput.tsx
This file contains hidden or 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,98 @@ | ||
| import React, { useCallback, useMemo, useState } from "react"; | ||
| import styled from "styled-components"; | ||
| import { TagInput } from "@appsmith/ads-old"; | ||
| import { Text } from "@appsmith/ads"; | ||
| import { createMessage, IN_APP_EMBED_SETTING } from "ee/constants/messages"; | ||
| import { | ||
| normalizeFrameAncestorToken, | ||
| removeAllowAllFrameAncestorChips, | ||
| removeDisableFrameAncestorChips, | ||
| } from "./Utils/utils"; | ||
|
|
||
| // Quote bare "self"/"none" keywords in each comma-separated chip so the chip the | ||
| // user sees matches what is stored. Chips can hold whitespace-separated tokens | ||
| // (pasted values), so normalize per token. | ||
| const normalizeChips = (value: string): string => | ||
| value | ||
| .split(",") | ||
| .filter(Boolean) | ||
| .map((chip) => | ||
| chip | ||
| .split(/\s+/) | ||
| .filter(Boolean) | ||
| .map(normalizeFrameAncestorToken) | ||
| .join(" "), | ||
| ) | ||
| .join(","); | ||
|
|
||
| const ErrorText = styled(Text)` | ||
| display: block; | ||
| margin-top: 4px; | ||
| color: var(--ads-v2-color-fg-error); | ||
| `; | ||
|
|
||
| interface FrameAncestorsTagInputProps { | ||
| // Injected by the radio field via nodeInputPath. Values are comma-separated. | ||
| input?: { | ||
| value?: string; | ||
| onChange?: (value: string) => void; | ||
| }; | ||
| placeholder: string; | ||
| type: string; | ||
| } | ||
|
|
||
| // Wraps the shared TagInput for the "Limit embedding to certain URLs" list and | ||
| // rejects any chip containing a keyword source that contradicts the "limit" | ||
| // intent: a bare "*" (belongs to "Allow embedding everywhere") or a | ||
| // "none"/"'none'" (belongs to "Disable embedding everywhere" - in CSP "'none'" | ||
| // is exclusive and would silently disable embedding if combined with URLs). Both | ||
| // checks are whitespace-aware because a pasted value can arrive as a single chip | ||
| // (e.g. "'self' *" or "none https://a.com"). Host wildcards like | ||
| // "https://*.example.com" are left untouched. | ||
| function FrameAncestorsTagInput(props: FrameAncestorsTagInputProps) { | ||
| const { input = {}, ...rest } = props; | ||
| const [error, setError] = useState(""); | ||
| const { onChange, value } = input; | ||
|
|
||
| const handleChange = useCallback( | ||
| (nextValue: string) => { | ||
| const withoutWildcard = removeAllowAllFrameAncestorChips(nextValue); | ||
| const withoutDisable = removeDisableFrameAncestorChips( | ||
| withoutWildcard.value, | ||
| ); | ||
|
|
||
| if (withoutWildcard.removed) { | ||
| setError( | ||
| createMessage(IN_APP_EMBED_SETTING.limitEmbeddingBareWildcardError), | ||
| ); | ||
| } else if (withoutDisable.removed) { | ||
| setError( | ||
| createMessage(IN_APP_EMBED_SETTING.limitEmbeddingDisableKeywordError), | ||
| ); | ||
| } else { | ||
| setError(""); | ||
| } | ||
|
|
||
| onChange?.(normalizeChips(withoutDisable.value)); | ||
| }, | ||
| [onChange], | ||
| ); | ||
|
|
||
| const tagInputProps = useMemo( | ||
| () => ({ value, onChange: handleChange }), | ||
| [value, handleChange], | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <TagInput {...rest} input={tagInputProps} /> | ||
| {error && ( | ||
| <ErrorText kind="body-s" renderAs="span"> | ||
| {error} | ||
| </ErrorText> | ||
| )} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default FrameAncestorsTagInput; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.