FYI 40 minutes and JFK is perfectly doable and there is a ton of service between JFK and LHR so misconnecting isn’t the end of the world, and gates are easier to navigate between than LAX in many cases.
Once you get to LAX there is nothing you need to do other than walk between gates so you should be fine, no security, your passport will be checked in SFO so all you need to do is change gates and board, that said TBIT can be a bit of a hike so be ready for that, TBIT is the international terminal at LAX so you will probably depart from there
btw if you ticketed this as two separate tickets and have luggage it will be tough going but it sounds like this is one ticket with a connection