Skip to content

Conversation

@nitya
Copy link
Member

@nitya nitya commented Oct 14, 2025

No description provided.

nitya added 7 commits October 14, 2025 04:01
- Configure key-based authentication in cognitiveservices.bicep
- Add comprehensive .gitignore for Azure and Python projects
- Update README.md with clearer project objectives
- Enhance setup script with Bicep authentication modifications
- Expand documentation with detailed deployment instructions
added custom template
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

response = JSONResponse(content=content)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.

Copilot Autofix

AI 2 months ago

To fix the problem, update the cookie-setting lines (271 and 272) so the cookies are set with secure=True, httponly=True, and samesite='Strict' (or 'Lax', depending on the application's requirements; 'Strict' is safest). This change only affects the arguments to response.set_cookie and does not alter existing functionality, except to make the cookies more resistant to network and script-based attacks. No imports or additional definitions are needed for this, as FastAPI (built atop Starlette) supports these flags directly.

Suggested changeset 1
.azd-setup/src/api/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.azd-setup/src/api/routes.py b/.azd-setup/src/api/routes.py
--- a/.azd-setup/src/api/routes.py
+++ b/.azd-setup/src/api/routes.py
@@ -268,8 +268,8 @@
         response = JSONResponse(content=content)
     
         # Update cookies to persist the thread and agent IDs.
-        response.set_cookie("thread_id", thread_id)
-        response.set_cookie("agent_id", agent_id)
+        response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Strict')
+        response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Strict')
         return response
     except Exception as e:
         logger.error(f"Error listing message: {e}")
EOF
@@ -268,8 +268,8 @@
response = JSONResponse(content=content)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)
response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Strict')
response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Strict')
return response
except Exception as e:
logger.error(f"Error listing message: {e}")
Copilot is powered by AI and may make mistakes. Always verify output.

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.

Copilot Autofix

AI 2 months ago

To fix this problem, set the secure, httponly, and samesite attributes explicitly when calling response.set_cookie for both "thread_id" and "agent_id". This should be done on lines 271 and 272. The best practice is to set secure=True (sent only over HTTPS), httponly=True (not accessible to JS), and samesite='Lax' (prevents CSRF by limiting cross-origin cookie sending). This change should not affect functionality but will ensure cookies are sent safely. No additional imports are needed because the attributes are supported directly by the FastAPI/Starlette API.


Suggested changeset 1
.azd-setup/src/api/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.azd-setup/src/api/routes.py b/.azd-setup/src/api/routes.py
--- a/.azd-setup/src/api/routes.py
+++ b/.azd-setup/src/api/routes.py
@@ -268,8 +268,8 @@
         response = JSONResponse(content=content)
     
         # Update cookies to persist the thread and agent IDs.
-        response.set_cookie("thread_id", thread_id)
-        response.set_cookie("agent_id", agent_id)
+        response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Lax')
+        response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Lax')
         return response
     except Exception as e:
         logger.error(f"Error listing message: {e}")
EOF
@@ -268,8 +268,8 @@
response = JSONResponse(content=content)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)
response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Lax')
response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Lax')
return response
except Exception as e:
logger.error(f"Error listing message: {e}")
Copilot is powered by AI and may make mistakes. Always verify output.
logger.info(f"Starting streaming response for thread ID {thread_id}")

# Create the streaming response using the generator.
response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 2 months ago

To address the information exposure through exception error, we should ensure that details of exceptions are logged on the server, but clients only receive a generic error message. In .azd-setup/src/api/routes.py, inside the get_result generator function, in the exception handling block (lines 221-223), replace str(e) with a fixed, non-revealing string, such as "An internal error has occurred." The logger will still store the full exception (including stack trace) for server-side review.
No new imports or methods are required, since logging is already present. Only the relevant yield serialize_sse_event(...) line needs changing.


Suggested changeset 1
.azd-setup/src/api/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.azd-setup/src/api/routes.py b/.azd-setup/src/api/routes.py
--- a/.azd-setup/src/api/routes.py
+++ b/.azd-setup/src/api/routes.py
@@ -220,7 +220,7 @@
                         logger.debug("Event received but no data to yield")
         except Exception as e:
             logger.exception(f"Exception in get_result: {e}")
