patchlwIP - A Lightweight TCP/IP stack - Patches: patch #10148, HTTPD add cookie support

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #10148: HTTPD add cookie support

Submitted by:  Adam Baron <vysocan>
Submitted on:  Sun 28 Nov 2021 07:29:45 PM UTC
 
Category:  Contrib Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       No canned response available

 

Fri 17 Dec 2021 11:36:58 AM UTC, comment #1: 

Hello,

please any comments or thoughts? This might get quite useful when creating some kind of authentication and require minimal changes to httpd.
Simply one page/form to authenticate and then send browser a Set-Cookie with unique value, possibly expiration or other standard flags. Then only validate the unique value with every GET, POST request.

Adam Baron <vysocan>
Sun 28 Nov 2021 07:29:45 PM UTC, original submission:  

Hello,

here is proposal to add cookie handling to HTTPD. It is quite simple and require LWIP_HTTPD_DYNAMIC_HEADERS to send the cookies. Also leaving all processing up to user application. Application then needs to provide following example functions.

#define SET_COOKIE_SIZE 48
char setCookie[SET_COOKIE_SIZE];

char httpd_set_cookies(const void connection, const char *uri) {
  LWIP_UNUSED_ARG(uri);

  if (connection == verifiedConn) {
    verifiedConn = NULL; // Clear verified connection
    snprintf(setCookie, SET_COOKIE_SIZE, HDR_HTTP_RES_SET_COOKIE "id=%08X\r\n", authorizedConn.id);
    return setCookie;
  }
  return NULL;
}

void httpd_received_cookies(const void connection, const char cookies) {
  const char *sessionId = strstr(cookies, "id=");
  if (sessionId != NULL) {
     uint32_t value = strtol(sessionId+3, NULL, 16);
     if (value == authorizedConn.id) {
       authorizedConn.conn = (uint32_t *)connection;
     }
  }
}

Adam Baron <vysocan>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #52365:  patch.diff added by vysocan (6KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by vysocan (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-28 vysocan Attached File- => Added patch.diff, #52365

    Back to the top


    Powered by Savane 3.9