VERIFIED ANSWERS|LATEST VERSION|ALREADY PASSED!!!
1. What is the primary defense against log
Sanitize outbound log
injection at- tacks?
messages
2. import
logging.error("The
logging
excep- tion that
import sys
occured is: %s", str(e))
import
logging
import sys
#log division by zero error to the log, the
output is printed to the screen
def divideByZeroError(dividend,
divisor):
logging.basicConfig(stream=sys.stdou
t,for- mat='%(levelname)s:%
(message)s')
try:
quotient =
dividend/divisor print
(quotient)
except Exception as e:
#logging error here, use str(e) as part of
the output if name == ' main ':
dividend =
int(input()) divisor =
int(input())
divideByZeroError(dividend,divisor)
3. An attacker exploits a cross-site scripting vulnerability. Access the
,D385 PRE-ASSESSMENT WITH ALL CORRECT & 100%
VERIFIED ANSWERS|LATEST VERSION|ALREADY PASSED!!!
user's data
4. Which Python function is prone to a eval()
potential code injection attack?
5. What are two common defensive coding
techniques?
, D385 PRE-ASSESSMENT WITH ALL CORRECT & 100%
VERIFIED ANSWERS|LATEST VERSION|ALREADY PASSED!!!
Check functional and
pre- conditions and
postcondi- tions
6. # unit test if x is None:
case import print("x is a null value")
unittest return y
def multiply_numbers(x, elif y is None:
y): #add your code print("y is a null value")
here return x * y return x
# add your code here else:
return x * y
class
TestForNone(unittest.TestCase):
def test_when_a_is_null(self):
try:
self.assertIsNone(multiply_numbers(5,
None)) except AssertionError as msg:
print(msg)
if name == ' main ':
unittest.main()
7. Which package is meant for internal use by Python for test
regression testing?
8. from string import U
Template CONFIG = { s
"API_KEY": "'you've just exposed your e
secret_key'" r
} :
class