Skip to content

Commit

Permalink
chore: ensure same origin match to apply cookies [run ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed Jul 8, 2024
1 parent 5f2236e commit 1b69a11
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'angular-signals-ct-harness', << pipeline.git.branch >> ]
- equal: [ 'investigate/darwin-ci-build-order', << pipeline.git.branch >> ]
- equal: [ 'same-origin-match-for-cookie-jar', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -55,7 +54,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/fix_kitchensink_against_staging_job', << pipeline.git.branch >> ]
- equal: [ 'same-origin-match-for-cookie-jar', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -78,7 +77,7 @@ windowsWorkflowFilters: &windows-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'angular-signals-ct-harness', << pipeline.git.branch >> ]
- equal: [ 'same-origin-match-for-cookie-jar', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -154,7 +153,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "chore/fix_kitchensink_against_staging_job" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "chore/fix_kitchensink_against_staging_job" && "$CIRCLE_BRANCH" != "same-origin-match-for-cookie-jar" ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
4 changes: 2 additions & 2 deletions packages/proxy/lib/http/response-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ const MaybeInjectHtml: ResponseMiddleware = function () {
wantsSecurityRemoved: this.res.wantsSecurityRemoved,
isNotJavascript: !resContentTypeIsJavaScript(this.incomingRes),
useAstSourceRewriting: this.config.experimentalSourceRewriting,
modifyObstructiveThirdPartyCode: this.config.experimentalModifyObstructiveThirdPartyCode && !this.remoteStates.isPrimarySuperDomainOrigin(this.req.proxiedUrl),
modifyObstructiveThirdPartyCode: this.config.experimentalModifyObstructiveThirdPartyCode && !this.remoteStates.isPrimaryOrigin(this.req.proxiedUrl),
shouldInjectDocumentDomain: cors.shouldInjectDocumentDomain(this.req.proxiedUrl, {
skipDomainInjectionForDomains: this.config.experimentalSkipDomainInjection,
}),
Expand Down Expand Up @@ -880,7 +880,7 @@ const MaybeRemoveSecurity: ResponseMiddleware = function () {
this.incomingResStream = this.incomingResStream.pipe(rewriter.security({
isNotJavascript: !resContentTypeIsJavaScript(this.incomingRes),
useAstSourceRewriting: this.config.experimentalSourceRewriting,
modifyObstructiveThirdPartyCode: this.config.experimentalModifyObstructiveThirdPartyCode && !this.remoteStates.isPrimarySuperDomainOrigin(this.req.proxiedUrl),
modifyObstructiveThirdPartyCode: this.config.experimentalModifyObstructiveThirdPartyCode && !this.remoteStates.isPrimaryOrigin(this.req.proxiedUrl),
modifyObstructiveCode: this.config.modifyObstructiveCode,
url: this.req.proxiedUrl,
deferSourceMapRewrite: this.deferSourceMapRewrite,
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/util/top-simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export const doesTopNeedToBeSimulated = <T>(ctx: HttpMiddlewareThis<T>): boolean

// only simulate top if the AUT is NOT the primary super domain origin, meaning that we should treat the AUT as top
// or the request is the AUT frame, which is common for redirects and navigations.
return !ctx.remoteStates.isPrimarySuperDomainOrigin(currentAUTUrl) || ctx.req.isAUTFrame
return !ctx.remoteStates.isPrimaryOrigin(currentAUTUrl) || ctx.req.isAUTFrame
}
12 changes: 6 additions & 6 deletions packages/server/lib/remote_states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class RemoteStates {
}

get (url: string) {
const state = this.remoteStates.get(cors.getSuperDomainOrigin(url))
const state = this.remoteStates.get(cors.getOrigin(url))

debug('getting remote state: %o for: %s', state, url)

Expand All @@ -74,8 +74,8 @@ export class RemoteStates {
return state
}

isPrimarySuperDomainOrigin (url: string): boolean {
return this.primaryOriginKey === cors.getSuperDomainOrigin(url)
isPrimaryOrigin (url: string): boolean {
return this.primaryOriginKey === cors.getOrigin(url)
}

reset () {
Expand All @@ -92,7 +92,7 @@ export class RemoteStates {
return this.get(this.currentOriginKey) as Cypress.RemoteState
}

set (urlOrState: string | Cypress.RemoteState, options: { auth?: {} } = {}, isPrimarySuperDomainOrigin: boolean = true): Cypress.RemoteState {
set (urlOrState: string | Cypress.RemoteState, options: { auth?: {} } = {}, isPrimaryOrigin: boolean = true): Cypress.RemoteState {
let state

if (_.isString(urlOrState)) {
Expand Down Expand Up @@ -122,11 +122,11 @@ export class RemoteStates {
state = urlOrState
}

const remoteOrigin = cors.getSuperDomainOrigin(state.origin)
const remoteOrigin = cors.getOrigin(state.origin)

this.currentOriginKey = remoteOrigin

if (isPrimarySuperDomainOrigin) {
if (isPrimaryOrigin) {
// convert map to array
const stateArray = Array.from(this.remoteStates.entries())

Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {

let handlingLocalFile = false
const previousRemoteState = this._remoteStates.current()
const previousRemoteStateIsPrimary = this._remoteStates.isPrimarySuperDomainOrigin(previousRemoteState.origin)
const previousRemoteStateIsPrimary = this._remoteStates.isPrimaryOrigin(previousRemoteState.origin)
const primaryRemoteState = this._remoteStates.getPrimary()

// nuke any hashes from our url since
Expand Down Expand Up @@ -932,7 +932,7 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {
restorePreviousRemoteState(previousRemoteState, previousRemoteStateIsPrimary)
}

details.isPrimarySuperDomainOrigin = this._remoteStates.isPrimarySuperDomainOrigin(newUrl!)
details.isPrimaryOrigin = this._remoteStates.isPrimaryOrigin(newUrl!)

return resolve(details)
})
Expand Down

2 comments on commit 1b69a11

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1b69a11 Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.1/linux-x64/same-origin-match-for-cookie-jar-1b69a11ca0d8de6e56aea91c92d8e051bfd9041e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1b69a11 Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.1/win32-x64/same-origin-match-for-cookie-jar-1b69a11ca0d8de6e56aea91c92d8e051bfd9041e/cypress.tgz

Please sign in to comment.