StudyFox
कीमतेंब्लॉगएक्सटेंशनमुफ़्त टूल
  • कीमतें
  • ब्लॉग
  • एक्सटेंशन
  • मुफ़्त टूल
  • शुरू करेंसाइन इन
StudyFox

अपने नोट्स, PDF और स्लाइड्स को फ़्लैशकार्ड, क्विज़, नोट्स और माइंड मैप में बदलें।

StudyFox खोलें

स्टडी टूल्स

  • होमवर्क हेल्पर
  • नोट मेकर
  • फ़्लैशकार्ड मेकर
  • क्विज़ मेकर
  • माइंड मैप मेकर

प्रोडक्ट

  • कीमतें
  • Chrome एक्सटेंशन
  • मुफ़्त एक्सटेंशन
  • स्टडी सेट देखें
  • ब्लॉग

सहायता

  • सहायता केंद्र
  • संपर्क करें
  • गोपनीयता नीति
  • सेवा की शर्तें

तुलना करें

  • Chegg का विकल्प
  • Course Hero का विकल्प
  • Coursology का विकल्प
  • Photomath का विकल्प
  • Gauthmath का विकल्प
  • PhotoSolve का विकल्प
  • CollegeTools का विकल्प
  • Transcript का विकल्प
  • SmartSolve का विकल्प
  • Homeworkify का विकल्प
  • AnswersAi का विकल्प
  • StudyX का विकल्प
  • Quizlet का विकल्प
  • Anki का विकल्प
  • Knowt का विकल्प
  • Brainscape का विकल्प
  • सभी तुलनाएँ

© 2026 StudyFox AI. सर्वाधिकार सुरक्षित।

  • X
  • Discord
  • Instagram
ExploreEngineering & TechWeb DevelopmentAPI Security, OAuth, CORS and GraphQL Scenarios Quiz

Quiz · Hard

API Security, OAuth, CORS and GraphQL Scenarios Quiz

Nineteen harder scenario questions on JWT pitfalls, CORS and preflights, OAuth 2.0 flows, BOLA, mass assignment, webhooks, rate limiting, GraphQL N+1 and real-time options.

by Kill h.19 questionsCreated Nov 20, 2026, 08:26 PM
Web Development· APIsTags#api#oauth#jwt#cors#graphql

