@@ -59,25 +59,19 @@ def handle_before_submit_prompt(ctx: typer.Context, payload: AIHookPayload, poli
5959 try :
6060 violation_summary , scan_id = _scan_text_for_secrets (ctx , clipped , timeout_ms )
6161
62- if (
63- violation_summary
64- and get_policy_value (prompt_config , 'action' , default = 'block' ) == 'block'
65- and mode == 'block'
66- ):
67- outcome = AIHookOutcome .BLOCKED
62+ if violation_summary :
6863 block_reason = BlockReason .SECRETS_IN_PROMPT
69- user_message = f'{ violation_summary } . Remove secrets before sending.'
70- response = response_builder .deny_prompt (user_message )
71- else :
72- if violation_summary :
73- outcome = AIHookOutcome .WARNED
74- response = response_builder .allow_prompt ()
75- return response
64+ if get_policy_value (prompt_config , 'action' , default = 'block' ) == 'block' and mode == 'block' :
65+ outcome = AIHookOutcome .BLOCKED
66+ user_message = f'{ violation_summary } . Remove secrets before sending.'
67+ return response_builder .deny_prompt (user_message )
68+ outcome = AIHookOutcome .WARNED
69+ return response_builder .allow_prompt ()
7670 except Exception as e :
7771 outcome = (
7872 AIHookOutcome .ALLOWED if get_policy_value (policy , 'fail_open' , default = True ) else AIHookOutcome .BLOCKED
7973 )
80- block_reason = BlockReason .SCAN_FAILURE if outcome == AIHookOutcome . BLOCKED else None
74+ block_reason = BlockReason .SCAN_FAILURE
8175 raise e
8276 finally :
8377 ai_client .create_event (
@@ -116,36 +110,50 @@ def handle_before_read_file(ctx: typer.Context, payload: AIHookPayload, policy:
116110
117111 try :
118112 # Check path-based denylist first
119- if is_denied_path (file_path , policy ) and action == 'block' :
120- outcome = AIHookOutcome .BLOCKED
113+ if is_denied_path (file_path , policy ):
121114 block_reason = BlockReason .SENSITIVE_PATH
122- user_message = f'Cycode blocked sending { file_path } to the AI (sensitive path policy).'
123- return response_builder .deny_permission (
115+ if mode == 'block' and action == 'block' :
116+ outcome = AIHookOutcome .BLOCKED
117+ user_message = f'Cycode blocked sending { file_path } to the AI (sensitive path policy).'
118+ return response_builder .deny_permission (
119+ user_message ,
120+ 'This file path is classified as sensitive; do not read/send it to the model.' ,
121+ )
122+ # Warn mode - ask user for permission
123+ outcome = AIHookOutcome .WARNED
124+ user_message = f'Cycode flagged { file_path } as sensitive. Allow reading?'
125+ return response_builder .ask_permission (
124126 user_message ,
125- 'This file path is classified as sensitive; do not read/send it to the model .' ,
127+ 'This file path is classified as sensitive; proceed with caution .' ,
126128 )
127129
128130 # Scan file content if enabled
129131 if get_policy_value (file_read_config , 'scan_content' , default = True ):
130132 violation_summary , scan_id = _scan_path_for_secrets (ctx , file_path , policy )
131- if violation_summary and action == 'block' and mode == 'block' :
132- outcome = AIHookOutcome .BLOCKED
133+ if violation_summary :
133134 block_reason = BlockReason .SECRETS_IN_FILE
134- user_message = f'Cycode blocked reading { file_path } . { violation_summary } '
135- return response_builder .deny_permission (
135+ if mode == 'block' and action == 'block' :
136+ outcome = AIHookOutcome .BLOCKED
137+ user_message = f'Cycode blocked reading { file_path } . { violation_summary } '
138+ return response_builder .deny_permission (
139+ user_message ,
140+ 'Secrets detected; do not send this file to the model.' ,
141+ )
142+ # Warn mode - ask user for permission
143+ outcome = AIHookOutcome .WARNED
144+ user_message = f'Cycode detected secrets in { file_path } . { violation_summary } '
145+ return response_builder .ask_permission (
136146 user_message ,
137- 'Secrets detected; do not send this file to the model .' ,
147+ 'Possible secrets detected; proceed with caution .' ,
138148 )
139- if violation_summary :
140- outcome = AIHookOutcome .WARNED
141149 return response_builder .allow_permission ()
142150
143151 return response_builder .allow_permission ()
144152 except Exception as e :
145153 outcome = (
146154 AIHookOutcome .ALLOWED if get_policy_value (policy , 'fail_open' , default = True ) else AIHookOutcome .BLOCKED
147155 )
148- block_reason = BlockReason .SCAN_FAILURE if outcome == AIHookOutcome . BLOCKED else None
156+ block_reason = BlockReason .SCAN_FAILURE
149157 raise e
150158 finally :
151159 ai_client .create_event (
@@ -192,9 +200,9 @@ def handle_before_mcp_execution(ctx: typer.Context, payload: AIHookPayload, poli
192200 if get_policy_value (mcp_config , 'scan_arguments' , default = True ):
193201 violation_summary , scan_id = _scan_text_for_secrets (ctx , clipped , timeout_ms )
194202 if violation_summary :
203+ block_reason = BlockReason .SECRETS_IN_MCP_ARGS
195204 if mode == 'block' and action == 'block' :
196205 outcome = AIHookOutcome .BLOCKED
197- block_reason = BlockReason .SECRETS_IN_MCP_ARGS
198206 user_message = f'Cycode blocked MCP tool call "{ tool } ". { violation_summary } '
199207 return response_builder .deny_permission (
200208 user_message ,
@@ -211,7 +219,7 @@ def handle_before_mcp_execution(ctx: typer.Context, payload: AIHookPayload, poli
211219 outcome = (
212220 AIHookOutcome .ALLOWED if get_policy_value (policy , 'fail_open' , default = True ) else AIHookOutcome .BLOCKED
213221 )
214- block_reason = BlockReason .SCAN_FAILURE if outcome == AIHookOutcome . BLOCKED else None
222+ block_reason = BlockReason .SCAN_FAILURE
215223 raise e
216224 finally :
217225 ai_client .create_event (
0 commit comments