-            yield serialize_sse_event({'type': "error", 'message': str(e)})
+            yield serialize_sse_event({'type': "error", 'message': "An internal error has occurred."})
 
 
 @router.get("/chat/history")
EOF
@@ -220,7 +220,7 @@
logger.debug("Event received but no data to yield")
except Exception as e:
logger.exception(f"Exception in get_result: {e}")
yield serialize_sse_event({'type': "error", 'message': str(e)})
yield serialize_sse_event({'type': "error", 'message': "An internal error has occurred."})


@router.get("/chat/history")
Copilot is powered by AI and may make mistakes. Always verify output.
response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.

Copilot Autofix

AI 2 months ago

To fix the problem, set the secure, httponly, and samesite flags explicitly when calling response.set_cookie.

  • secure=True ensures the cookie is only sent over HTTPS.
  • httponly=True makes the cookie inaccessible to client-side JavaScript.
  • samesite='Lax' (or 'Strict' if strictest CSRF protection is desired) limits the contexts in which the cookie is sent, mitigating CSRF.

Best fixed by:

  • In file .azd-setup/src/api/routes.py, lines 349-350, update the set_cookie calls to include: secure=True, httponly=True, samesite='Lax'.

No imports or other code changes are needed, as StreamingResponse.set_cookie supports these parameters directly.


Suggested changeset 1
.azd-setup/src/api/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.azd-setup/src/api/routes.py b/.azd-setup/src/api/routes.py
--- a/.azd-setup/src/api/routes.py
+++ b/.azd-setup/src/api/routes.py
@@ -346,8 +346,8 @@
         response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)
 
         # Update cookies to persist the thread and agent IDs.
-        response.set_cookie("thread_id", thread_id)
-        response.set_cookie("agent_id", agent_id)
+        response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Lax')
+        response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Lax')
         return response
 
 def read_file(path: str) -> str:
EOF
@@ -346,8 +346,8 @@
response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)
response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Lax')
response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Lax')
return response

def read_file(path: str) -> str:
Copilot is powered by AI and may make mistakes. Always verify output.

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)

Check warning

Code scanning / CodeQL

Failure to use secure cookies Medium

Cookie is added without the Secure and HttpOnly attributes properly set.

Copilot Autofix

AI 2 months ago

To fix this issue, both cookie-setting calls on lines 349 and 350 should use secure attributes to protect them. Update each call to response.set_cookie to specify secure=True, httponly=True, and samesite='Strict'. This is accomplished by editing only these lines within the file .azd-setup/src/api/routes.py. No additional imports or restructuring are required. These changes will ensure that these cookies are only sent over HTTPS, are not accessible clientside from JavaScript, and are protected against cross-origin requests.

Suggested changeset 1
.azd-setup/src/api/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.azd-setup/src/api/routes.py b/.azd-setup/src/api/routes.py
--- a/.azd-setup/src/api/routes.py
+++ b/.azd-setup/src/api/routes.py
@@ -346,8 +346,8 @@
         response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)
 
         # Update cookies to persist the thread and agent IDs.
-        response.set_cookie("thread_id", thread_id)
-        response.set_cookie("agent_id", agent_id)
+        response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Strict')
+        response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Strict')
         return response
 
 def read_file(path: str) -> str:
EOF
@@ -346,8 +346,8 @@
response = StreamingResponse(get_result(request, thread_id, agent_id, ai_project, app_insights_conn_str, carrier), headers=headers)

# Update cookies to persist the thread and agent IDs.
response.set_cookie("thread_id", thread_id)
response.set_cookie("agent_id", agent_id)
response.set_cookie("thread_id", thread_id, secure=True, httponly=True, samesite='Strict')
response.set_cookie("agent_id", agent_id, secure=True, httponly=True, samesite='Strict')
return response

def read_file(path: str) -> str:
Copilot is powered by AI and may make mistakes. Always verify output.
@nitya nitya merged commit aa3bacf into msignite25-prel13 Oct 14, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants