File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 110110
111111 const fetchTasksIfNeeded = async ( ) => {
112112 const taskStore = JSON . parse ( sessionStorage . getItem ( 'task' ) ) ;
113+
114+ const sanitizeHeaderValue = ( value ) => {
115+ // Ensure the value is a valid UTF-8 string and URL-encode non-ASCII characters
116+ return encodeURIComponent ( value ) ;
117+ } ;
118+
119+ const sanitizeHeaders = ( headers ) => {
120+ const sanitizedHeaders = { } ;
121+ for ( const key in headers ) {
122+ if ( headers . hasOwnProperty ( key ) ) {
123+ const sanitizedKey = sanitizeHeaderValue ( key ) ; // Sanitize the key
124+ const sanitizedValue = sanitizeHeaderValue ( headers [ key ] ) ; // Sanitize the value
125+ sanitizedHeaders [ sanitizedKey ] = sanitizedValue ;
126+ }
127+ }
128+ return sanitizedHeaders ;
129+ } ;
130+
113131 window . headers
114132 . then ( headers => {
133+ const sanitized = sanitizeHeaders ( headers ) ;
134+ console . log ( "Sanitized Headers:" , sanitized ) ;
115135 fetch ( apiEndpoint + '/plans' , {
116136 method : 'GET' ,
117- headers : headers ,
137+ headers : sanitized ,
118138 } )
119139 . then ( response => response . json ( ) )
120140 . then ( data => {
You can’t perform that action at this time.
0 commit comments