19 questions

  1. 1

    Your API issues JWTs containing the user's email and role. A teammate says the token is safe because it is 'encrypted'. What is the correct response?

    • A

      Correct: JWTs are always encrypted

    • B

      Correct, as long as the signature uses HS256

    • Wrong: a standard signed JWT is only Base64URL-encoded, so anyone holding it can read the payload; the signature only prevents tampering

    • D

      Wrong: JWTs are plain text with no signature

    A normal JWT (JWS) is signed, not encrypted. Do not put secrets in the payload; use JWE or an opaque token if the claims must be hidden.

  2. 2

    An API verifies JWTs using the algorithm named in each token's own header. An attacker sends a token with "alg": "none" and no signature. What is the flaw?

    • The server must enforce the expected algorithm and key; trusting the header's algorithm lets attackers skip or change verification

    • B

      Tokens must be shorter

    • C

      The server should use HTTP instead of HTTPS

    • D

      There is no flaw because 'none' is invalid JSON

    Never let the token choose how it is verified. Pin the allowed algorithms and key (and reject none), then check exp, iss and aud.

  3. 3

    A front-end at https://app.example.com calls https://api.example.com/data. The browser console shows a CORS error but curl works. Why?

    • A

      The API is down for browsers

    • B

      curl bypasses TLS

    • C

      The browser blocks all JSON

    • CORS is a browser-enforced policy; the API must send the right Access-Control-Allow-Origin header for the page's origin

    Different subdomains are different origins. Browsers only expose a cross-origin response to scripts if the server's CORS headers allow it. curl and servers do not apply the policy.

  4. 4

    A fetch call sends Content-Type: application/json and an Authorization header to another origin. What does the browser do first?

    • A

      Nothing, it sends the request directly

    • It sends an OPTIONS preflight request to check permission

    • C

      It converts the request to GET

    • D

      It blocks it permanently

    A JSON content type and a custom/Authorization header make the request non-simple, so the browser sends an OPTIONS preflight with Access-Control-Request-Method and Access-Control-Request-Headers first.

  5. 5

    The server replies with Access-Control-Allow-Origin: * but the front-end uses credentials: 'include' and the browser still blocks the response. Why?

    • A

      Cookies are not allowed over HTTPS

    • Browsers refuse a wildcard origin when credentials are included; the server must echo the specific origin and send Access-Control-Allow-Credentials: true

    • C

      The wildcard must be **

    • D

      Credentials only work with GET

    With credentials, * is not accepted. Respond with the exact origin, set Vary: Origin, and add Access-Control-Allow-Credentials: true.

  6. 6

    Which OAuth 2.0 flow should a single-page app or native mobile app use to sign users in and call an API?

    • A

      Implicit flow

    • B

      Resource owner password credentials

    • C

      Client credentials

    • Authorization code flow with PKCE

    Public clients cannot keep a secret, so they use the authorization code flow with PKCE. Implicit leaks tokens in URLs and the password grant exposes the user's password to the app. Client credentials has no user.

  7. 7

    A nightly backend job must call another company's API with its own identity and no user present. Which OAuth 2.0 grant fits?

    • Client credentials

    • B

      Authorization code with PKCE

    • C

      Implicit

    • D

      Device code

    Client credentials is for machine-to-machine access: the app authenticates with its own id and secret to get a token for its own resources.

  8. 8

    GET /api/invoices/1042 returns another customer's invoice when you change the number from 1041. Which vulnerability is this?

    • A

      SQL injection

    • B

      CSRF

    • Broken object level authorization (BOLA / IDOR)

    • D

      Clickjacking

    The API checks that you are logged in but not that the invoice belongs to you. Authorize every object access on the server (ownership or permission checks); hiding or randomizing ids is not enough.

  9. 9

    You verify a webhook by computing an HMAC of the request body, but verification randomly fails. Parsing the JSON and re-serializing it before hashing changes whitespace. What should you hash?

    • A

      The re-serialized JSON

    • B

      Only the URL

    • C

      Only the headers

    • The exact raw request body bytes

    The signature was computed over the raw bytes the provider sent. Any re-serialization changes them. Compute the HMAC on the raw body and compare in constant time.

  10. 10

    An attacker captures a valid signed webhook and replays it a day later. Which measure helps most?

    • A

      Make the webhook URL longer

    • Include and check a signed timestamp (reject old events) and store processed event ids

    • C

      Use HTTP instead of HTTPS

    • D

      Respond with 500

    A valid signature on an old message is still valid unless freshness is checked. Reject events outside a short window and deduplicate by event id.

  11. 11

    A client receives 429 Too Many Requests with Retry-After: 30. What should a well-behaved client do?

    • A

      Retry immediately in a tight loop

    • B

      Switch to POST

    • Wait at least 30 seconds, then retry (with backoff), instead of hammering the API

    • D

      Treat it as success

    429 means you are being rate limited; Retry-After states when to try again. Immediate retries make the problem worse and may get the client blocked.

  12. 12

    A GraphQL API always returns HTTP 200, even when a query fails, and puts problems in an errors array. Your monitoring only alerts on 5xx status codes. What is the risk?

    • Failures go unnoticed; you must inspect the errors field (and track it) in monitoring

    • B

      None, 200 means success

    • C

      GraphQL does not support errors

    • D

      The server is using the wrong port

    GraphQL reports field-level and partial errors in the response body, usually with status 200. Monitoring has to parse the body or use GraphQL-aware tooling.

  13. 13

    A GraphQL query for 50 posts, each with its author, triggers 51 database queries. What is the standard solution?

    • Batching and caching per request with a DataLoader-style utility

    • B

      Switching the API to SOAP

    • C

      Turning on HTTP/3

    • D

      Removing the author field from the schema

    This is the N+1 problem. A DataLoader collects the author ids requested during one tick and fetches them in a single query.

  14. 14

    You need a live notification feed where the server pushes events to browsers over plain HTTP, with automatic reconnection. Which technology fits best?

    • A

      WebSockets

    • B

      Long polling only

    • Server-Sent Events (SSE)

    • D

      SOAP

    SSE is purpose-built for one-way server-to-client streams, reuses HTTP, and EventSource reconnects automatically. WebSockets suit two-way interaction like chat or games.

  15. 15

    A browser app stores its JWT in localStorage. What is the main security trade-off?

    • A

      Tokens expire faster

    • Any injected script (XSS) can read and exfiltrate it

    • C

      The token cannot be sent in headers

    • D

      HTTPS no longer applies

    localStorage is accessible to all scripts on the page. HttpOnly cookies are not readable by JavaScript but then need CSRF protection.

  16. 16

    A client updates PATCH /users/42 with {"name":"Ada","isAdmin":true} and becomes an administrator, because the API binds the whole body to the model. What is this flaw called?

    • A

      Cache poisoning

    • B

      Replay attack

    • C

      Clickjacking

    • Mass assignment

    The server let the client set a field it should control. Use an allowlist of writable fields or a dedicated input object.

  17. 17

    The OAuth 2.0 state parameter in the authorization request is mainly used to...

    • A

      encrypt the access token

    • B

      choose the scopes

    • prevent CSRF by tying the response to the request that started it

    • D

      set the token lifetime

    The client generates a random state, stores it, and checks that the same value comes back on the redirect. Otherwise an attacker could trick the app into completing a login the user never started.

  18. 18

    In this token, which part would an attacker change to try to make themselves an admin, and what stops it from working?

    • Payload; the signature no longer matches, so verification fails

    • B

      Header; the issuer's URL

    • C

      Signature; the payload is encrypted

    • D

      Payload; the header hides it

    Claims live in the payload. Changing them invalidates the signature, which only the holder of the secret or private key can recompute, so the API rejects the token.

  19. 19

    What is the purpose of step 1 (OPTIONS) in the diagram?

    • A

      To download the data

    • B

      To log the user in

    • C

      To compress the body

    • To ask the API whether the real PUT request from this origin is allowed

    The preflight asks permission using Origin, Access-Control-Request-Method and Access-Control-Request-Headers. Only if the response allows it does the browser send the actual request.