Generation of Error Message Containing Sensitive Information
The product generates an error message that includes sensitive information about its environment, users, or associated data.
The sensitive information may be valuable information on its own, or it may be useful for launching other, more serious attacks. The error message may be created in different ways, and the information that is included can range widely.
Comment corriger cette vulnérabilité
Stratégies de prévention pour Error Message Information Leak basées sur 5 règles de détection Shoulder.
Return generic error messages to clients; log detailed errors server-side
func handler(w http.ResponseWriter, r *http.Request) { rows, err := db.Query("SELECT * FROM users") if err != nil { - http.Error(w, err.Error(), 500) + log.Printf("database query failed: %v", err) + http.Error(w, "Internal server error", 500) return } }
Return generic error messages to users and log detailed errors server-side
} catch (error) { - res.status(500).json({ error: error.message, stack: error.stack }); + logger.error('Operation failed', { error: error.message }); + res.status(500).json({ error: 'An error occurred' }); }
Configure errorFormatter to strip stack traces in production and use TRPCError with generic messages
- import { initTRPC } from '@trpc/server'; - import { router, publicProcedure } from './trpc'; - - export const t = initTRPC.context<Context>().create({ - // No errorFormatter configured - }); - - export const userRouter = router({ - createUser: publicProcedure - .mutation(async ({ input }) => { - try { - return await db.user.create({ data: input }); - } catch (err) { - throw err; // Raw database error exposed to client + import { initTRPC, TRPCError } from '@trpc/server'; + + export const t = initTRPC.context<Context>().create({ + errorFormatter({ shape }) { + return { + ...shape, + data: { + ...shape.data, + stack: process.env.NODE_ENV === 'production' + ? undefined + : shape.data.stack, + }, + }; + }, + }); + + export const userRouter = router({ + createUser: publicProcedure + .mutation(async ({ input }) => { + try { + return await db.user.create({ data: input }); + } catch (err) { + throw new TRPCError({ + code: 'INTERNAL_SERVER_ERROR', + message: 'Failed to create user', + }); } }) });
Log full exception details internally but return generic error messages to users
- from flask import jsonify - - @app.route('/api/process') - def process(): - try: - result = expensive_operation() - return jsonify(result) - except Exception as e: - return jsonify({'error': str(e)}), 500 + import logging + from flask import jsonify + + logger = logging.getLogger(__name__) + + @app.route('/api/process') + def process(): + try: + result = expensive_operation() + return jsonify(result) + except Exception as e: + logger.error(f"Processing failed: {e}", exc_info=True) + return jsonify({'error': 'Internal server error'}), 500
Return generic responses; log internal paths server-side only
- from flask import jsonify - - @app.route('/info') - def get_info(): - return jsonify({ - 'status': 'ok', - 'path': __file__, - 'cwd': os.getcwd() - }) + import logging + from flask import jsonify + + logger = logging.getLogger(__name__) + + @app.route('/info') + def get_info(): + logger.info(f"Info request from {__file__}") + return jsonify({'status': 'ok', 'version': '1.0'})
Trouvez les vulnérabilités dans votre code
Utilisez Shoulder pour scanner votre code à la recherche de patterns Generation of Error Message Containing Sensitive Information. 5 règles.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=209 # Or scan entire project npx @shoulderdev/cli trust .
Règles de Détection (5)
Ce qu'il faut surveiller lors des revues de code
Ces patterns indiquent des vulnérabilités potentielles Generation of Error Message Containing Sensitive Information. Recherchez-les lors des revues de code et des audits de sécurité.
Scannez votre base de code pour Generation of Error Message Containing Sensitive Information
Shoulder CLI trouve les motifs vulnérables dans toute votre base de code.