Skip to content

Commit 8562c98

Browse files
calvincestarigh-action-runner
authored andcommitted
fix: Add preflight HTTP header (apollographql/apollo-ios-dev#900)
1 parent 369116b commit 8562c98

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/Apollo/JSONRequest.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ public struct JSONRequest<Operation: GraphQLOperation>: GraphQLRequest, AutoPers
122122

123123
// GET requests shouldn't have a content-type since they do not provide actual content.
124124
request.allHTTPHeaderFields?.removeValue(forKey: "Content-Type")
125+
126+
// Note: Apollo Server's CSRF prevention feature (introduced in AS3.7 and intended to be
127+
// the default in AS4) includes this in the set of headers that indicate that a GET
128+
// request couldn't have been a non-preflighted simple request and thus is safe to execute.
129+
//
130+
// See https://www.apollographql.com/docs/apollo-server/security/cors/#preventing-cross-site-request-forgery-csrf
131+
// for details.
132+
request.addValue("true", forHTTPHeaderField: "Apollo-Require-Preflight")
133+
125134
} else {
126135
throw GraphQLHTTPRequestError.serializedQueryParamsMessageError
127136
}

0 commit comments

Comments
 (0)