React Client Headers Are Missing in the Server Spring Boot

Abstract: Fix missing custom headers in Spring Boot by configuring CORS to allow preflight requests and specific headers from React.

Created: 2026-08-22 by
The issue of missing headers in a Spring Boot server when called from React, despite working in Postman, is almost always caused by the browser’s Cross-Origin Resource Sharing (CORS) policy. Browsers block requests that do not explicitly allow them, and for non-simple requests or those with custom headers, a preflight check occurs. If the server does not correctly respond to this preflight request with appropriate CORS headers, the actual request is never sent, making it appear as if the headers are missing.

Understanding the Browser's CORS Mechanism

When you use Postman, you are bypassing the browser entirely. Postman sends raw HTTP requests without enforcing same-origin policies or checking for CORS permissions. However, modern browsers enforce strict security measures to protect users from malicious scripts. When your React application attempts to make an API call to a different domain, port, or protocol than the one serving the frontend, the browser initiates a two-step process. First, if the request involves methods other than GET, POST, or HEAD, or includes custom headers like Authorization or X-Custom-Header, the browser sends an OPTIONS request known as a "preflight" request. This preflight asks the server: "Is it okay to send the real request with these specific headers?" The server must respond with specific headers indicating which origins, methods, and headers are allowed. If the server fails to respond correctly to this preflight, the browser cancels the actual request. Consequently, your Spring Boot controller never sees the request, and no headers arrive. This is often misinterpreted as headers being "stripped," but they are simply blocked before transmission.

Configuring CORS in Spring Boot

To resolve this, you must configure your Spring Boot application to handle CORS properly. The most robust way to do this is by creating a configuration class that implements WebMvcConfigurer. This allows you to define global CORS settings that apply to all endpoints or specific ones. Create a new class annotated with @Configuration and implement WebMvcConfigurer. Override the addCorsMappings method to specify which origins are allowed. For development, you might allow your local React development server, typically running on port 3000. You should also specify which HTTP methods are permitted, such as GET, POST, PUT, and DELETE. Crucially, you must list the headers that your React client will send. If you are sending an Authorization header, it must be explicitly included in the allowedHeaders list. Without this, the preflight response will reject the custom header, causing the browser to block the request.
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOrigins("http://localhost:3000")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}
Setting allowedHeaders("*") permits all headers, which is convenient for development but may need tightening for production security. Setting allowCredentials(true) is essential if your React app uses cookies or authentication tokens, as it tells the browser to include credentials in the cross-origin request. Note that when credentials are allowed, you cannot use allowedOrigins("*"); you must specify the exact origin.

Verifying Header Transmission in React

Once the server is configured, ensure your React code is actually attaching the headers. Using the native fetch API, you can pass headers via the headers option in the request configuration. For example, to send an authorization token, structure your fetch call as follows:
fetch('http://localhost:8080/api/resource', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
  },
  body: JSON.stringify(data)
});
If you are using Axios, set the headers globally or per-request using axios.defaults.headers.common['Authorization'] = token. It is vital to verify that these headers are present in the Network tab of your browser's developer tools. Look for the initial OPTIONS request. Check its Response Headers. You should see Access-Control-Allow-Headers containing the names of your custom headers. If they are missing there, the server configuration is incorrect. If they are present but the subsequent POST request is not sent, check the console for CORS errors.

Common Pitfalls and Debugging Steps

A frequent mistake is assuming that setting allowedHeaders("*") on the server is sufficient without ensuring the client actually sends the headers. Another pitfall is mismatched origins. Ensure that the origin specified in allowedOrigins matches exactly what the browser reports, including the scheme (http vs https) and port. Sometimes, developers forget that localhost and 127.0.0.1 are treated as different origins by the browser. Additionally, check if any intermediate proxies or load balancers are stripping headers. While less common in local development, it is a possibility in production environments. Ensure that your Spring Security configuration, if used, does not interfere with CORS preflight requests. By default, Spring Security might block OPTIONS requests. You can configure Security to permit all requests for paths matching your CORS mapping, or disable security checks for preflight requests specifically. For more insights into handling context and configurations in Spring Boot, you might find Spring Boot Context Comes as Null When Implementing ImportBeanDefinitionRegistrar useful, as it touches on broader configuration challenges. Similarly, understanding how to manage profiles can help isolate environment-specific CORS issues, as discussed in Excluding Included Profiles in Spring: A Comprehensive Guide.

Frequently Asked Questions

Why does my request work in Postman but fail in the browser?

Postman does not enforce browser security policies like CORS. The browser blocks the request because the server did not explicitly allow the cross-origin request during the preflight phase. This is a security feature, not a bug in your code.

What is a preflight request?

A preflight request is an automatic OPTIONS request sent by the browser before the actual request. It asks the server if the real request is safe to proceed. If the server responds with incorrect or missing CORS headers, the browser aborts the actual request.

How do I allow custom headers in Spring Boot?

You must include the custom header names in the allowedHeaders method within your CorsRegistry configuration. Using * allows all headers, but specifying them explicitly is better for security in production environments.

Can I use CORS filters instead of WebMvcConfigurer?

Yes, you can use a FilterRegistrationBean to register a CORS filter. However, using WebMvcConfigurer is generally preferred in Spring Boot as it integrates more cleanly with the MVC framework and is easier to maintain for most applications.

What if I am using Spring Security?

Spring Security can intercept CORS preflight requests and block them. You need to configure Security to permit OPTIONS requests or ensure that the CORS configuration is applied before Security checks. This often involves adding a custom filter or adjusting the Security configuration chain.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More